//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 a = 1; a <= n; a++) {
nw += matrix[a][j] == 'o';
}
cnt += min(nw, n - nw);
}
/*
cerr << i << " :: " << cnt << "\n";
for(int t = 1; t <= n; t++) {
for(int l = 1; l <= n; l++) {
cerr << matrix[t][l];
}
cerr << "\n";
}
*/
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 a = 1; a <= n; a++) {
nw += matrix[j][a] == 'o';
}
cnt += min(nw, n - nw);
}
/*
cerr << i << " :: " << cnt << "\n";
for(int t = 1; t <= n; t++) {
for(int l = 1; l <= n; l++) {
cerr << matrix[t][l];
}
cerr << "\n";
}
*/
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 |
139 ms |
860 KB |
Output is correct |
3 |
Correct |
270 ms |
860 KB |
Output is correct |
4 |
Correct |
1473 ms |
1336 KB |
Output is correct |
5 |
Correct |
274 ms |
960 KB |
Output is correct |
6 |
Correct |
63 ms |
764 KB |
Output is correct |
7 |
Correct |
701 ms |
1108 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 |
5028 ms |
1368 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 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 |
843 ms |
1180 KB |
Output is correct |
2 |
Correct |
1191 ms |
1112 KB |
Output is correct |
3 |
Correct |
614 ms |
1116 KB |
Output is correct |
4 |
Correct |
527 ms |
860 KB |
Output is correct |
5 |
Correct |
1526 ms |
1328 KB |
Output is correct |
6 |
Correct |
306 ms |
972 KB |
Output is correct |
7 |
Correct |
810 ms |
1368 KB |
Output is correct |
8 |
Correct |
904 ms |
1360 KB |
Output is correct |
9 |
Correct |
385 ms |
604 KB |
Output is correct |
10 |
Execution timed out |
5021 ms |
1372 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1297 ms |
1296 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
558 ms |
856 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2070 ms |
1420 KB |
Output is correct |
2 |
Incorrect |
1881 ms |
1400 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |