QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#360072#5438. Half MixedPYD1#RE 4ms58472kbC++142.0kb2024-03-21 11:12:362024-03-21 11:12:36

Judging History

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

  • [2024-03-21 11:12:36]
  • 评测
  • 测评结果:RE
  • 用时:4ms
  • 内存:58472kb
  • [2024-03-21 11:12:36]
  • 提交

answer

#include <set>
#include <map>
#include <list>
#include <queue>
#include <cmath>
#include <time.h>
#include <random>
#include <bitset>
#include <vector>
#include <cstdio>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <memory.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <unordered_map>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define mk make_pair
#define fi first
#define se second

inline int read(){
	int t = 0,f = 1;
	register char c = getchar();
	while (c < 48 || c > 57) f = (c == '-') ? -1 : 1,c = getchar();
	while (c >= 48 && c <= 57) t = (t << 1) + (t << 3) + (c ^ 48),c = getchar();
	return f * t;
}

const int N = 1e6 + 10;
int T,n,m;
ll val[N];

vector <int> res;

map <ll,bool> mp[N];

bool dfs(int n,ll s){
	if (mp[n].find(s) != mp[n].end()){
		if (!mp[n][s]) return 0;
	}
	if (n > s) return 0;
	if (n == 0) return s == 0;
	ll x = upper_bound(val + 1,val + 1000001,s) - val - 1;
	if(s<=6*n)x=3;
	for (ll p = x;p > 0;p--){
		res.emplace_back(p);
		if (dfs(n - p,s - val[p])) {mp[n][s] = 1;return 1;}
		res.pop_back();
	}
	mp[n][s] = 0;
	return 0;
}

void init(){
	for (int i = 1;i <= 1000000;i++) val[i] = 1ll * i * (i + 1) / 2;
}

void solve(){
	n = read(),m = read();
	bool f = 0;
	if ((n & 3) == 1 || (n & 3) == 2) swap(n,m),f = 1;
	if ((n & 3) == 1 || (n & 3) == 2) {puts("No");return ;}
	dfs(n,1ll * n * (n + 1) / 4);
	puts("Yes");
	if (f){
		for (int i = 1;i <= m;i++){
			int c = 0;
			for (int p : res){
				for (int j = 1;j <= p;j++) printf("%d ",c);
				c ^= 1;
			}
			puts("");
		}
	}else{
		int c = 0;
		for (int p : res){
			for (int j = 1;j <= p;j++){
				for (int k = 1;k <= m;k++) printf("%d ",c);puts("");
			}
			c ^= 1;
		}
	}
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	// freopen("out.out","w",stdout);
#endif
	init();
	T = read();
	while (T--) solve();
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 4ms
memory: 58472kb

input:

2
2 3
1 1

output:

Yes
0 1 0 
0 1 0 
No

result:

ok OK, Accepted. (2 test cases)

Test #2:

score: -100
Runtime Error

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:


result: