//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; k++) {
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; k++) {
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 |
Execution timed out |
5061 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5016 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5038 ms |
1112 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5025 ms |
1116 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5053 ms |
860 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5032 ms |
1368 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |