Submission #871246

#TimeUsernameProblemLanguageResultExecution timeMemory
871246MisterReaperSajam (COCI18_sajam)C++17
90 / 90
4639 ms588 KiB
#pragma GCC optimize("unroll-loops,O3")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

//author: Ahmet Alp Orakci
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;

bitset <1005> bs[1005];

char getc() {
    char ch;
    cin >> ch;
    return ch;
}

int dist(bitset <1005> &a, bitset <1005> &b) {
    return (a ^ b).count();
}

#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++) {
            bs[i][j] = (getc() == 'o');
        }
    }
    
    for(int i = 1; i <= n; i++) {
        int tot = 0;
        for(int j = 1; j <= n; j++) {
            int c = dist(bs[i], bs[j]);
            tot += min(c, n - c);
        }

        if(tot <= k) {
            return cout << "DA" << "\n", void();
        }
    }

    if(k == n) {
        for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= n; j++) {
                bs[i][j] = bs[i][j] ^ 1;
                
                int tot = 0;
                for(int j = 1; j <= n; j++) {
                    int c = dist(bs[i], bs[j]);
                    tot += min(c, n - c);
                }

                if(tot <= k -1) {
                    return cout << "DA" << "\n", void();
                }

                bs[i][j] = bs[i][j] ^ 1;
            }
        }
    }

    cout << "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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...