QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#299548 | #7857. (-1,1)-Sumplete | ucup-team134 | RE | 0ms | 0kb | C++14 | 3.2kb | 2024-01-07 00:49:24 | 2024-01-07 00:49:24 |
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--;
///r[n-j].ff--;
}
///sort(r+1,r+n+1);
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];
///assert(pt1)
}
if(pt2<pom.size())v2=pom[pt2];
if(v1<v2){
pom2.pb(v1);
pt1++;
}
else{
pom2.pb(v2);
pt2++;
}
assert(pom2.back().ss!=-1);
}
assert(pom2.size()==n);
for(int j=0;j<pom2.size();j++)r[j+1]=pom2[j];
for(int j=2;i<=n;i++){
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;
}
詳細信息
Test #1:
score: 0
Runtime Error
input:
3 +-+ -++ +-+ 1 1 1 1 -1 3