QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#817910#9874. Matrix ConstructionlzyWA 0ms3504kbC++231.2kb2024-12-17 14:41:572024-12-17 14:41:58

Judging History

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

  • [2024-12-17 14:41:58]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3504kb
  • [2024-12-17 14:41:57]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
const int N=1e3+10;
ll a[N][N],n,m;
void f1()
{
	ll sum=1;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			a[i][(i+j)%m]=sum;
			sum++;
		}
	}
}
void f2()
{
	ll sum=1;
	for(int j=0;j<m;j++)
	{
		for(int i=0;i<n;i++)
		{
			a[(i+j)%n][j]=sum;
			sum++;
		}
	}
}
int check()
{
	set<ll>st;
	ll ans=0;
	for(int i=0;i<n-1;i++)
	{
		for(int j=0;j<m-1;j++)
		{
			ll t=a[i][j]+a[i+1][j];
			st.insert(t);
			ans++;
			t=a[i][j]+a[i][j+1];
			st.insert(t);
			ans++;
		}
	}
	for(int i=0;i<n-1;i++)
	{
		ll t=a[i][m-1]+a[i+1][m-1];
		ans++;
		st.insert(t);
	}
	//cout<<ans<<" "<<st.size()<<"\n";
	if(ans==st.size())
		return 1;
	else
		return 0;
}
void print()
{
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
			cout<<a[i][j]<<" ";
		cout<<"\n";
	}
}
int main()
{
	IOS;
	int T;
	cin>>T;
	while(T--)
	{
		cin>>n>>m;
		if(n>m)
			f1();
		else
			f2();
		if(check())
		{
			cout<<"Yes\n";
			print();
		}
		else
		{
			f2();
			if(check())
			{
				cout<<"Yes\n";
				print();
			}
			else
			{
				cout<<"No\n";
			}
		}
	}
	return 0;
}
/*


*/

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3504kb

input:

2
1 1
2 3

output:

Yes
1 
Yes
1 4 5 
2 3 6 

result:

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