QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#695632 | #5438. Half Mixed | xzin | RE | 0ms | 0kb | C++14 | 1.3kb | 2024-10-31 20:29:15 | 2024-10-31 20:29:27 |
answer
#include "bits/stdc++.h"
using namespace std;
#define N 1010000
using ll = long long;
int n, m;
long long f[N];
int v[N];
int ck(ll k) {
int p = 1, oe = 1;
for(int i = max(n, m);i >= 2; i--) {
while (k >= f[i]) {
k -= f[i];
for(int j = p; j <= p + i - 1; j++)
v[j] = oe;
oe ^= 1; p += i;
}
}
for(int i = p; i <= max(n, m); i++) {
v[i] = oe; oe ^= 1;
}
}
void sl() {
cin>>n>>m;
for(int i = 1;i <= max(n, m); i++) v[i] = 0;
if(n % 4 == 0 || n % 4 == 3) {
cout<<"Yes\n";
int k = ck(1ll * n * (n + 1) / 4 - n);
for(int i = 1;i <= n; i++) {
for(int j = 1; j <= m; j++)
cout<<v[i]<<" ";
cout<<'\n';
}
}
else if(m % 4 == 0 || m % 4 == 3) {
cout<<"Yes\n";
int k = ck(1ll * m * (m + 1) / 4 - m);
for(int i = 1;i <= n; i++) {
for(int j = 1; j <= m; j++)
cout<<v[j]<<" ";
cout<<'\n';
}
}
else cout<<"No"<<endl;
}
int main(){
// ios::sync_with_stdio(false);
// cin.tie(0);cout.tie(0);
for(int i = 2;i <= 1000000; i++) {
f[i] = i * (i - 1) / 2;
}
int T; cin>>T;
while (T--) sl();
return 0;
}
/*
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
2 2 3 1 1