QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#360088 | #5438. Half Mixed | PYD1# | TL | 8ms | 58356kb | C++14 | 2.1kb | 2024-03-21 11:28:28 | 2024-03-21 11:28:28 |
Judging History
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 (n < 0) return 0;
if (1ll * n * (n + 1) / 2 < s) return 0;
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;
int x = 0;
if(s<=2*n)x=3;
else if(s<=3*n)x=5;
else x=upper_bound(val + 1,val + 1000001,s) - val - 1;
for (int 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++) cout << 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++) cout << c << ' ';cout << '\n';
}
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 8ms
memory: 58356kb
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
Time Limit Exceeded
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 Yes 0 1 0 No Yes 0 1 0 1 0 1 Yes 0 1 0 1 0 1 0 0 1 0 Yes 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 0 1 0 1 0 0 1 0 1 0 1 Yes 0 0 1 1 0 0 1 1 0 0 1 1 0 0 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 Yes 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 0 1 1 0 1 No Yes 0 1 0 1 0 1 0 0 1...