# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
870825 |
2023-11-09T08:41:41 Z |
vjudge1 |
Sajam (COCI18_sajam) |
C++17 |
|
2301 ms |
1616 KB |
//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";
}
*/
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";
}
*/
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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
148 ms |
864 KB |
Output is correct |
3 |
Correct |
255 ms |
1108 KB |
Output is correct |
4 |
Correct |
1419 ms |
1336 KB |
Output is correct |
5 |
Correct |
265 ms |
952 KB |
Output is correct |
6 |
Correct |
62 ms |
604 KB |
Output is correct |
7 |
Correct |
281 ms |
932 KB |
Output is correct |
8 |
Correct |
1920 ms |
1372 KB |
Output is correct |
9 |
Correct |
26 ms |
604 KB |
Output is correct |
10 |
Correct |
1962 ms |
1368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
794 ms |
1180 KB |
Output is correct |
2 |
Correct |
1088 ms |
1280 KB |
Output is correct |
3 |
Correct |
601 ms |
1116 KB |
Output is correct |
4 |
Correct |
498 ms |
1068 KB |
Output is correct |
5 |
Correct |
1374 ms |
1324 KB |
Output is correct |
6 |
Correct |
292 ms |
972 KB |
Output is correct |
7 |
Correct |
772 ms |
1364 KB |
Output is correct |
8 |
Correct |
886 ms |
1204 KB |
Output is correct |
9 |
Correct |
150 ms |
856 KB |
Output is correct |
10 |
Correct |
2301 ms |
1616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1231 ms |
1368 KB |
Output is correct |
2 |
Correct |
1229 ms |
1288 KB |
Output is correct |
3 |
Correct |
542 ms |
1080 KB |
Output is correct |
4 |
Correct |
750 ms |
1364 KB |
Output is correct |
5 |
Correct |
821 ms |
1364 KB |
Output is correct |
6 |
Correct |
1714 ms |
1392 KB |
Output is correct |
7 |
Correct |
196 ms |
904 KB |
Output is correct |
8 |
Correct |
708 ms |
1152 KB |
Output is correct |
9 |
Correct |
1035 ms |
1184 KB |
Output is correct |
10 |
Correct |
2286 ms |
1412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
522 ms |
1076 KB |
Output is correct |
2 |
Correct |
526 ms |
1108 KB |
Output is correct |
3 |
Incorrect |
1788 ms |
1432 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1882 ms |
1616 KB |
Output is correct |
2 |
Correct |
1725 ms |
1400 KB |
Output is correct |
3 |
Incorrect |
1528 ms |
1372 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |