QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#153801#5438. Half Mixedvalue0WA 1ms3524kbC++201.8kb2023-08-31 01:08:482023-08-31 01:08:50

Judging History

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

  • [2023-08-31 01:08:50]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3524kb
  • [2023-08-31 01:08:48]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
ll n,m,k;

void solve()
{
	cin>>n>>m;
	ll all = n * (n + 1) / 2 * m * (m + 1) / 2;
	if(all & 1)
	{
		puts("No");
		return;
	}
	ll s,t;
	if(n * (n + 1) % 4 == 0)
	{
		s = n * (n + 1) / 4 - n;
		t = n;
	}
	else if(m * (m + 1) % 4 == 0)
	{
		s = m * (m + 1) / 4 - m;
		t = m;
	}
	else
	{
		puts("No");
		return;
	}
	vector<ll> cnt;
	while(s)
	{
		ll a = 1;
		while(a * (a - 1) / 2 <= s)
		{
			a++;
		}
		a--;
		s -= a * (a - 1) /2;
		cnt.push_back(a);
		t -= a;
//		cout<<a<<endl;
	}
	while(t)
	{
		cnt.push_back(1);
		t--;
	}
//	while(s)
//	{
//		ll l = 1;
//		ll r = s;
//		while(l + 1 < r)
//		{
//			ll mid = l + r >> 1;
//			if(check(mid))
//			{
//				l = mid;
//			}
//			else
//			{
//				r = mid;
//			}
//		}
//		t -= l;
//		s -= l * (l + 1) / 2;
//		cnt.push_back(l);
//	}
	vector<vector<int>> g(n + 10,vector<int>(m + 10));
	if(n * (n + 1) % 4 == 0)
	{
		ll cur = 1;
		for(int i = 0;i<cnt.size();i++)
		{
			int len = cnt[i];
			for(int j = cur;j < cur + len;j++)
			{
				for(int k = 1;k<=m;k++)
				{
					if(i & 1)
					{
						g[j][k] = 1;
					}
					else
					{
						g[j][k] = 0;
					}
				}
			}
			cur += len;
		}
	}
	else if(m * (m + 1) % 4 == 0)
	{
		ll cur = 1;
		for(int i = 0;i<cnt.size();i++)
		{
			int len = cnt[i];
			for(int j = cur;j<cur + len;j++)
			{
				for(int k = 1;k<=n;k++)
				{
					if(i & 1)
					{
						g[k][j] = 1;
					}
					else
					{
						g[k][j] = 0;
					}
				}
			}
			cur += len;
		}
	}
	puts("Yes");
	for(int i = 1;i<=n;i++)
	{
		for(int j = 1;j<=m;j++)
		{
			printf("%d ",g[i][j]);
		}
		puts("");
	}
	
	
}

int main()
{
	int t = 1;
//	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3524kb

input:

2
2 3
1 1

output:

No

result:

wrong answer Wrong Verdict (test case 1)