QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#630296#8830. Breaking BadRainingLoveWA 1ms3636kbC++231.8kb2024-10-11 17:40:512024-10-11 17:40:51

Judging History

你现在查看的是最新测评结果

  • [2024-10-11 17:40:51]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3636kb
  • [2024-10-11 17:40:51]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;


int n;
int a[1003][1003];
vector<pair<int,int>> b[5];
int vis[5];
void solve() {
    cin>>n;
    for(int i=1;i<=n;i++) {
        for(int j=1;j<=n;j++) {
            cin>>a[i][j];
            b[a[i][j]].push_back({i,j});
        }
    }

    bitset<1003> vr,vc;
    int cr=0,cc=0;
    while(cr<min(n,8) || cc<min(n,8)) {
        int f=0;
        for(int i=0;i<5;i++) {
            while(!b[i].empty() &&(vr[b[i].back().first] && vc[b[i].back().second])) b[i].pop_back();
            if(b[i].empty()) continue;

            if(cr<min(n,8) && !vr[b[i].back().first]) cr++,vr[b[i].back().first]=1,f=1;
            if(cc<min(n,8) && !vc[b[i].back().second]) cc++,vc[b[i].back().second]=1,f=1;
        }
        if(!f)break;
    }

    vector<int> R;
    vector<int> C;
    vector<int> resR,resC;
    for(int i=1;i<=n;i++) {
        if(!vr[i] && cr<cc ) vr[i]=1,cr++;
        if(!vc[i] && cc<cr ) vc[i]=1,cc++;

        if(vr[i])R.push_back(i);
        else resR.push_back(i);
        if(vc[i])C.push_back(i);
        else resC.push_back(i); 
    }

    int base=0;
    random_shuffle(resR.begin(),resR.end());
    for(int i=0;i<resR.size();i++) {
        base=(base+a[resR[i]][resC[i]])%5;
    }
    
    // for(auto x:R) cout<<"R "<<x<<endl;
    // for(auto y:C) cout<<"C "<<y<<endl;

    do {
        int sum=0;
        for(int i=0;i<R.size();i++) {
            sum=(sum+a[R[i]][C[i]])%5;
        }
        vis[(base+sum)%5]=1;
    } while(next_permutation(C.begin(),C.end()));

    for(int i=0;i<5;i++) {
        if(vis[i]) cout<<"Y";
        else cout<<"N";
    }

}
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);

    int t=1;
    // cin>>t;
    while(t--)
    solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3600kb

input:

2
0 4
4 0

output:

YNNYN

result:

ok "YNNYN"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3628kb

input:

2
1 1
1 1

output:

NNYNN

result:

ok "NNYNN"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3636kb

input:

4
0 0 1 0
0 1 0 1
0 0 0 0
1 1 0 0

output:

YYYYN

result:

ok "YYYYN"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3568kb

input:

4
0 0 0 1
0 1 0 1
1 0 0 0
0 1 0 0

output:

YYYYN

result:

ok "YYYYN"

Test #5:

score: 0
Accepted
time: 1ms
memory: 3596kb

input:

10
1 4 2 0 0 2 0 1 3 3
0 3 1 4 4 1 4 0 2 2
1 4 2 0 0 2 0 1 0 3
0 3 1 4 4 1 4 0 2 2
4 2 0 3 3 0 3 4 1 1
2 0 3 1 1 3 1 2 4 4
4 2 0 3 3 0 3 4 1 1
2 0 3 1 1 3 1 2 4 4
1 4 2 0 0 2 0 1 3 3
3 1 4 2 2 4 2 3 0 0

output:

NYNNY

result:

ok "NYNNY"

Test #6:

score: 0
Accepted
time: 1ms
memory: 3592kb

input:

10
4 4 4 1 3 4 1 4 3 0
3 3 3 0 2 3 0 3 2 4
3 3 3 0 2 3 0 3 2 4
4 4 4 1 3 4 1 4 3 0
2 2 2 4 1 2 4 2 1 3
2 2 2 4 1 3 4 2 1 3
4 4 4 1 3 4 1 4 3 0
3 3 3 0 2 3 0 3 2 4
2 2 2 4 1 2 4 2 1 3
4 4 4 1 3 4 1 1 3 0

output:

YYYNY

result:

ok "YYYNY"

Test #7:

score: -100
Wrong Answer
time: 0ms
memory: 3540kb

input:

10
1 2 0 4 2 3 4 0 2 3
0 1 4 3 1 2 3 4 1 2
4 0 3 2 0 1 2 3 0 1
1 2 0 4 2 3 4 0 2 3
3 4 2 1 4 0 1 2 4 0
0 1 4 3 1 2 3 4 1 2
2 3 1 0 3 4 0 1 3 4
3 1 1 1 4 0 1 2 4 0
1 2 0 4 2 3 4 0 2 3
1 3 0 4 2 3 4 0 2 3

output:

NYYNN

result:

wrong answer 1st words differ - expected: 'NYYYY', found: 'NYYNN'