Submission #870854

# Submission time Handle Problem Language Result Execution time Memory
870854 2023-11-09T10:01:00 Z vjudge1 Sajam (COCI18_sajam) C++17
45 / 90
3337 ms 2184 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++) {
        vector <bool> rev(n);
        for(int i = 1; i <= n; i++) {
            if(matrix[i][t] != 'o') {
                reversex(i);
                rev[i] = true;
            }
        }

        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";
        }
        */

        assert(0 <= ans);
        anss = min(anss, ans);

        for(int i = 1; i <= n; i++) {
            if(rev[i]) {
                reversex(i);
            }
        }
    }

    for(int t = 1; t <= n; t++) {
        vector <bool> rev(n);
        for(int i = 1; i <= n; i++) {
            if(matrix[t][i] != 'o') {
                reversey(i);
                rev[i] = true;
            }
        }

        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";
        }
        */

        assert(0 <= ans);
        anss = min(anss, ans);

        for(int i = 1; i <= n; i++) {
            if(rev[i]) {
                reversey(i);
            }
        }
    }

    assert(0 <= anss);
    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 600 KB Output is correct
2 Correct 247 ms 864 KB Output is correct
3 Correct 450 ms 952 KB Output is correct
4 Correct 2515 ms 1332 KB Output is correct
5 Correct 459 ms 856 KB Output is correct
6 Correct 115 ms 756 KB Output is correct
7 Correct 402 ms 944 KB Output is correct
8 Correct 2649 ms 1372 KB Output is correct
9 Correct 36 ms 604 KB Output is correct
10 Correct 2694 ms 1616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 532 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 1413 ms 1176 KB Output is correct
2 Correct 1923 ms 1260 KB Output is correct
3 Correct 1061 ms 1116 KB Output is correct
4 Correct 853 ms 1068 KB Output is correct
5 Correct 2433 ms 1204 KB Output is correct
6 Correct 520 ms 968 KB Output is correct
7 Correct 1359 ms 1364 KB Output is correct
8 Correct 1536 ms 1116 KB Output is correct
9 Correct 207 ms 600 KB Output is correct
10 Correct 3197 ms 1412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2166 ms 1296 KB Output is correct
2 Correct 2089 ms 1796 KB Output is correct
3 Correct 926 ms 1372 KB Output is correct
4 Correct 1327 ms 1876 KB Output is correct
5 Correct 1464 ms 1700 KB Output is correct
6 Correct 3029 ms 2168 KB Output is correct
7 Correct 350 ms 1116 KB Output is correct
8 Correct 1246 ms 1876 KB Output is correct
9 Correct 1433 ms 1700 KB Output is correct
10 Correct 3175 ms 2184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 919 ms 1080 KB Output is correct
2 Correct 927 ms 1504 KB Output is correct
3 Incorrect 3187 ms 2184 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3337 ms 1428 KB Output is correct
2 Correct 3096 ms 1396 KB Output is correct
3 Incorrect 2685 ms 2140 KB Output isn't correct
4 Halted 0 ms 0 KB -