QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#289758#7857. (-1,1)-Sumpleteucup-team139#WA 1ms3508kbC++172.2kb2023-12-23 23:18:212023-12-23 23:18:21

Judging History

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

  • [2023-12-23 23:18:21]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3508kb
  • [2023-12-23 23:18:21]
  • 提交

answer

#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;

void solve(int t){
    int n;
    cin>>n;
    
    vector<string> mat(n);
    for(int i=0;i<n;i++){
        cin>>mat[i];
    }

    vector r(n,0),c(n,0);
    
    for(int i=0;i<n;i++)cin>>r[i];
    for(int i=0;i<n;i++)cin>>c[i];
    
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(mat[i][j]=='-'){
                r[i]++;
                c[j]++;
            }
        }
    }
    
    long long totr=0,totc=0;
    for(int i=0;i<n;i++){
        if(r[i]<0 || c[i]<0){
            cout<<"No\n";
            return;
        }
        totr+=r[i];
        totc+=c[i];
    }
    
    if(totr!=totc){
        cout<<"No\n";
    }else{
        
        vector ok(n,vector(n,false));
        for(int i=0;i<2*n;i++){
            int curr=0,mode=0;
            for(int j=0;j<n;j++){
                if(r[j]>curr){
                    curr=r[j];
                    mode=j;
                }
                if(c[j]>curr){
                    curr=c[j];
                    mode=n+j;
                }
            }
            if(curr==0)break;
            
            if(mode<n){
                for(int i=0;i<n;i++){
                    if(!ok[mode][i] && r[mode]>0 && c[i]>0){
                        ok[mode][i]=true;
                        r[mode]--;
                        c[i]--;
                    }
                }
            }else{
                mode-=n;
                for(int i=0;i<n;i++){
                    if(!ok[i][mode] && r[i]>0 && c[mode]>0){
                        ok[i][mode]=true;
                        r[i]--;
                        c[mode]--;
                    }
                }
            }
        }
        
        cout<<"Yes\n";
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if(ok[i][j]^(mat[i][j]=='+')){
                    cout<<"0";
                }else{
                    cout<<"1";
                }
            }
            cout<<"\n";
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int t=1;
    //cin>>t;
    for(int i=1;i<=t;i++)solve(i);
    
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
+-+
-++
+-+
1 1 1
1 -1 3

output:

Yes
111
001
001

result:

ok n=3

Test #2:

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

input:

3
---
-++
+++
-2 -1 0
-2 -1 0

output:

Yes
110
100
000

result:

ok n=3

Test #3:

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

input:

3
+-+
-++
++-
1 0 2
2 2 -1

output:

Yes
100
000
111

result:

wrong answer wrong sum at row 3