#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];
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);
}
}
if (k == n) {
for (int i = 0; i < n; i++) {
row[0].flip(i);
int cost = 0;
for (int j = 1; j < n; j++) {
int cnt = (row[j]^row[0]).count();
cost += min(cnt, n-cnt);
}
row[0].flip(i);
if (cost <= k-1) {
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;
}
}
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 |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
3 |
Correct |
5 ms |
748 KB |
Output is correct |
4 |
Correct |
9 ms |
1372 KB |
Output is correct |
5 |
Correct |
3 ms |
768 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
16 ms |
764 KB |
Output is correct |
8 |
Correct |
50 ms |
1372 KB |
Output is correct |
9 |
Correct |
3 ms |
348 KB |
Output is correct |
10 |
Correct |
52 ms |
1368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
860 KB |
Output is correct |
2 |
Correct |
7 ms |
1084 KB |
Output is correct |
3 |
Correct |
5 ms |
860 KB |
Output is correct |
4 |
Correct |
4 ms |
832 KB |
Output is correct |
5 |
Correct |
8 ms |
1112 KB |
Output is correct |
6 |
Correct |
20 ms |
812 KB |
Output is correct |
7 |
Correct |
29 ms |
1096 KB |
Output is correct |
8 |
Correct |
32 ms |
1116 KB |
Output is correct |
9 |
Correct |
10 ms |
604 KB |
Output is correct |
10 |
Correct |
64 ms |
1624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
1084 KB |
Output is correct |
2 |
Correct |
8 ms |
1128 KB |
Output is correct |
3 |
Correct |
4 ms |
860 KB |
Output is correct |
4 |
Correct |
5 ms |
1016 KB |
Output is correct |
5 |
Correct |
6 ms |
968 KB |
Output is correct |
6 |
Correct |
49 ms |
1368 KB |
Output is correct |
7 |
Correct |
12 ms |
604 KB |
Output is correct |
8 |
Correct |
28 ms |
860 KB |
Output is correct |
9 |
Correct |
33 ms |
856 KB |
Output is correct |
10 |
Correct |
64 ms |
1372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
860 KB |
Output is correct |
2 |
Correct |
23 ms |
948 KB |
Output is correct |
3 |
Correct |
35 ms |
1372 KB |
Output is correct |
4 |
Correct |
18 ms |
664 KB |
Output is correct |
5 |
Correct |
9 ms |
860 KB |
Output is correct |
6 |
Correct |
88 ms |
1396 KB |
Output is correct |
7 |
Correct |
26 ms |
604 KB |
Output is correct |
8 |
Correct |
43 ms |
832 KB |
Output is correct |
9 |
Correct |
34 ms |
604 KB |
Output is correct |
10 |
Correct |
31 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
53 ms |
1372 KB |
Output is correct |
2 |
Correct |
51 ms |
1372 KB |
Output is correct |
3 |
Correct |
30 ms |
1372 KB |
Output is correct |
4 |
Correct |
28 ms |
860 KB |
Output is correct |
5 |
Correct |
9 ms |
1196 KB |
Output is correct |
6 |
Correct |
55 ms |
1088 KB |
Output is correct |
7 |
Correct |
51 ms |
604 KB |
Output is correct |
8 |
Correct |
72 ms |
1112 KB |
Output is correct |
9 |
Correct |
42 ms |
856 KB |
Output is correct |
10 |
Correct |
122 ms |
1276 KB |
Output is correct |