QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#809047#9874. Matrix Constructionhjh123455WA 2ms3720kbC++231.3kb2024-12-11 11:00:022024-12-11 11:00:03

Judging History

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

  • [2024-12-11 11:00:03]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3720kb
  • [2024-12-11 11:00:02]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
int a[1010][1010];
void solve()
{
    int n, m;
    cin >> n >> m;
    int id = 1, id2 = 2;
    for (int i = 1; i <= n/2*2; i++)
    {
        if (i % 2)
        {
            for (int j = 1; j <= m; j++)
            {
                a[i][j] = id;
                id += 2;
            }
        }
        else
        {
            for (int j = 1; j <= m; j++)
            {
                a[i][j] = id2;
                id2 += 2;
            }
        }
    }
    if(n%2){
        for(int i=1;i<=m;i++){
            if(id<=n*m){
                a[n][i]=id;
                id+=2;
            }
            else {
                a[n][i]=id2;
                id2+=2;
            }
        }
        for(int i=1;i<=m;i++){
            if(a[n][i]%2==0){
                if(a[n][i]+a[n-1][i]==a[n-1][m-1]+a[n-1][m]){
                    swap(a[n][i],a[n][i-1]);
                }
                break;
            }
        }
    }
    cout<<"YES"<<'\n';
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cout<<a[i][j]<<' ';
        }
        cout<<'\n';
    }
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while (t--)
    {
        solve();
    }
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3644kb

input:

2
1 1
2 3

output:

YES
1 
YES
1 3 5 
2 4 6 

result:

ok All test cases passed. (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 3720kb

input:

361
4 9
11 12
16 14
3 7
17 13
1 19
12 3
15 19
11 3
8 18
13 10
8 13
9 18
14 11
7 13
6 16
12 13
1 6
11 15
18 19
5 6
17 19
2 3
17 11
16 19
6 14
5 9
7 2
5 11
15 16
3 15
7 11
16 2
19 15
5 19
2 17
13 12
3 5
19 14
6 3
18 2
16 4
6 8
10 9
17 4
5 16
17 9
16 11
6 9
16 5
3 19
18 9
13 9
12 19
6 13
17 15
13 7
12 ...

output:

YES
1 3 5 7 9 11 13 15 17 
2 4 6 8 10 12 14 16 18 
19 21 23 25 27 29 31 33 35 
20 22 24 26 28 30 32 34 36 
YES
1 3 5 7 9 11 13 15 17 19 21 23 
2 4 6 8 10 12 14 16 18 20 22 24 
25 27 29 31 33 35 37 39 41 43 45 47 
26 28 30 32 34 36 38 40 42 44 46 48 
49 51 53 55 57 59 61 63 65 67 69 71 
50 52 54 56 5...

result:

wrong answer Duplicate sum found for adjacent elements at (2,1) and (3,1) (test case 2)