Submission #870968

# Submission time Handle Problem Language Result Execution time Memory
870968 2023-11-09T15:48:07 Z MisterReaper Sajam (COCI18_sajam) C++17
45 / 90
3334 ms 2396 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);
            }
        }
    }

    {
        int ans = 0;
        for(int i = 0; i <= n; i++) {
            int cnt = 0;
            for(int j = 0; j <= n; j++) {
                cnt += matrix[i][j] == 'o';
            }

            ans += min(cnt, n - cnt);
        }

        anss = min(anss, ans);
    }

    {
        int ans = 0;
        for(int i = 0; i <= n; i++) {
            int cnt = 0;
            for(int j = 0; j <= n; j++) {
                cnt += matrix[j][i] == 'o';
            }

            ans += min(cnt, n - cnt);
        }

        anss = min(anss, ans);
    }

    assert(0 <= anss);
    cerr << 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 348 KB Output is correct
2 Correct 247 ms 1040 KB Output is correct
3 Correct 453 ms 1212 KB Output is correct
4 Correct 2515 ms 2152 KB Output is correct
5 Correct 462 ms 1228 KB Output is correct
6 Correct 111 ms 856 KB Output is correct
7 Correct 405 ms 1176 KB Output is correct
8 Correct 2700 ms 2200 KB Output is correct
9 Correct 41 ms 604 KB Output is correct
10 Correct 2758 ms 2224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Incorrect 3 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1548 ms 1732 KB Output is correct
2 Correct 1986 ms 1940 KB Output is correct
3 Correct 1092 ms 1620 KB Output is correct
4 Correct 884 ms 1620 KB Output is correct
5 Correct 2541 ms 2136 KB Output is correct
6 Correct 514 ms 1252 KB Output is correct
7 Correct 1365 ms 1708 KB Output is correct
8 Correct 1583 ms 1804 KB Output is correct
9 Correct 209 ms 856 KB Output is correct
10 Correct 3309 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2270 ms 2032 KB Output is correct
2 Correct 2096 ms 2128 KB Output is correct
3 Correct 910 ms 1492 KB Output is correct
4 Correct 1353 ms 1688 KB Output is correct
5 Correct 1479 ms 1748 KB Output is correct
6 Correct 3115 ms 2308 KB Output is correct
7 Correct 344 ms 1112 KB Output is correct
8 Correct 1251 ms 1656 KB Output is correct
9 Correct 1445 ms 1744 KB Output is correct
10 Correct 3265 ms 2372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 981 ms 1488 KB Output is correct
2 Correct 929 ms 1500 KB Output is correct
3 Incorrect 3223 ms 2364 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3334 ms 2396 KB Output is correct
2 Correct 3191 ms 2392 KB Output is correct
3 Incorrect 2701 ms 2212 KB Output isn't correct
4 Halted 0 ms 0 KB -