QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#557003#5438. Half MixedPonyHexWA 15ms3552kbC++142.4kb2024-09-10 23:37:582024-09-10 23:37:59

Judging History

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

  • [2024-09-10 23:37:59]
  • 评测
  • 测评结果:WA
  • 用时:15ms
  • 内存:3552kb
  • [2024-09-10 23:37:58]
  • 提交

answer

#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;
#define ll long long
#define double long double
#define lc u<<1
#define rc u<<1|1
#define X first
#define Y second
//#define int long long
const int N = 5e5 + 50;
const int M = 2005;
const ll maxm = 1e18 + 5;
const ll mod = 998244353;




void solve()
{
	///首先,ans是可以由一行递推出来的
	//问题就变成了,对于n/m在一行中是否能找到结论
	//如果是奇数,显然是找不到答案的,如果是偶数
	//我们直接贪心的放,
	ll n, m; cin >> n >> m;
	if (n % 2 == 1 && m % 2 == 1) {
		cout << "No" << endl; return;
	}
	if ((n) * (n + 1) % 4==0) {
		//cout << "Yes" << endl;
		vector<int>v;
		v.push_back(114514);
		ll sum = (n) * (n + 1) / 4;
		//放纯的(1)如果放不了,就放0
		ll idx = n;
		int ans = 1;
		while (1) {
			if (idx <= 0)break;
			ll val = (idx) * (idx + 1) / 2;
			if (val > sum||val==sum&&idx+v.size()!=n+1) {
				idx--; continue;
			}
			sum -= val;
			for (int i = 1; i <= idx; i++) {
				v.push_back(ans);
			}
			ans = !ans;
		}
		if (v.size() == n+1) {
			cout << "Yes" << endl;
			for (int i = 1; i <= n; i++) {
				cout << v[i];
				for (int j = 2; j <= m; j++) {
					cout << " " << v[i];
				}
				cout << endl;
			}
			return;
		}
	}
	if ((m) * (m + 1) % 4==0) {
		//cout << "Yes" << endl;
		vector<int>v;
		v.push_back(114514);
		ll sum = (m) * (m + 1) / 4;
		//放纯的(1)如果放不了,就放0
		ll idx = m;
		int ans = 1;
		while (1) {
			if (idx <= 0)break;
			ll val = (idx) * (idx + 1) / 2;
			if (val > sum||val==sum&&v.size()+idx!=m+1) {
				idx--; continue;
			}
			sum -= val;
			for (int i = 1; i <= idx; i++) {
				v.push_back(ans);
			}
			ans = !ans;
		}
		if (v.size() == m+1) {
			cout << "Yes" << endl;
			for (int i = 1; i <= n; i++) {
				cout << v[1];
				for (int j = 2; j <= m; j++) {
					cout << " " << v[j];
				}
				cout << endl;
			}
			return;
		}
	}
	cout << "No" << endl;
	return;
}


signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int T = 1;
	std::cin >> T;
	while (T--)
		solve();
	return 0;
}


ll ksm(ll a, ll b) {
	ll base = a;
	ll ans = 1;
	while (b) {
		if (b & 1)ans *= base;
		base *= base;
		b >>= 1;
	}
	return ans;
}
ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3528kb

input:

2
2 3
1 1

output:

Yes
1 0 1
1 0 1
No

result:

ok OK, Accepted. (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 15ms
memory: 3552kb

input:

5382
1 1
1 2
2 1
1 3
2 2
3 1
1 4
2 3
3 2
4 1
1 5
2 4
3 3
4 2
5 1
1 6
2 5
3 4
4 3
5 2
6 1
1 7
2 6
3 5
4 4
5 3
6 2
7 1
1 8
2 7
3 6
4 5
5 4
6 3
7 2
8 1
1 9
2 8
3 7
4 6
5 5
6 4
7 3
8 2
9 1
1 10
2 9
3 8
4 7
5 6
6 5
7 4
8 3
9 2
10 1
1 11
2 10
3 9
4 8
5 7
6 6
7 5
8 4
9 3
10 2
11 1
1 12
2 11
3 10
4 9
5 8
6 ...

output:

No
No
No
No
No
No
Yes
1 1 0 1
Yes
1 0 1
1 0 1
Yes
1 1
0 0
1 1
Yes
1
1
0
1
No
Yes
1 1 0 1
1 1 0 1
No
Yes
1 1
1 1
0 0
1 1
No
No
No
Yes
1 1 1 1
0 0 0 0
1 1 1 1
Yes
1 1 1
1 1 1
0 0 0
1 1 1
No
No
No
No
No
Yes
1 1 1 1
1 1 1 1
0 0 0 0
1 1 1 1
No
No
No
Yes
1 1 1 1 1 0 1 0
Yes
1 1 1 1 0 0 1
1 1 1 1 0 0 1
Yes...

result:

wrong answer Wrong Verdict (test case 4)