# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
153705 | kimcoding | Sajam (COCI18_sajam) | C++17 | 71 ms | 2424 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <algorithm>
using namespace std;
bool chk[2][1005], map[1005][1005];
int cnt[2][1005], n, k, sum;
bool solve(int t) {
if (sum <= k) return true;
for (t = 1; t <= n * 2; t++) {
int Max = -1, a, b;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= 1; j++) {
if (chk[j][i]) continue;
if (Max < cnt[j][i])
Max = cnt[j][i], a = j, b = i;
}
}
chk[a][b] = true;
sum += n - 2 * cnt[a][b];
cnt[a][b] = n - cnt[a][b];
for (int i = 1; i <= n; i++)
cnt[!a][i] += ((map[a ? b : i][a ? i : b] ^= 1) ? 1 : -1);
if (sum <= k) return true;
}
return false;
}
int main() {
scanf("%d %d", &n, &k);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
char x;
scanf(" %c", &x);
map[i][j] = (x == 'o');
cnt[0][j] += map[i][j];
cnt[1][i] += map[i][j];
}
sum += cnt[1][i];
}
printf("%s\n", solve(0) ? "DA" : "NE");
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |