diff --git a/contests/CodeJam/2018/Qualification/A.cpp b/contests/CodeJam/2018/Qualification/A.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0239075ee7e43f1f0dddc9660e1722e8b31cbe7a --- /dev/null +++ b/contests/CodeJam/2018/Qualification/A.cpp @@ -0,0 +1,69 @@ +#include <bits/stdc++.h> + +#define EPS 1e-6 +#define MOD 1000000007 +#define inf 0x3f3f3f3f +#define llinf 0x3f3f3f3f3f3f3f3f + +#define fi first +#define se second +#define pb push_back +#define ende '\n' + +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() +#define mset(x, y) memset(&x, (y), sizeof(x)) + +using namespace std; + +typedef long long ll; +typedef pair<int,int> ii; + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + int t; cin >> t; + for (int cas = 1; cas <= t; ++cas) { + int d; cin >> d; + string s; cin >> s; + + int n = s.size(); + vector<ll> v(n); + + int nums = 0; + ll curr = 1, sum = 0; + for (int i = 0; i < n; ++i) { + if (s[i] == 'S') { + sum += curr; + nums++; + } else curr <<= 1; + + v[i] = curr; + } + + cout << "Case #" << cas << ": "; + if (nums > d) { + cout << "IMPOSSIBLE" << ende; + continue; + } + + int ans = 0; + int i = n - 2; + while (sum > d) { + if (i <= n - 2 && s[i] == 'C' && s[i+1] == 'S') { + sum -= v[i]; + v[i] >>= 1; + sum += v[i]; + swap(s[i], s[i+1]); + ans++; + i++; + } else + i--; + } + + cout << ans << ende; + } + + return 0; +} diff --git a/contests/CodeJam/2018/Qualification/B.cpp b/contests/CodeJam/2018/Qualification/B.cpp new file mode 100644 index 0000000000000000000000000000000000000000..933ccd199dbd1795d7c083983c0adc07dbb2d7e6 --- /dev/null +++ b/contests/CodeJam/2018/Qualification/B.cpp @@ -0,0 +1,65 @@ +#include <bits/stdc++.h> + +#define EPS 1e-6 +#define MOD 1000000007 +#define inf 0x3f3f3f3f +#define llinf 0x3f3f3f3f3f3f3f3f + +#define fi first +#define se second +#define pb push_back +#define ende '\n' + +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() +#define mset(x, y) memset(&x, (y), sizeof(x)) + +using namespace std; + +typedef long long ll; +typedef pair<int,int> ii; + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + int t; cin >> t; + for (int cas = 1; cas <= t; ++cas) { + int n; cin >> n; + vector<int> v(n); + for (auto &i : v) cin >> i; + + vector<int> v1, v2; + for (int i = 0; i < n; ++i) + if (i % 2) v2.pb(v[i]); + else v1.pb(v[i]); + + sort(all(v1)); + sort(all(v2)); + + int j = 0; + for (auto i : v1) { + v[j] = i; + j += 2; + } + + j = 1; + for (auto i : v2) { + v[j] = i; + j += 2; + } + + int ans = -1; + for (int i = 0; i < n - 1; ++i) { + if (v[i] > v[i+1]) { + ans = i; + break; + } + } + cout << "Case #" << cas << ": "; + if (ans == -1) cout << "OK" << ende; + else cout << ans << ende; + } + + return 0; +} diff --git a/contests/CodeJam/2018/Qualification/C.cpp b/contests/CodeJam/2018/Qualification/C.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9faa1d6ff5b347b2ba787a9a6280c79cadc5d63c --- /dev/null +++ b/contests/CodeJam/2018/Qualification/C.cpp @@ -0,0 +1,80 @@ +#include <bits/stdc++.h> + +#define EPS 1e-6 +#define MOD 1000000007 +#define inf 0x3f3f3f3f +#define llinf 0x3f3f3f3f3f3f3f3f + +#define fi first +#define se second +#define pb push_back +#define ende '\n' + +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() +#define mset(x, y) memset(&x, (y), sizeof(x)) + +using namespace std; + +typedef long long ll; +typedef pair<int,int> ii; + +int v[3][3]; +int m[1001][1001]; + +bool check() { + return (v[0][0] && v[0][1] && v[0][2]); +} + +int count() { + int num = 0; + for (int i = 0; i < 3; ++i) + for (int j = 0; j < 3; ++j) + num += !v[i][j]; + return num; +} + +void move(int &line) { + line++; + + for (int i = 0; i < 3; ++i) v[0][i] = v[1][i]; + for (int i = 0; i < 3; ++i) v[1][i] = v[2][i]; + for (int i = 0; i < 3; ++i) v[2][i] = 0; +} + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + int t; cin >> t; + + for (int cas = 1; cas <= t; ++cas) { + int a; cin >> a; + int line = 2; + int num = 0; + mset(v, 0); + mset(m, 0); + + while (true) { + while (check() && line < 1000) { + if (count() + num >= a) break; + move(line); + } + + cout << line << " " << 2 << ende; + cout << flush; + int x, y; cin >> x >> y; + + if (x == 0 && y == 0) + break; + + if (!m[x][y]) num++; + m[x][y] = 1; + + assert(x != -1 && y != -1); + v[x - line + 1][y - 1] = 1; + } + } + + return 0; +}