Submission #870847

#TimeUsernameProblemLanguageResultExecution timeMemory
870847vjudge1Sajam (COCI18_sajam)C++17
0 / 90
5057 ms2188 KiB
//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); } /* 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 k = 1; k <= n; k++) { nw += matrix[j][k] == '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; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...