Submission #779148

# Submission time Handle Problem Language Result Execution time Memory
779148 2023-07-11T08:28:50 Z 1075508020060209tc Sajam (COCI18_sajam) C++14
60 / 90
5000 ms 16332 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>>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";





}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 5 ms 6484 KB Output is correct
3 Correct 9 ms 8308 KB Output is correct
4 Correct 18 ms 14676 KB Output is correct
5 Correct 7 ms 8532 KB Output is correct
6 Correct 3 ms 4436 KB Output is correct
7 Correct 270 ms 8116 KB Output is correct
8 Correct 2257 ms 14988 KB Output is correct
9 Correct 27 ms 2904 KB Output is correct
10 Correct 2403 ms 15104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 1 ms 852 KB Output is correct
3 Correct 2 ms 1108 KB Output is correct
4 Correct 1 ms 724 KB Output is correct
5 Correct 1 ms 816 KB Output is correct
6 Correct 2 ms 852 KB Output is correct
7 Correct 4 ms 1080 KB Output is correct
8 Correct 2 ms 724 KB Output is correct
9 Correct 2 ms 952 KB Output is correct
10 Correct 2 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 12076 KB Output is correct
2 Correct 17 ms 13436 KB Output is correct
3 Correct 14 ms 11000 KB Output is correct
4 Correct 10 ms 10324 KB Output is correct
5 Correct 18 ms 14448 KB Output is correct
6 Correct 344 ms 8796 KB Output is correct
7 Correct 987 ms 12016 KB Output is correct
8 Correct 1185 ms 12536 KB Output is correct
9 Correct 169 ms 6016 KB Output is correct
10 Correct 2973 ms 15936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 14004 KB Output is correct
2 Correct 17 ms 13780 KB Output is correct
3 Correct 11 ms 10508 KB Output is correct
4 Correct 13 ms 11896 KB Output is correct
5 Correct 15 ms 12244 KB Output is correct
6 Correct 2913 ms 15580 KB Output is correct
7 Correct 237 ms 7608 KB Output is correct
8 Correct 954 ms 11684 KB Output is correct
9 Correct 1096 ms 12244 KB Output is correct
10 Correct 2824 ms 15928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 10580 KB Output is correct
2 Correct 11 ms 10580 KB Output is correct
3 Correct 3606 ms 15856 KB Output is correct
4 Correct 570 ms 9172 KB Output is correct
5 Correct 767 ms 11092 KB Output is correct
6 Execution timed out 5070 ms 16332 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 27 ms 16052 KB Output is correct
2 Correct 22 ms 15824 KB Output is correct
3 Correct 3240 ms 15160 KB Output is correct
4 Correct 1582 ms 12312 KB Output is correct
5 Correct 997 ms 12380 KB Output is correct
6 Correct 2236 ms 12760 KB Output is correct
7 Correct 826 ms 9172 KB Output is correct
8 Correct 4117 ms 14884 KB Output is correct
9 Correct 1343 ms 10852 KB Output is correct
10 Execution timed out 5066 ms 16204 KB Time limit exceeded
11 Halted 0 ms 0 KB -