QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#778897 | #7857. (-1,1)-Sumplete | zzfs | WA | 1ms | 7704kb | C++17 | 4.3kb | 2024-11-24 16:42:42 | 2024-11-24 16:42:43 |
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;
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(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;
}
cout<<"NO";
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5908kb
input:
3 +-+ -++ +-+ 1 1 1 1 -1 3
output:
Yes 111 111 111
result:
ok n=3
Test #2:
score: 0
Accepted
time: 0ms
memory: 5580kb
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: 5680kb
input:
3 +-+ -++ ++- 1 0 2 2 2 -1
output:
No
result:
ok n=3
Test #4:
score: 0
Accepted
time: 0ms
memory: 7704kb
input:
1 - -1 1
output:
No
result:
ok n=1
Test #5:
score: 0
Accepted
time: 1ms
memory: 5668kb
input:
1 - 0 0
output:
Yes 0
result:
ok n=1
Test #6:
score: -100
Wrong Answer
time: 1ms
memory: 5684kb
input:
20 +-------+-----+++-++ -+-++++----++-++-++- -+++--+---+--+-++--- -+++-+--+----++---+- +++-+-++++++-+-+---+ -++-----+----++++++- +-++--+++++-++-+---- +-+----+---+-+++--+- +++++-+++++----+--+- ------++++---+--++-- ++++--------++++--+- -+-+-++++-+-++-++--+ ---+-++---+-++-++--- +-++++-++----+-+++-- +-+...
output:
No
result:
wrong answer Jury has the answer but participant has not