QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#71936#5371. Matrixzhoukangyang0 2ms3568kbC++171.6kb2023-01-12 16:43:422023-01-12 17:16:23

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-01-12 17:16:23]
  • 评测
  • 测评结果:0
  • 用时:2ms
  • 内存:3568kb
  • [2023-01-12 16:43:42]
  • 提交

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, p[N];
ll a[N][N];
ll sx[N], sy[N];
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 ;
	}
	cout << n * n - 2 * n + 2 << '\n';
	L(i, 1, n) {
		L(j, 1, i - 2) {
			ll w = a[i][j];
			cout << w << ' ';
			L(k, 1, j - 1) p[k] = k;
			L(k, i + 1, n) p[k] = k;
			p[i] = j;
			L(k, j, i - 1) p[k] = k + 1;
			L(k, 1, n) cout << p[k] << ' ', a[k][p[k]] -= w;
			cout << '\n';
		}
	}
	
	L(i, 1, n) {
		L(j, i + 1, n) {
			ll w = a[i][j];
			cout << w << ' ';
			L(k, 1, i - 1) p[k] = k;
			L(k, j + 1, n) p[k] = k;
			p[i] = j;
			L(k, i + 1, j) p[k] = k - 1;
			L(k, 1, n) L(t, k + 1, n) assert(p[k] != p[t]);
			L(k, 1, n) cout << p[k] << ' ', a[k][p[k]] -= w;
			cout << '\n';
		}
	}
	ll w = a[1][1];
	cout << w << ' ';
	L(i, 1, n) cout << i << ' ', a[i][i] -= w;
	cout << '\n';
	L(i, 1, n) L(j, 1, n) assert(!a[i][j]);
}

int main () {
	ios :: sync_with_stdio(false);
	cin.tie(0); cout.tie(0); 
	int t;
	cin >> t;
	while(t--) Main();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 3568kb

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
33885 2 3 1 4 5 
44465 2 3 4 1 5 
23080 1 3 4 2 5 
27473 2 3 4 5 1 
66127 1 3 4 5 2 
38724 1 2 4 5 3 
-63312 2 1 3 4 5 
33247 3 1 2 4 5 
26106 4 1 2 3 5 
48874 5 1 2 3 4 
-147496 1 3 2 4 5 
46545 1 4 2 3 5 
13600 1 5 2 3 4 
-175946 1 2 4 3 5 
82580 1 2 5 3 4 
-92867 1 2 3 5 4 
187532 1 2 3 ...

result:

wrong answer a[i] should be non-negative (test case 3)

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%