This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define PF push_front
#define MP make_pair
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int maxn = 1000 + 5;
bitset <maxn> bs[maxn];
int main(){
ios_base::sync_with_stdio(false);
int n, k;
cin >> n >> k;
int cnt = 0;
for (int i = 0; i < n; i++){
string s;
cin >> s;
for (int j = 0; j < n; j++){
bs[i][j] = (s[j] == 'x');
cnt += bs[i][j];
}
}
if (cnt <= k or n * n - cnt <= k)
return cout << "DA" << endl, 0;
for (int i = 0; i < n; i++){
int tmp = 0;
for (int j = 0; j < n; j++){
if (i == j)
continue;
bs[j] ^= bs[i];
tmp += min(bs[j].count(), n - bs[j].count());
}
if (tmp <= k)
return cout << "DA" << endl, 0;
tmp = 0;
for (int j = 0; j < n; j++){
if (i == j)
continue;
bs[j].flip();
int ret = bs[j].count() - (maxn - n);
tmp += min(ret, n - ret);
}
if (tmp <= k)
return cout << "DA" << endl, 0;
for (int j = 0; j < n; j++){
if (i == j)
continue;
bs[j].flip();
bs[j] ^= bs[i];
}
}
if (k < n)
return cout << "NE" << endl, 0;
for (int x = 0; x < n; x++){
bs[0][x].flip();
int i = 0;
int tmp = 0;
for (int j = 0; j < n; j++){
if (i == j)
continue;
bs[j] ^= bs[i];
tmp += min(bs[j].count(), n - bs[j].count());
}
if (tmp <= k)
return cout << "DA" << endl, 0;
tmp = 0;
for (int j = 0; j < n; j++){
if (i == j)
continue;
bs[j].flip();
int ret = bs[j].count() - (maxn - n);
tmp += min(ret, n - ret);
}
if (tmp <= k)
return cout << "DA" << endl, 0;
for (int j = 0; j < n; j++){
if (i == j)
continue;
bs[j].flip();
bs[j] ^= bs[i];
}
bs[0][x].flip();
}
cout << "NE" << endl, 0;
}
Compilation message (stderr)
sajam.cpp: In function 'int main()':
sajam.cpp:93:25: warning: right operand of comma operator has no effect [-Wunused-value]
cout << "NE" << endl, 0;
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |