답안 #1091475

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1091475 2024-09-21T00:02:41 Z tfgs Sajam (COCI18_sajam) C++17
45 / 90
134 ms 1464 KB
#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#include "algo/debug.h"
#endif

#define f first
#define s second
template<class T> using V = vector<T>; 
using vi = V<int>;
using vb = V<bool>;
using vs = V<string>;

#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x) 
#define len(x) (int)((x).size())
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pb push_back
#define lb lower_bound
#define ub upper_bound
template<class T> int lwb(V<T>& a, const T& b) { return lb(all(a),b)-begin(a); }
template<class T> int upb(V<T>& a, const T& b) { return ub(all(a),b)-begin(a); }
template<class T> bool ckmin(T& a, const T& b) { return a > b ? a=b, true : false; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a=b, true : false; }
#define pct __builtin_popcount
#define ctz __builtin_ctz
#define clz __builtin_clz
constexpr int p2(int x) { return (int)1 << x; }
constexpr int bits(int x) { return x == 0 ? 0 : 31-clz(x); } // floor(log2(x)) 

const int N = 1000;
bitset<N> row[N], col[N];

void solve() {
    int n, k; cin >> n >> k;

    if (n == 1) {
        cout << "DA\n";
        return;
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            char c; cin >> c;
            if (c == 'o') {
                row[i].set(j);
                col[j].set(i);
            }
        }
    }

    if (k == n) {
        bool is_perm = true;
        for (int i = 0; i < n; i++) {
            row[0].flip(i);

            for (int j = 1; j < n; j++) {
                int cnt = (row[j]^row[0]).count();
                is_perm &= cnt == 1 || cnt+1 == n;
            }

            row[0].flip(i);
        }
        if (is_perm) {
            cout << "DA\n";
            return;
        }
    }

    for (int i = 0; i < n; i++) {
        int cost = 0;
        for (int j = 0; j < n; j++) if (j != i) {
            int cnt = (row[i]^row[j]).count();
            cost += min(cnt, n-cnt);
        }
        if (cost <= k) {
            cout << "DA\n";
            return;
        }
    }
    for (int i = 0; i < n; i++) {
        int cost = 0;
        for (int j = 0; j < n; j++) if (j != i) {
            int cnt = (col[i]^col[j]).count();
            cost += min(cnt, n-cnt);
        }
        if (cost <= k) {
            cout << "DA\n";
            return;
        }
    }
    cout << "NE\n";
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 360 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 3 ms 604 KB Output is correct
4 Correct 8 ms 1372 KB Output is correct
5 Correct 3 ms 648 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 25 ms 604 KB Output is correct
8 Correct 86 ms 1444 KB Output is correct
9 Correct 6 ms 348 KB Output is correct
10 Correct 89 ms 1464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 6 ms 1164 KB Output is correct
2 Correct 7 ms 1124 KB Output is correct
3 Correct 5 ms 860 KB Output is correct
4 Correct 4 ms 860 KB Output is correct
5 Correct 8 ms 1452 KB Output is correct
6 Correct 28 ms 860 KB Output is correct
7 Correct 55 ms 1116 KB Output is correct
8 Correct 56 ms 1116 KB Output is correct
9 Correct 16 ms 604 KB Output is correct
10 Correct 98 ms 1372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 1116 KB Output is correct
2 Correct 7 ms 1168 KB Output is correct
3 Correct 4 ms 860 KB Output is correct
4 Correct 6 ms 1116 KB Output is correct
5 Correct 6 ms 1112 KB Output is correct
6 Correct 96 ms 1440 KB Output is correct
7 Correct 21 ms 600 KB Output is correct
8 Correct 49 ms 1112 KB Output is correct
9 Correct 64 ms 1116 KB Output is correct
10 Correct 99 ms 1456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 856 KB Output is correct
2 Correct 23 ms 860 KB Output is correct
3 Incorrect 134 ms 1456 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 1336 KB Output is correct
2 Correct 54 ms 1348 KB Output is correct
3 Incorrect 119 ms 1372 KB Output isn't correct
4 Halted 0 ms 0 KB -