Submission #870817

# Submission time Handle Problem Language Result Execution time Memory
870817 2023-11-09T08:09:46 Z vjudge1 Sajam (COCI18_sajam) C++17
45 / 90
1251 ms 1616 KB
//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');
        }
    };

    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 cnt = 0;
            for(int j = 1; j <= n; j++) {
                cnt += (matrix[j][i] == 'o');
            }

            //cerr << i << " :: " << cnt << "\n";
            ans += min(cnt, n - cnt);
        }

        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 1 ms 344 KB Output is correct
2 Correct 63 ms 860 KB Output is correct
3 Correct 103 ms 944 KB Output is correct
4 Correct 612 ms 1352 KB Output is correct
5 Correct 108 ms 960 KB Output is correct
6 Correct 26 ms 600 KB Output is correct
7 Correct 157 ms 1112 KB Output is correct
8 Correct 1033 ms 1368 KB Output is correct
9 Correct 14 ms 600 KB Output is correct
10 Correct 1055 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 346 ms 1180 KB Output is correct
2 Correct 469 ms 1264 KB Output is correct
3 Correct 256 ms 1112 KB Output is correct
4 Correct 209 ms 1068 KB Output is correct
5 Correct 608 ms 1364 KB Output is correct
6 Correct 121 ms 860 KB Output is correct
7 Correct 330 ms 1116 KB Output is correct
8 Correct 379 ms 1116 KB Output is correct
9 Correct 79 ms 836 KB Output is correct
10 Correct 1251 ms 1616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 529 ms 1296 KB Output is correct
2 Correct 511 ms 1288 KB Output is correct
3 Correct 219 ms 860 KB Output is correct
4 Correct 321 ms 1160 KB Output is correct
5 Correct 359 ms 1112 KB Output is correct
6 Correct 735 ms 1372 KB Output is correct
7 Correct 79 ms 856 KB Output is correct
8 Correct 303 ms 1364 KB Output is correct
9 Correct 570 ms 1188 KB Output is correct
10 Correct 1240 ms 1412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 222 ms 1080 KB Output is correct
2 Correct 231 ms 1088 KB Output is correct
3 Incorrect 781 ms 1416 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 802 ms 1372 KB Output is correct
2 Correct 747 ms 1372 KB Output is correct
3 Incorrect 656 ms 1368 KB Output isn't correct
4 Halted 0 ms 0 KB -