//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];
char f(char x) {
if(x == 'o')
return 'x';
else if(x == 'x')
return 'o';
else
return assert(false), char(23);
}
#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[i][x] = f(matrix[i][x]);
}
};
auto reversey = [&](int x) -> void {
for(int i = 1; i <= n; i++) {
matrix[x][i] = f(matrix[x][i]);
}
};
int anss = k +1;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
if(matrix[i][j] == 'o') {
reversex(j);
}
}
int cnt = 0;
for(int j = 1; j <= n; j++) {
int nw = 0;
for(int k = 1; k <= n; k++) {
nw += matrix[k][j] == 'o';
}
cnt += min(nw, n - nw);
}
anss = min(anss, cnt);
}
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
if(matrix[j][i] == 'o') {
reversey(j);
}
}
int cnt = 0;
for(int j = 1; j <= n; j++) {
int nw = 0;
for(int k = 1; k <= n; k++) {
nw += matrix[j][k] == 'o';
}
cnt += min(nw, n - nw);
}
anss = min(anss, cnt);
}
cout << (anss <= k ? "DA" : "NE") << "\n";
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 |
150 ms |
864 KB |
Output is correct |
3 |
Correct |
265 ms |
856 KB |
Output is correct |
4 |
Correct |
1499 ms |
1340 KB |
Output is correct |
5 |
Correct |
268 ms |
856 KB |
Output is correct |
6 |
Correct |
64 ms |
760 KB |
Output is correct |
7 |
Correct |
691 ms |
936 KB |
Output is correct |
8 |
Correct |
4912 ms |
1372 KB |
Output is correct |
9 |
Correct |
67 ms |
600 KB |
Output is correct |
10 |
Execution timed out |
5061 ms |
1372 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Incorrect |
2 ms |
372 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
844 ms |
1180 KB |
Output is correct |
2 |
Correct |
1158 ms |
1256 KB |
Output is correct |
3 |
Correct |
637 ms |
1116 KB |
Output is correct |
4 |
Correct |
525 ms |
856 KB |
Output is correct |
5 |
Correct |
1504 ms |
1328 KB |
Output is correct |
6 |
Correct |
311 ms |
1108 KB |
Output is correct |
7 |
Correct |
816 ms |
1188 KB |
Output is correct |
8 |
Correct |
906 ms |
1200 KB |
Output is correct |
9 |
Correct |
383 ms |
604 KB |
Output is correct |
10 |
Execution timed out |
5036 ms |
1368 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1311 ms |
1312 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
559 ms |
1096 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2056 ms |
1420 KB |
Output is correct |
2 |
Incorrect |
1907 ms |
1620 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |