답안 #870847

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
870847 2023-11-09T09:50:38 Z vjudge1 Sajam (COCI18_sajam) C++17
0 / 90
5000 ms 2188 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];

char f(char x) {
    if(x == 'o')
        return 'x';
    else if(x == 'x')
        return 'o';
    else
        return assert(false), char(23);
}

#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[i][x] = f(matrix[i][x]);
        }
    };
    
    auto reversey = [&](int x) -> void {
        for(int i = 1; i <= n; i++) {
            matrix[x][i] = f(matrix[x][i]);
        }
    };

    int anss = k +1;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            if(matrix[i][j] == 'o') {
                reversex(j);
            }
        }

        int cnt = 0;
        for(int j = 1; j <= n; j++) {
            int nw = 0;
            for(int k = 1; k <= n; k++) {
                nw += matrix[k][j] == 'o';
            }

            cnt += min(nw, n - nw);
        }
        
        /*
        cerr << i << " :: " << cnt << "\n";
        for(int t = 1; t <= n; t++) {
            for(int l = 1; l <= n; l++) {
                cerr << matrix[t][l];
            }
            cerr << "\n";
        }
        */

        anss = min(anss, cnt);
    }

    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            if(matrix[j][i] == 'o') {
                reversey(j);
            }
        }

        int cnt = 0;
        for(int j = 1; j <= n; j++) {
            int nw = 0;
            for(int k = 1; k <= n; k++) {
                nw += matrix[j][k] == 'o';
            }

            cnt += min(nw, n - nw);
        }
        
        /*
        cerr << i << " :: " << cnt << "\n";
        for(int t = 1; t <= n; t++) {
            for(int l = 1; l <= n; l++) {
                cerr << matrix[t][l];
            }
            cerr << "\n";
        }
        */

        anss = min(anss, cnt);
    }

    cout << (anss <= k ? "DA" : "NE") << "\n";
    
    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 348 KB Output is correct
2 Correct 139 ms 1032 KB Output is correct
3 Correct 264 ms 1208 KB Output is correct
4 Correct 1534 ms 2108 KB Output is correct
5 Correct 269 ms 1116 KB Output is correct
6 Correct 64 ms 860 KB Output is correct
7 Correct 698 ms 1192 KB Output is correct
8 Correct 4926 ms 2140 KB Output is correct
9 Correct 68 ms 604 KB Output is correct
10 Execution timed out 5034 ms 2136 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 2 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 865 ms 1892 KB Output is correct
2 Correct 1174 ms 1876 KB Output is correct
3 Correct 623 ms 1564 KB Output is correct
4 Correct 514 ms 1468 KB Output is correct
5 Correct 1512 ms 2092 KB Output is correct
6 Correct 298 ms 1116 KB Output is correct
7 Correct 812 ms 1620 KB Output is correct
8 Correct 901 ms 1628 KB Output is correct
9 Correct 389 ms 1000 KB Output is correct
10 Execution timed out 5057 ms 2140 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1314 ms 1808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 556 ms 1372 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2029 ms 2188 KB Output is correct
2 Incorrect 1929 ms 2164 KB Output isn't correct
3 Halted 0 ms 0 KB -