QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#459828 | #8474. Matrices and Sums | propane# | WA | 1ms | 3652kb | C++20 | 2.0kb | 2024-06-30 14:15:56 | 2024-06-30 14:15:56 |
Judging History
answer
#include<iostream>
#include<cstring>
#include<vector>
#include<set>
#include<cassert>
using namespace std;
using LL = long long;
int a[1005][1005];
int ans2[2][2]{
{1, 0},
{1, -1},
};
int ans4[4][4]{
{-1, -1, -1, 0},
{0, -1, -1, 1},
{1, 1, 1, 1},
{1, 1, -1, 1},
};
void solve(int s, int n){
if (n <= 4){
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
a[s + i][s + j] = (n == 2 ? ans2[i][j] : ans4[i][j]);
}
}
return;
}
for(int i = 1; i <= n; i++){
a[s][s + i - 1] = -1;
}
for(int i = 1; i <= n; i++){
a[s + i - 1][s + n - 1] = 1;
}
for(int i = 1; i <= n; i++){
a[s + n - 1][s + i - 1] = -1;
}
for(int i = 1; i <= n; i++){
a[s + i - 1][1] = 1;
}
for(int i = 2; i <= n - 1; i++){
a[s + i - 1][s + 1] = -1;
}
for(int i = 2; i <= n - 1; i++){
a[s + 1][s + i - 1] = 1;
}
for(int i = 2; i <= n - 1; i++){
a[s + i - 1][s + n - 2] = -1;
}
for(int i = 2; i <= n - 1; i++){
a[s + n - 2][s + i - 1] = 1;
}
a[s + 1][s + 1] = a[n + s - 2][n + s - 2] = 0;
solve(s + 2, n - 4);
}
int main(){
#ifdef LOCAL
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int n;
cin >> n;
if (n % 2 == 1){
cout << "No" << '\n';
return 0;
}
solve(1, n);
vector<int> row(n + 1), col(n + 1);
set<int> s;
cout << "Yes" << '\n';
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
cout << a[i][j] << " \n"[j == n];
row[i] += a[i][j];
col[j] += a[i][j];
}
}
for(int i = 1; i <= n; i++){
s.insert(row[i]);
s.insert(col[i]);
}
// assert(s.size() == 2 * n);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3424kb
input:
2
output:
Yes 1 0 1 -1
result:
ok OK, Accepted.
Test #2:
score: 0
Accepted
time: 0ms
memory: 3540kb
input:
1
output:
No
result:
ok OK, Accepted.
Test #3:
score: 0
Accepted
time: 1ms
memory: 3468kb
input:
3
output:
No
result:
ok OK, Accepted.
Test #4:
score: 0
Accepted
time: 1ms
memory: 3556kb
input:
4
output:
Yes -1 -1 -1 0 0 -1 -1 1 1 1 1 1 1 1 -1 1
result:
ok OK, Accepted.
Test #5:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
5
output:
No
result:
ok OK, Accepted.
Test #6:
score: 0
Accepted
time: 0ms
memory: 3572kb
input:
6
output:
Yes 1 -1 -1 -1 -1 1 1 0 1 1 -1 1 1 -1 1 0 -1 1 1 -1 1 -1 -1 1 1 1 1 1 0 1 1 -1 -1 -1 -1 -1
result:
ok OK, Accepted.
Test #7:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
7
output:
No
result:
ok OK, Accepted.
Test #8:
score: 0
Accepted
time: 0ms
memory: 3504kb
input:
8
output:
Yes 1 -1 -1 -1 -1 -1 -1 1 1 0 1 1 1 1 -1 1 1 -1 -1 -1 -1 0 -1 1 1 -1 0 -1 -1 1 -1 1 1 -1 1 1 1 1 -1 1 1 -1 1 1 -1 1 -1 1 1 1 1 1 1 1 0 1 1 -1 -1 -1 -1 -1 -1 -1
result:
ok OK, Accepted.
Test #9:
score: 0
Accepted
time: 0ms
memory: 3508kb
input:
9
output:
No
result:
ok OK, Accepted.
Test #10:
score: -100
Wrong Answer
time: 1ms
memory: 3652kb
input:
10
output:
Yes 1 -1 -1 -1 -1 -1 -1 -1 -1 1 1 0 1 1 1 1 1 1 -1 1 1 -1 -1 -1 -1 -1 -1 1 -1 1 1 -1 0 0 1 1 -1 1 -1 1 1 -1 0 -1 1 0 -1 1 -1 1 1 -1 0 -1 1 -1 -1 1 -1 1 1 -1 0 1 1 1 0 1 -1 1 1 -1 -1 -1 -1 -1 -1 -1 -1 1 1 1 1 1 1 1 1 1 0 1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1
result:
wrong answer Duplicated Sum