#include <bits/stdc++.h>
using namespace std;
#define int long long
#define OYY 1000000000005
#define faster ios_base::sync_with_stdio(false); cin.tie(NULL);
#define mid (start+end)/2
#define mod 1000000007
int32_t main(){
faster
int n,k;
cin>>n>>k;
string s[n],ger[n],sor1[n];
int cev=0,xi=0,oi=0,cev1=0,cev2=0,cev3=0,oim=0,xim=0,gec2=OYY,tr=0;
for(int i=0;i<n;i++){
cin>>s[i];
string f="";
for(int j=0;j<n;j++){
if(s[i][j]=='x'){
f+='o';
tr++;
}
else f+='x';
}
ger[i]=f;
}
int gec=n*n;
if(gec%2!=0)gec++;
gec/=2;
//cout<<gec<<endl;
if(tr==n*n/2 && n%2==0){
cout<<"DA"<<'\n';;
}
else if(k>=gec){
cout<<"DA"<<'\n';
}
else{
for(int i=0;i<n;i++){
if(ger[i][0]=='o'){
sor1[i]=ger[i];
}
else{
sor1[i]=s[i];
}
}
int gec=OYY;
for(int i=0;i<n;i++){
gec=OYY;
gec2=OYY;
xi=0,oi=0;
oim=0,xim=0;
for(int j=0;j<n;j++){
if(sor1[j][i]=='x')xi++;
else oi++;
}
for(int j=0;j<n;j++){
if(sor1[i][j]=='x')xim++;
else oim++;
}
gec=min(oi,xi);
gec2=min(oim,xim);
cev+=gec;
cev1+=gec2;
//cout<<cev<<" "<<cev1<<endl;
}
for(int i=0;i<n;i++){
if(ger[0][i]=='o'){
for(int j=0;j<n;j++){
sor1[j][i]=ger[j][i];
}
}
else{
for(int j=0;j<n;j++){
sor1[j][i]=s[j][i];
}
}
}
gec=OYY;
for(int i=0;i<n;i++){
gec=OYY;
gec2=OYY;
xi=0,oi=0;
for(int j=0;j<n;j++){
if(sor1[i][j]=='x')xi++;
else oi++;
}
for(int j=0;j<n;j++){
if(sor1[j][i]=='x')xim++;
else oim++;
}
gec=min(xi,oi);
gec2=min(xim,oim);
cev2+=gec;
cev3+=gec2;
//cout<<cev2<<" "<<cev3<<endl;
}
int sonuc=min(cev,min(cev1,min(cev2,cev3)));
//}
//////////////////////////////
for(int i=0;i<n;i++){
if(ger[i][1]=='o'){
sor1[i]=ger[i];
}
else{
sor1[i]=s[i];
}
}
gec=OYY;
for(int i=0;i<n;i++){
gec=OYY;
gec2=OYY;
xi=0,oi=0;
oim=0,xim=0;
for(int j=0;j<n;j++){
if(sor1[j][i]=='x')xi++;
else oi++;
}
for(int j=0;j<n;j++){
if(sor1[i][j]=='x')xim++;
else oim++;
}
gec=min(oi,xi);
gec2=min(oim,xim);
cev+=gec;
cev1+=gec2;
}
for(int i=0;i<n;i++){
if(ger[1][i]=='o'){
for(int j=0;j<n;j++){
sor1[j][i]=ger[j][i];
}
}
else{
for(int j=0;j<n;j++){
sor1[j][i]=s[j][i];
}
}
}
gec=OYY;
for(int i=0;i<n;i++){
gec=OYY;
gec2=OYY;
xi=0,oi=0;
for(int j=0;j<n;j++){
if(sor1[i][j]=='x')xi++;
else oi++;
}
for(int j=0;j<n;j++){
if(sor1[j][i]=='x')xim++;
else oim++;
}
gec=min(xi,oi);
gec2=min(xim,oim);
cev2+=gec;
cev3+=gec2;
//cout<<cev2<<" "<<cev3<<endl;
}
int son2=min(cev,min(cev1,min(cev2,cev3)));
if(min(sonuc,son2)<=k)cout<<"DA"<<'\n';
else cout<<"NE"<<'\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Output is correct |
2 |
Correct |
3 ms |
992 KB |
Output is correct |
3 |
Correct |
5 ms |
1364 KB |
Output is correct |
4 |
Correct |
14 ms |
3724 KB |
Output is correct |
5 |
Correct |
5 ms |
1364 KB |
Output is correct |
6 |
Correct |
2 ms |
724 KB |
Output is correct |
7 |
Correct |
13 ms |
1352 KB |
Output is correct |
8 |
Correct |
44 ms |
3848 KB |
Output is correct |
9 |
Correct |
3 ms |
468 KB |
Output is correct |
10 |
Correct |
46 ms |
3952 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
2636 KB |
Output is correct |
2 |
Correct |
12 ms |
3172 KB |
Output is correct |
3 |
Correct |
8 ms |
2132 KB |
Output is correct |
4 |
Correct |
7 ms |
2004 KB |
Output is correct |
5 |
Correct |
13 ms |
3660 KB |
Output is correct |
6 |
Correct |
5 ms |
1492 KB |
Output is correct |
7 |
Correct |
9 ms |
2588 KB |
Output is correct |
8 |
Correct |
10 ms |
2772 KB |
Output is correct |
9 |
Correct |
9 ms |
976 KB |
Output is correct |
10 |
Correct |
53 ms |
5128 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
3336 KB |
Output is correct |
2 |
Correct |
12 ms |
3272 KB |
Output is correct |
3 |
Correct |
8 ms |
2052 KB |
Output is correct |
4 |
Correct |
9 ms |
2508 KB |
Output is correct |
5 |
Correct |
9 ms |
2636 KB |
Output is correct |
6 |
Correct |
16 ms |
4044 KB |
Output is correct |
7 |
Correct |
4 ms |
1232 KB |
Output is correct |
8 |
Correct |
9 ms |
2388 KB |
Output is correct |
9 |
Correct |
29 ms |
2644 KB |
Output is correct |
10 |
Correct |
50 ms |
5196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
1976 KB |
Output is correct |
2 |
Correct |
8 ms |
2000 KB |
Output is correct |
3 |
Incorrect |
21 ms |
5188 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
5132 KB |
Output is correct |
2 |
Correct |
19 ms |
5060 KB |
Output is correct |
3 |
Incorrect |
16 ms |
3808 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |