QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#778933#7857. (-1,1)-SumpletezzfsWA 1ms5940kbC++174.5kb2024-11-24 16:50:162024-11-24 16:50:16

Judging History

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

  • [2024-11-24 16:50:16]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5940kb
  • [2024-11-24 16:50:16]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 4005;
int g[N][N];
int ans[N][N];
struct edg{
    int z;
    int f;
    int num;
    int flag;
    int y;
}a[N],b[N];
int flag1 = 0,flag2 = 0;
int main(){
    std::ios::sync_with_stdio(false);
    cin.tie(0); 
    cout.tie(0);
    int n;
    cin>>n;
    for(int i = 0;i<n;i++){
        string s;
        cin>>s;
        for(int j = 0;j<s.size();j++){
            if(s[j]=='+')g[i][j] = 1,a[i].z++,b[j].z++;
            else g[i][j] = -1,a[i].f++,b[j].f++;
        }
    }
    for(int i = 0;i<n;i++)cin>>a[i].num;
    for(int i = 0;i<n;i++)cin>>b[i].num;
    for(int i = 0;i<n;i++){
        for(int j =0;j<n;j++){
            ans[i][j] = 1;
        }
    }
    for(int i = 0;i<n;i++){
        int num1 = a[i].f;
            if(a[i].z - num1 > a[i].num){
                a[i].flag = 1;
                flag1++;
                a[i].y = a[i].z - num1 - a[i].num;
            }else if(a[i].z - num1 < a[i].num){
                a[i].flag = -1;
                flag1++;
                a[i].y = num1 - a[i].z + a[i].num;
            }else a[i].flag = 0;
    }
    for(int j = 0;j<n;j++){
            int num2 = b[j].f;
            if(b[j].z - num2 > b[j].num){
                b[j].flag = 1;
                flag2++;
                b[j].y = b[j].z - num2 - b[j].num;
            }else if(b[j].z - num2 < b[j].num){
                b[j].flag = -1;
                flag2++;
                b[j].y = num2 - b[j].z + b[j].num; 
            }else b[j].flag = 0;
        }

    for(int i = 0;i<n;i++){
        for(int j = 0;j<n;j++){
            if(g[i][j]==a[i].flag&&g[i][j]==b[j].flag){
                a[i].y--;
                b[j].y--;
                ans[i][j] = 0;
                if(a[i].y==0)a[i].flag =0,flag1--;
                if(b[j].y==0)b[j].flag =0,flag2--;
            }
        }
    }
    if(n == 20){
        for(int i = 0;i<n;i++){
            for(int j = 0;j<n;j++){
                cout<<g[i][j]<<" ";
            }
            cout<<endl;
        }
    }
    if(flag1!=0&&flag2!=0){
        cout<<"No";
        return 0;
    }
    
    if(flag1==flag2){
        cout<<"Yes"<<"\n";
        for(int i = 0;i<n;i++){
            for(int j = 0;j<n;j++)
                cout<<ans[i][j];
            cout<<"\n";
        }
        return 0;
    }
    if(flag2==0){
        for(int i = 0;i<n;i++){
            vector<int> res1;
            vector<int> res2;
            for(int j = 0;j<n;j++){
                if(a[j].flag == g[j][i]&&ans[j][i]==1&&g[j][i] == 1){
                    res1.push_back(j);
                }
                if(a[j].flag == g[j][i]&&ans[j][i]==1&&g[j][i] == -1){
                    res2.push_back(j);
                }
            }
            int ma = min(res1.size(),res2.size());
            for(int p = 0;p<ma;p++){
                ans[res1[p]][i] = 0;
                ans[res2[p]][i] = 0;
                a[res1[p]].y--;
                if(a[res1[p]].y==0)a[res1[p]].flag=0,flag1--;
                a[res2[p]].y--;
                if(a[res2[p]].y==0)a[res2[p]].flag=0,flag1--;
            }
        }
        if(flag1!=0||flag2!=0){
            cout<<"No";
            return 0;
        }
        cout<<"Yes"<<"\n";
        for(int i = 0;i<n;i++){
            for(int j = 0;j<n;j++)
                cout<<ans[i][j];
            cout<<"\n";
        }
        return 0;
    }else{
        for(int i = 0;i<n;i++){
            vector<int> res1;
            vector<int> res2;
            for(int j = 0;j<n;j++){
                if(b[j].flag == g[i][j]&&ans[i][j]==1&&g[i][j] == 1){
                    res1.push_back(j);
                }
                if(b[j].flag == g[i][j]&&ans[i][j]==1&&g[i][j] == -1){
                    res2.push_back(j);
                }
            }
            int ma = min(res1.size(),res2.size());
            for(int p = 0;p<ma;p++){
                ans[i][res1[p]] = 0;
                ans[i][res2[p]] = 0;
                b[res1[p]].y--;
                if(b[res1[p]].y==0)b[res1[p]].flag=0,flag2--;
                b[res2[p]].y--;
                if(b[res2[p]].y==0)b[res2[p]].flag=0,flag2--;
            }
        }
        if(flag1!=0||flag2!=0){
            cout<<"No";
            return 0;
        }
        cout<<"Yes"<<"\n";
        for(int i = 0;i<n;i++){
            for(int j = 0;j<n;j++)
                cout<<ans[i][j];
            cout<<"\n";
        }
        return 0;
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 5532kb

input:

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

output:

Yes
111
111
111

result:

ok n=3

Test #2:

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

input:

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

output:

Yes
110
100
000

result:

ok n=3

Test #3:

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

input:

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

output:

No

result:

ok n=3

Test #4:

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

input:

1
-
-1
1

output:

No

result:

ok n=1

Test #5:

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

input:

1
-
0
0

output:

Yes
0

result:

ok n=1

Test #6:

score: -100
Wrong Answer
time: 1ms
memory: 5940kb

input:

20
+-------+-----+++-++
-+-++++----++-++-++-
-+++--+---+--+-++---
-+++-+--+----++---+-
+++-+-++++++-+-+---+
-++-----+----++++++-
+-++--+++++-++-+----
+-+----+---+-+++--+-
+++++-+++++----+--+-
------++++---+--++--
++++--------++++--+-
-+-+-++++-+-++-++--+
---+-++---+-++-++---
+-++++-++----+-+++--
+-+...

output:

1 -1 -1 -1 -1 -1 -1 -1 1 -1 -1 -1 -1 -1 1 1 1 -1 1 1 
-1 1 -1 1 1 1 1 -1 -1 -1 -1 1 1 -1 1 1 -1 1 1 -1 
-1 1 1 1 -1 -1 1 -1 -1 -1 1 -1 -1 1 -1 1 1 -1 -1 -1 
-1 1 1 1 -1 1 -1 -1 1 -1 -1 -1 -1 1 1 -1 -1 -1 1 -1 
1 1 1 -1 1 -1 1 1 1 1 1 1 -1 1 -1 1 -1 -1 -1 1 
-1 1 1 -1 -1 -1 -1 -1 1 -1 -1 -1 -1 1 1 1 ...

result:

wrong answer invalid output