답안 #779151

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
779151 2023-07-11T08:30:53 Z 1075508020060209tc Sajam (COCI18_sajam) C++14
90 / 90
3574 ms 8180 KB
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define X first
#define Y second

int n;int K;
int gr[1010][1010];
int ogr[1010][1010];
int rcal(int r){
int cnt=0;
for(int i=1;i<=n;i++){
    cnt+=gr[r][i];
}
return min(cnt,n-cnt);
}

void solve(int rw){
for(int i=1;i<=n;i++){
    if(gr[rw][i]==0){
        for(int j=1;j<=n;j++){
            gr[j][i]^=1;
        }
    }
}
int cal=0;
for(int i=1;i<=n;i++){
    cal+=rcal(i);
}
if(cal<=K){
    cout<<"DA\n";exit(0);
}
}

void rst(){
for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
        gr[i][j]=ogr[i][j];
    }
}
}

signed main(){
cin.tie(0);
ios_base::sync_with_stdio(0);
cin>>n>>K;
for(int i=1;i<=n;i++){
    string s;
    cin>>s;
    s="*"+s;
    for(int j=1;j<=n;j++){
        if(s[j]=='o'){
            gr[i][j]=0;
        }else{
            gr[i][j]=1;
        }
        ogr[i][j]=gr[i][j];
    }
}


for(int i=1;i<=n;i++){
    rst();
    solve(i);
    rst();
    for(int j=1;j<=n;j++){
        gr[i][j]^=1;
    }
    solve(i);
}

if(K==n){
    for(int clm=1;clm<=n;clm++){
        rst();
        for(int i=1;i<=n;i++){
            if(i==clm){
                if(gr[1][i]==1){
                    for(int j=1;j<=n;j++){
                        gr[j][i]^=1;
                    }
                }
            }else{
                if(gr[1][i]==0){
                    for(int j=1;j<=n;j++){
                        gr[j][i]^=1;
                    }
                }
            }
        }
        int ok=1;
        for(int i=1;i<=n;i++){
            if(rcal(i)>=2){ok=0;}
        }
        if(ok){
            cout<<"DA\n";return 0;
        }
    }
    for(int i=1;i<=n;i++){
        ogr[1][i]^=1;
    }
    for(int clm=1;clm<=n;clm++){
        rst();
        for(int i=1;i<=n;i++){
            if(i==clm){
                if(gr[1][i]==1){
                    for(int j=1;j<=n;j++){
                        gr[j][i]^=1;
                    }
                }
            }else{
                if(gr[1][i]==0){
                    for(int j=1;j<=n;j++){
                        gr[j][i]^=1;
                    }
                }
            }
        }
        int ok=1;
        for(int i=1;i<=n;i++){
            if(rcal(i)>=2){ok=0;}
        }
        if(ok){
            cout<<"DA\n";return 0;
        }
    }
}


cout<<"NE\n";





}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 2 ms 3668 KB Output is correct
3 Correct 3 ms 4340 KB Output is correct
4 Correct 5 ms 7468 KB Output is correct
5 Correct 2 ms 4436 KB Output is correct
6 Correct 2 ms 2900 KB Output is correct
7 Correct 240 ms 4300 KB Output is correct
8 Correct 1543 ms 7688 KB Output is correct
9 Correct 22 ms 2004 KB Output is correct
10 Correct 1608 ms 7764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 852 KB Output is correct
3 Correct 2 ms 980 KB Output is correct
4 Correct 1 ms 724 KB Output is correct
5 Correct 1 ms 724 KB Output is correct
6 Correct 2 ms 720 KB Output is correct
7 Correct 3 ms 980 KB Output is correct
8 Correct 2 ms 724 KB Output is correct
9 Correct 2 ms 852 KB Output is correct
10 Correct 2 ms 852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 6228 KB Output is correct
2 Correct 5 ms 6868 KB Output is correct
3 Correct 4 ms 5648 KB Output is correct
4 Correct 3 ms 5332 KB Output is correct
5 Correct 7 ms 7400 KB Output is correct
6 Correct 303 ms 4564 KB Output is correct
7 Correct 806 ms 6216 KB Output is correct
8 Correct 897 ms 6484 KB Output is correct
9 Correct 140 ms 3532 KB Output is correct
10 Correct 1783 ms 8180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7124 KB Output is correct
2 Correct 5 ms 7040 KB Output is correct
3 Correct 3 ms 5460 KB Output is correct
4 Correct 4 ms 6100 KB Output is correct
5 Correct 4 ms 6356 KB Output is correct
6 Correct 1736 ms 7988 KB Output is correct
7 Correct 207 ms 4088 KB Output is correct
8 Correct 712 ms 6052 KB Output is correct
9 Correct 828 ms 6324 KB Output is correct
10 Correct 1768 ms 8180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5460 KB Output is correct
2 Correct 4 ms 5460 KB Output is correct
3 Correct 2135 ms 8120 KB Output is correct
4 Correct 412 ms 4564 KB Output is correct
5 Correct 610 ms 5528 KB Output is correct
6 Correct 3398 ms 7976 KB Output is correct
7 Correct 592 ms 4788 KB Output is correct
8 Correct 737 ms 5076 KB Output is correct
9 Correct 769 ms 5208 KB Output is correct
10 Correct 731 ms 5076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 8148 KB Output is correct
2 Correct 6 ms 8020 KB Output is correct
3 Correct 1978 ms 7720 KB Output is correct
4 Correct 1097 ms 6100 KB Output is correct
5 Correct 767 ms 6132 KB Output is correct
6 Correct 1743 ms 6292 KB Output is correct
7 Correct 685 ms 4620 KB Output is correct
8 Correct 2682 ms 7268 KB Output is correct
9 Correct 1110 ms 5424 KB Output is correct
10 Correct 3574 ms 7904 KB Output is correct