//author: Ahmet Alp Orakci
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define int i64
const int MAXN = 1E3 + 5;
char matrix[MAXN][MAXN];
#define ONLINE_JUDGE
void solve() {
int n, k;
cin >> n >> k;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
cin >> matrix[i][j];
}
}
auto reversex = [&](int x) -> void {
for(int i = 1; i <= n; i++) {
matrix[x][i] = (matrix[x][i] == 'o' ? 'x' : 'o');
}
};
auto reversey = [&](int x) -> void {
for(int i = 1; i <= n; i++) {
matrix[i][x] = (matrix[i][x] == 'o' ? 'x' : 'o');
}
};
int anss = int(1E18);
for(int t = 1; t <= n; t++) {
for(int i = 1; i <= n; i++) {
if(matrix[i][t] != 'o') {
reversex(i);
}
}
int ans = 0;
for(int i = 1; i <= n; i++) {
int cnto = 0;
for(int j = 1; j <= n; j++) {
cnto += (matrix[j][i] == 'o');
}
ans += min(cnto, n - cnto);
}
/*
cerr << t << " :: " << ans << "\n";
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
cerr << matrix[i][j];
}
cerr << "\n";
}
*/
assert(0 <= ans);
anss = min(anss, ans);
}
for(int t = 1; t <= n; t++) {
for(int i = 1; i <= n; i++) {
if(matrix[t][i] != 'o') {
reversey(i);
}
}
int ans = 0;
for(int i = 1; i <= n; i++) {
int cnto = 0;
for(int j = 1; j <= n; j++) {
cnto += (matrix[i][j] == 'o');
}
ans += min(cnto, n - cnto);
}
/*
cerr << t << " :: " << ans << "\n";
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
cerr << matrix[i][j];
}
cerr << "\n";
}
*/
assert(0 <= ans);
anss = min(anss, ans);
}
assert(0 <= anss);
cout << (anss <= k ? "DA" : "NE");
return;
}
signed main() {
#ifndef ONLINE_JUDGE
freopen(".in", "r", stdin);
freopen(".out", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int t = 1; //cin >> t;
for(int i = 1; i <= t; i++) {
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
143 ms |
860 KB |
Output is correct |
3 |
Correct |
245 ms |
944 KB |
Output is correct |
4 |
Correct |
1446 ms |
1332 KB |
Output is correct |
5 |
Correct |
262 ms |
952 KB |
Output is correct |
6 |
Correct |
62 ms |
604 KB |
Output is correct |
7 |
Correct |
283 ms |
932 KB |
Output is correct |
8 |
Correct |
1912 ms |
1372 KB |
Output is correct |
9 |
Correct |
31 ms |
600 KB |
Output is correct |
10 |
Correct |
1965 ms |
1368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
808 ms |
1180 KB |
Output is correct |
2 |
Correct |
1118 ms |
1260 KB |
Output is correct |
3 |
Correct |
606 ms |
1116 KB |
Output is correct |
4 |
Correct |
495 ms |
1068 KB |
Output is correct |
5 |
Correct |
1398 ms |
1332 KB |
Output is correct |
6 |
Correct |
296 ms |
860 KB |
Output is correct |
7 |
Correct |
779 ms |
1168 KB |
Output is correct |
8 |
Correct |
911 ms |
1364 KB |
Output is correct |
9 |
Correct |
153 ms |
836 KB |
Output is correct |
10 |
Correct |
2320 ms |
1412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1247 ms |
1312 KB |
Output is correct |
2 |
Correct |
1210 ms |
1284 KB |
Output is correct |
3 |
Correct |
513 ms |
1084 KB |
Output is correct |
4 |
Correct |
777 ms |
1164 KB |
Output is correct |
5 |
Correct |
835 ms |
1116 KB |
Output is correct |
6 |
Correct |
1740 ms |
1396 KB |
Output is correct |
7 |
Correct |
193 ms |
920 KB |
Output is correct |
8 |
Correct |
725 ms |
1160 KB |
Output is correct |
9 |
Correct |
1045 ms |
1360 KB |
Output is correct |
10 |
Correct |
2293 ms |
1416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
516 ms |
1096 KB |
Output is correct |
2 |
Correct |
528 ms |
860 KB |
Output is correct |
3 |
Incorrect |
1820 ms |
1412 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1864 ms |
1428 KB |
Output is correct |
2 |
Correct |
1756 ms |
1400 KB |
Output is correct |
3 |
Incorrect |
1539 ms |
1372 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |