QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#459833#8474. Matrices and Sumspropane#AC ✓36ms7584kbC++201.9kb2024-06-30 14:20:372024-06-30 14:20:38

Judging History

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

  • [2024-06-30 14:20:38]
  • 评测
  • 测评结果:AC
  • 用时:36ms
  • 内存:7584kb
  • [2024-06-30 14:20:37]
  • 提交

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][s] = 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: 3628kb

input:

2

output:

Yes
1 0
1 -1

result:

ok OK, Accepted.

Test #2:

score: 0
Accepted
time: 1ms
memory: 3640kb

input:

1

output:

No

result:

ok OK, Accepted.

Test #3:

score: 0
Accepted
time: 0ms
memory: 3476kb

input:

3

output:

No

result:

ok OK, Accepted.

Test #4:

score: 0
Accepted
time: 0ms
memory: 3532kb

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: 3480kb

input:

5

output:

No

result:

ok OK, Accepted.

Test #6:

score: 0
Accepted
time: 1ms
memory: 3488kb

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: 1ms
memory: 3656kb

input:

7

output:

No

result:

ok OK, Accepted.

Test #8:

score: 0
Accepted
time: 0ms
memory: 3436kb

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: 3548kb

input:

9

output:

No

result:

ok OK, Accepted.

Test #10:

score: 0
Accepted
time: 0ms
memory: 3676kb

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 1 0 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 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:

ok OK, Accepted.

Test #11:

score: 0
Accepted
time: 1ms
memory: 3616kb

input:

21

output:

No

result:

ok OK, Accepted.

Test #12:

score: 0
Accepted
time: 0ms
memory: 3516kb

input:

37

output:

No

result:

ok OK, Accepted.

Test #13:

score: 0
Accepted
time: 1ms
memory: 3552kb

input:

73

output:

No

result:

ok OK, Accepted.

Test #14:

score: 0
Accepted
time: 1ms
memory: 3944kb

input:

100

output:

Yes
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 -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 -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 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...

result:

ok OK, Accepted.

Test #15:

score: 0
Accepted
time: 1ms
memory: 3508kb

input:

233

output:

No

result:

ok OK, Accepted.

Test #16:

score: 0
Accepted
time: 0ms
memory: 3468kb

input:

555

output:

No

result:

ok OK, Accepted.

Test #17:

score: 0
Accepted
time: 16ms
memory: 6092kb

input:

666

output:

Yes
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 -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 -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 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...

result:

ok OK, Accepted.

Test #18:

score: 0
Accepted
time: 19ms
memory: 7120kb

input:

888

output:

Yes
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 -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 -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 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...

result:

ok OK, Accepted.

Test #19:

score: 0
Accepted
time: 0ms
memory: 3520kb

input:

999

output:

No

result:

ok OK, Accepted.

Test #20:

score: 0
Accepted
time: 36ms
memory: 7584kb

input:

1000

output:

Yes
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 -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 -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 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...

result:

ok OK, Accepted.