QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#305524 | #7857. (-1,1)-Sumplete | qiling | WA | 0ms | 3928kb | C++14 | 2.3kb | 2024-01-15 15:34:31 | 2024-01-15 15:34:31 |
Judging History
answer
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#define endl '\n'
#define N 4010
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<int> sz(n + 1, 0);
vector<vector<int> > mp(n + 1, vector<int> (n + 1, 0));
for (int i = 1; i <= n; ++ i) {
string s;
cin >> s;
for (int j = 0; j < s.length(); ++ j) {
if(s[j] == '+') {
++ sz[i];
mp[i][j + 1] = 1;
}else mp[i][j + 1] = -1;
}
}
vector<vector<int> > sum(2, vector<int>(n + 1));
for (int i = 0; i < 2; ++ i) {
for (int j = 1; j <= n; ++ j) {
cin >> sum[i][j];
}
}
for (int i = 1; i <= n; ++ i) {
for (int j = 1; j <= n; ++ j) {
if(mp[j][i] == -1) ++ sum[1][i];
if(mp[i][j] == -1) ++ sum[0][i];
}
}
auto No = [] {
cout << "No" << endl;
exit(0);
};
int sum1 = 0, sum2 = 0;
for (int i = 1; i <= n; ++ i) {
if(sum[0][i] > n || sum[1][i] > n || sum[0][i] < 0 || sum[1][i] < 0) No();
sum1 += sum[0][i];
sum2 += sum[1][i];
}
if(sum1 != sum2) No();
vector<vector<int> > ans(n + 1, vector<int> (n + 1, 0));
for (int i = 1; i <= n; ++ i) {
for (int j = 1; j <= n; ++ j) {
if(mp[i][j] == -1) ans[i][j] = 1;
else ans[i][j] = 0;
}
}
for (int i = 1; i <= n; ++ i) {
vector<int> buk[N];
for (int j = 1; j <= n; ++ j) {
buk[sum[1][j]].push_back(j);
}
for (int j = n, c = sum[0][i]; j >= 0; -- j) {
if(buk[j].size()) {
for (int k = 0; k < min(c, (int)buk[j].size()); ++ k) {
if(sum[1][buk[j][k]] <= 0) No();
ans[i][buk[j][k]] = 1 - ans[i][buk[j][k]];
-- sum[1][buk[j][k]];
}
c -= buk[i].size();
}
}
}
cout << "Yes" << endl;
for (int i = 1; i <= n; ++ i) {
for (int j = 1; j <= n; ++ j) {
cout << ans[i][j];
}
cout << endl;
}
return 0;
}
/*
3
+-+
-++
+-+
1 1 1
1 -1 3
3
---
-++
+++
-2 -1 0
-2 -1 0
3
+-+
-++
++-
1 0 2
2 2 -1
*/
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3928kb
input:
3 +-+ -++ +-+ 1 1 1 1 -1 3
output:
No
result:
wrong answer Jury has the answer but participant has not