QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#806685 | #9874. Matrix Construction | WilliamHu# | WA | 0ms | 3608kb | C++11 | 1.5kb | 2024-12-09 13:53:27 | 2024-12-09 13:53:29 |
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()
{
// freopen("std.in", "r", stdin);
// freopen("std.out", "w", stdout);
T = read();
while(T --)
{
n = read();
m = read();
int flag = 0;
//cout<<n<<' '<<m<<endl;
if(n % 2 != 0)
{
if(m % 2 == 0)
{
flag = 1;
swap(n, m);
}
else if(n < m)
{
flag = 1;
swap(n, m);
}
}
if(n%2==0)
{
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: 0
Wrong Answer
time: 0ms
memory: 3608kb
input:
2 1 1 2 3
output:
Yes 1 Yes 1 2 5 3 4 6
result:
wrong answer Duplicate sum found for adjacent elements at (2,1) and (2,2) (test case 2)