//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 -1; i++) {
if(matrix[i][t] != matrix[i +1][t]) {
reversex(i +1);
}
}
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";
}
*/
anss = min(anss, ans);
}
for(int t = 1; t <= n; t++) {
for(int i = 1; i <= n -1; i++) {
if(matrix[t][i] != matrix[t][i +1]) {
reversey(i +1);
}
}
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";
}
*/
anss = min(anss, ans);
}
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 |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
102 ms |
856 KB |
Output is correct |
3 |
Correct |
188 ms |
860 KB |
Output is correct |
4 |
Correct |
1076 ms |
1332 KB |
Output is correct |
5 |
Correct |
202 ms |
956 KB |
Output is correct |
6 |
Correct |
47 ms |
604 KB |
Output is correct |
7 |
Correct |
281 ms |
860 KB |
Output is correct |
8 |
Correct |
1906 ms |
1372 KB |
Output is correct |
9 |
Correct |
28 ms |
600 KB |
Output is correct |
10 |
Correct |
1964 ms |
1368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
602 ms |
1116 KB |
Output is correct |
2 |
Correct |
833 ms |
1264 KB |
Output is correct |
3 |
Correct |
461 ms |
1116 KB |
Output is correct |
4 |
Correct |
371 ms |
1068 KB |
Output is correct |
5 |
Correct |
1068 ms |
1320 KB |
Output is correct |
6 |
Correct |
219 ms |
856 KB |
Output is correct |
7 |
Correct |
589 ms |
1172 KB |
Output is correct |
8 |
Correct |
669 ms |
1200 KB |
Output is correct |
9 |
Correct |
149 ms |
600 KB |
Output is correct |
10 |
Correct |
2318 ms |
1412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
957 ms |
1292 KB |
Output is correct |
2 |
Correct |
924 ms |
1112 KB |
Output is correct |
3 |
Correct |
397 ms |
1112 KB |
Output is correct |
4 |
Correct |
570 ms |
1168 KB |
Output is correct |
5 |
Correct |
623 ms |
1188 KB |
Output is correct |
6 |
Correct |
1297 ms |
1388 KB |
Output is correct |
7 |
Correct |
145 ms |
860 KB |
Output is correct |
8 |
Correct |
543 ms |
1148 KB |
Output is correct |
9 |
Correct |
1052 ms |
1364 KB |
Output is correct |
10 |
Correct |
2306 ms |
1416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
392 ms |
1116 KB |
Output is correct |
2 |
Correct |
396 ms |
856 KB |
Output is correct |
3 |
Incorrect |
1402 ms |
1412 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1439 ms |
1420 KB |
Output is correct |
2 |
Correct |
1345 ms |
1400 KB |
Output is correct |
3 |
Incorrect |
1159 ms |
1372 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |