QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#806654 | #9874. Matrix Construction | WilliamHu# | WA | 0ms | 3592kb | C++11 | 1.3kb | 2024-12-09 13:34:53 | 2024-12-09 13:34:54 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
int read()
{
int x = 0, f = 1;
char c = getchar();
while(c != EOF and !isdigit(c))
{
if(c == '-')f = -1;
c = getchar();
}
while(isdigit(c))
{
x = x * 10 + c - '0';
c = getchar();
}
return x * f;
}
int n, m, T;
int a[1010][1010];
int ans;
signed main()
{
T = read();
while(T --)
{
n = read();
m = read();
int flag = 0;
if(n % 2 != 0)
{
if(m % 2 == 0)
{
flag = 1;
swap(n, m);
}
else if(n < m)
{
flag = 1;
swap(n, m);
}
}
cout<<"Yes\n";
int cnt1 = 0, cnt2 = 0;
for(int i = 1;i <= (n/2)*2;i ++)
{
for(int j = 1;j <= m;j ++)
{
if(i % 2 == 0)a[i][j] = 2* (++ cnt2);
else a[i][j] = 2*(++cnt1)-1;
}
}
if(n % 2 == 1)
{
for(int j = 1;j <= m;j ++)
{
if(cnt1 * 2 + 1 <= n * m)a[n][j] = 2*(++cnt1)-1;
else a[n][j] = 2*(++cnt2);
}
}
if(flag)
{
for(int i = 1;i <= m;i ++)
{
for(int j = 1;j <= n;j ++)
{
cout<<a[j][i]<<' ';
}
cout<<endl;
}
}
else
{
for(int i = 1;i <= n;i ++)
{
for(int j = 1;j <= m;j ++)
{
cout<<a[i][j]<<' ';
}
cout<<endl;
}
}
}
return 0;
}
//1 3 5
//2 4 6
//7 9 8
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3592kb
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: 0ms
memory: 3580kb
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 2 23 24 45 46 67 68 89 90 111 112 3 4 25 26 47 48 69 70 91 92 113 114 5 6 27 28 49 50 71 72 93 94 115 116 7 8 29 30 51 52 73 74 95 96 117 118 9 10 31 32 53 54 75 76 97 98 119 120 11 ...
result:
wrong answer Duplicate sum found for adjacent elements at (2,1) and (3,1) (test case 3)