QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#809302#9874. Matrix Construction3343156983WA 6ms3604kbC++14972b2024-12-11 14:01:352024-12-11 14:01:36

Judging History

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

  • [2024-12-11 14:01:36]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:3604kb
  • [2024-12-11 14:01:35]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
        int n,m;
        cin>>n>>m;
        if(m==1){
            cout<<"YES"<<endl;
            cout<<1<<endl;
            continue;
        }
        else if(m%2==0){
            cout<<"YES"<<endl;
            for(int i=1;i<=n;i++,cout<<endl)
                for(int j=1;j<=m;j++)
                    cout<<(i-1)*m+j<<' ';
        }else {
            cout<<"YES"<<endl;
            vector<vector<int>> g(n+1,vector<int>(m+1));
            for(int i=1;i<=n;i++)
                for(int j=1;j<=m;j++)
                    if((i%2)==0)
                        g[i][j]=(i-1)*m+j;
                    else g[i][j]=(i-1)*m+j+1;
            for(int i=1;i<=n;i+=2)
                g[i][m]=(i-1)*m+1;
            for(int i=1;i<=n;i++,cout<<endl)
                for(int j=1;j<=m;j++)
                    cout<<g[i][j]<<' ';
        }
        
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
1 1
2 3

output:

YES
1
YES
2 3 1 
4 5 6 

result:

ok All test cases passed. (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 6ms
memory: 3604kb

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

result:

wrong output format Expected integer, but "YES" found (test case 83)