QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#778955 | #7857. (-1,1)-Sumplete | zzfs | WA | 1ms | 5860kb | C++17 | 4.6kb | 2024-11-24 16:53:10 | 2024-11-24 16:53:11 |
Judging History
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;
if(n==20&&i>=14){
cout<<s<<endl;
}
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;
if(n==20){
cout<<a[i].num<<" ";
}
}
if(n==20)
cout<<endl;
for(int i = 0;i<n;i++){
cin>>b[i].num;
if(n==20){
cout<<a[i].num<<" ";
}
}
if(n==20)
cout<<endl;
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(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: 5596kb
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: 5584kb
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: 5792kb
input:
3 +-+ -++ ++- 1 0 2 2 2 -1
output:
No
result:
ok n=3
Test #4:
score: 0
Accepted
time: 1ms
memory: 5652kb
input:
1 - -1 1
output:
No
result:
ok n=1
Test #5:
score: 0
Accepted
time: 0ms
memory: 5620kb
input:
1 - 0 0
output:
Yes 0
result:
ok n=1
Test #6:
score: -100
Wrong Answer
time: 1ms
memory: 5860kb
input:
20 +-------+-----+++-++ -+-++++----++-++-++- -+++--+---+--+-++--- -+++-+--+----++---+- +++-+-++++++-+-+---+ -++-----+----++++++- +-++--+++++-++-+---- +-+----+---+-+++--+- +++++-+++++----+--+- ------++++---+--++-- ++++--------++++--+- -+-+-++++-+-++-++--+ ---+-++---+-++-++--- +-++++-++----+-+++-- +-+...
output:
+-+-++--++--+-++---+ --++-+--++--+-+-+-++ --+---+-----+-++--+- ----+--++-+---+-++++ -++--+++--++----++++ ++--+----++--++---++ -2 3 -2 -4 6 -1 -2 -1 0 -4 -6 1 2 3 -4 0 -1 -2 1 -1 -2 3 -2 -4 6 -1 -2 -1 0 -4 -6 1 2 3 -4 0 -1 -2 1 -1 No
result:
wrong answer invalid output