제출 #870821

#제출 시각아이디문제언어결과실행 시간메모리
870821vjudge1Sajam (COCI18_sajam)C++17
45 / 90
2303 ms1424 KiB
//author: Ahmet Alp Orakci #include <bits/stdc++.h> using namespace std; using i64 = long long; 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(1E9); 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; }
#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...