QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#299559#7857. (-1,1)-Sumpleteucup-team134RE 0ms0kbC++143.0kb2024-01-07 01:07:502024-01-07 01:07:51

Judging History

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

  • [2024-01-07 01:07:51]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-01-07 01:07:50]
  • 提交

answer

#include<bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
using namespace std;
using u128=__uint128_t;
typedef pair<int,int> pii;

const int mod=998244353;
inline int add(int x,int y){int ret=x+y;if(ret>=mod)ret-=mod;return ret;}
inline int sub(int x,int y){int ret=x-y;if(ret<0)ret+=mod;return ret;}
inline int mul(int x,int y){return ((ll)x*y)%mod;}
inline int step(int base,int pw){int ret=1;while(pw){if(pw&1)ret=mul(ret,base);base=mul(base,base);pw>>=1;}return ret;}
inline int invv(int x){return step(x,mod-2);}

const int maxn=4000+10;

int n,a[maxn][maxn];
pii r[maxn];
int c[maxn],rez[maxn][maxn],orr[maxn],oc[maxn];


int main(){

    ///freopen("test.txt","r",stdin);

    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        string s;
        cin>>s;
        for(int j=0;j<n;j++){
            a[i][j+1]=(s[j]=='+')?1:-1;
        }
    }

    for(int i=1;i<=n;i++){
        scanf("%d",&r[i].ff);
        r[i].ss=i;

        orr[i]=r[i].ff;
    }

    for(int i=1;i<=n;i++){
        scanf("%d",&c[i]);

        oc[i]=c[i];
    }

    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(a[i][j]==1){
                rez[i][j]=1;
            }
            else{
                r[i].ff++;
                c[j]++;
            }
        }
    }


    sort(r+1,r+n+1);


    int e=1;
    int sum=0;
    for(int i=1;i<=n;i++){
        if(r[i].ff<0 || c[i]<0){
            e=0;
            break;
        }
        sum+=r[i].ff-c[i];
    }
    if(!e || sum!=0){
        printf("No\n");
        return 0;
    }

    for(int i=1;i<=n;i++){

        vector<pii>pom;

        for(int j=1;j<=c[i];j++){
            pom.pb(r[n-j+1]);
            if(r[n-j+1].ff==0){
                e=0;
                break;
            }
        }
        if(!e)break;

        for(int j=0;j<pom.size();j++){
            rez[pom[j].ss][i]^=1;
            pom[j].ff--;
        }

        vector<pii>pom2;
        int pt1=1;
        int pt2=0;
        for(int j=1;j<=n;j++){

            pii v1,v2;
            v1={1e9,-1};
            v2={1e9,-1};

            if(pt1<=n-c[i])v1=r[pt1];
            if(pt2<pom.size())v2=pom[pt2];

            if(v1<v2){
                pom2.pb(v1);
                pt1++;
            }
            else{
                pom2.pb(v2);
                pt2++;
            }

        }

        for(int j=0;j<pom2.size();j++)r[j+1]=pom2[j];

        ///sort(r+1,r+n+1);
        for(int j=2;j<=n;j++)
            assert(r[j]>=r[j-1]);

    }
    if(!e){
        printf("No\n");
        return 0;
    }

    printf("Yes\n");
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            printf("%d",(rez[i][j]^1));

            if(rez[i][j]==0)oc[j]-=a[i][j];
            if(rez[i][j]==0)orr[i]-=a[i][j];
        }
        printf("\n");
    }

    int pe=1;
    for(int i=1;i<=n;i++){
        if(oc[i]!=0 || orr[i]!=0)pe=0;
    }
    if(pe==0)while(1){}

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

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

output:


result: