답안 #870821

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
870821 2023-11-09T08:25:12 Z vjudge1 Sajam (COCI18_sajam) C++17
45 / 90
2303 ms 1424 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');
        }
    };

    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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 103 ms 860 KB Output is correct
3 Correct 188 ms 948 KB Output is correct
4 Correct 1078 ms 1344 KB Output is correct
5 Correct 198 ms 860 KB Output is correct
6 Correct 47 ms 600 KB Output is correct
7 Correct 283 ms 932 KB Output is correct
8 Correct 1912 ms 1372 KB Output is correct
9 Correct 29 ms 848 KB Output is correct
10 Correct 1969 ms 1372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 600 ms 1184 KB Output is correct
2 Correct 822 ms 1260 KB Output is correct
3 Correct 453 ms 1116 KB Output is correct
4 Correct 379 ms 1072 KB Output is correct
5 Correct 1044 ms 1364 KB Output is correct
6 Correct 221 ms 860 KB Output is correct
7 Correct 578 ms 1168 KB Output is correct
8 Correct 668 ms 1360 KB Output is correct
9 Correct 152 ms 836 KB Output is correct
10 Correct 2302 ms 1416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 931 ms 1292 KB Output is correct
2 Correct 898 ms 1368 KB Output is correct
3 Correct 390 ms 1080 KB Output is correct
4 Correct 583 ms 1164 KB Output is correct
5 Correct 631 ms 1188 KB Output is correct
6 Correct 1290 ms 1396 KB Output is correct
7 Correct 145 ms 860 KB Output is correct
8 Correct 532 ms 1364 KB Output is correct
9 Correct 1030 ms 1200 KB Output is correct
10 Correct 2303 ms 1372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 395 ms 860 KB Output is correct
2 Correct 396 ms 860 KB Output is correct
3 Incorrect 1360 ms 1412 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1424 ms 1424 KB Output is correct
2 Correct 1315 ms 1404 KB Output is correct
3 Incorrect 1172 ms 1368 KB Output isn't correct
4 Halted 0 ms 0 KB -