QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#71937 | #5371. Matrix | zhoukangyang | 0 | 2ms | 3480kb | C++17 | 1.5kb | 2023-01-12 17:05:28 | 2023-01-12 17:05:30 |
Judging History
answer
#include<bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); ++i)
#define R(i, j, k) for(int i = (j); i >= (k); --i)
#define ll long long
#define sz(a) ((int) (a).size())
#define vi vector < int >
#define me(a, x) memset(a, x, sizeof(a))
#define ull unsigned long long
#define ld __float128
using namespace std;
const int N = 57;
int n;
int a[N][N];
ll sx[N], sy[N];
int mat[N], p[N];
bool vis[N];
bool dfs(int x) {
L(i, 1, n) if(a[x][i]) {
if(vis[i]) continue;
vis[i] = true;
if(!mat[i] || dfs(mat[i])) return mat[i] = x, p[x] = i, true;
}
return false;
}
vector < vi > vc;
void Main() {
cin >> n;
me(sx, 0), me(sy, 0);
L(i, 1, n) {
L(j, 1, n) {
cin >> a[i][j];
sx[i] += a[i][j];
sy[j] += a[i][j];
}
}
L(i, 1, n) L(j, 1, n) if(a[i][j] < 0) {
cout << -1 << '\n';
return ;
}
L(i, 1, n) if(sx[i] != sx[1] || sy[i] != sy[1]) {
cout << -1 << '\n';
return ;
}
vc.clear();
bool ok = 1;
L(i, 1, n) dfs(i);
while(ok) {
int mn = 1e9;
L(i, 1, n) mn = min(mn, a[i][p[i]]);
vi tmp = vi{mn};
L(i, 1, n) tmp.emplace_back(a[i][p[i]]), a[i][p[i]] -= mn;
vc.emplace_back(tmp);
L(i, 1, n) {
if(!a[i][p[i]]) {
mat[p[i]] = 0, p[i] = 0, me(vis, 0);
if(!dfs(i))
ok = 0;
}
}
}
cout << sz(vc) << '\n';
for(auto u : vc) {
for(auto v : u) cout << v << ' ';
cout << '\n';
}
}
int main () {
ios :: sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int t;
cin >> t;
while(t--) Main();
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 3480kb
input:
10 5 41 18467 6334 26500 2995 19169 15724 11478 29358 -21392 26962 24464 5705 28145 -30939 23281 16827 9961 491 3777 -15116 -21145 20859 -30157 99896 5 4827 5436 32391 14604 1869 3902 153 292 12382 42398 17421 18716 19718 19895 -16623 5447 21726 14771 11538 5645 27530 13096 -8045 708 25838 5 41879 4...
output:
-1 -1 17 8106 41879 40023 31353 43856 8106 23923 42511 47534 23923 39457 27473 15534 33247 46545 33885 15534 66127 13600 26106 13600 20876 44465 38724 23080 48874 44915 23247 23080 52187 167 25794 31917 167 30865 29107 18351 25627 31750 18351 41759 28940 7276 7276 21835 7276 23408 10589 3313...
result:
wrong answer Integer 41879 violates the range [1, 5] (test case 3)
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%