QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#806685#9874. Matrix ConstructionWilliamHu#WA 0ms3608kbC++111.5kb2024-12-09 13:53:272024-12-09 13:53:29

Judging History

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

  • [2024-12-09 13:53:29]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3608kb
  • [2024-12-09 13:53:27]
  • 提交

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

Details

Tip: Click on the bar to expand more detailed information

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)