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 ll long long
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define pii pair<int, int>
#define FF first.first
#define FS first.second
#define pb push_back
using namespace std;
const ll N=1000006, INF=1e18, P=998244353;
int q=1, n, m, x, y, c, l, r, k, a[N], f[N], ansl, ansr, ans, o, u, Ans;
string s;
bitset<1000> b[1000];
int xorr(bitset<1000> x, bitset<1000> y){return min((int)(x^y).count(), (int)(n-(x^y).count()));}
int solve(int i){
int ans=0;
for (int j=0; j<n; j++)ans+=xorr(b[i],b[j]);
return ans;
}
main(){ios_base::sync_with_stdio(false), cin.tie(0);
cin>>n>>k;
Ans=INF;
for (int i=0; i<n; i++){
cin>>s;
int j=0;
for(auto c:s)b[i][j++]=(c=='x');
}
for (int i=0; i<n; i++)Ans=min(solve(i), Ans);
if(k==n){
for (int i=0; i<n; i++){
b[0][i].flip();
Ans=min(solve(0)+1, Ans);
b[0][i].flip();
}
}
puts((Ans<=k) ? "DA":"NE");
}
/*
3 2
xxo
xox
oxx
*/
Compilation message (stderr)
sajam.cpp:22:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
22 | main(){ios_base::sync_with_stdio(false), cin.tie(0);
| ^~~~
sajam.cpp: In function 'int main()':
sajam.cpp:25:9: warning: overflow in conversion from 'long long int' to 'int' changes value from '1000000000000000000' to '-1486618624' [-Woverflow]
25 | Ans=INF;
| ^~~
# | 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... |