Skip to content
Snippets Groups Projects
Commit f921a2d9 authored by Bruno Freitas Tissei's avatar Bruno Freitas Tissei
Browse files

Add CodeJam

parent a772185e
Branches
No related tags found
No related merge requests found
#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;
}
#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;
}
#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;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment