QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#664151 | #5438. Half Mixed | Yurily | WA | 2ms | 3788kb | C++20 | 1.7kb | 2024-10-21 19:23:41 | 2024-10-21 19:23:45 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int MAX=1e6+5;
int n,m;
vector<int> ans[MAX];
void solve(){
cin>>n>>m;
int k=(1+n)*n/2*(1+m)*m/2;
for(int i=1;i<=n;++i){
ans[i].clear();
for(int j=1;j<=m+1;++j)
ans[i].push_back(0);
}
if(k&1){
printf("No\n");
return;
}
if(m%4==0||(1+m)%4==0){
bool flag=0;
int cur=0,now=0,len=0,k=(1+m)*m/4;
while(cur<=m){
cur++,len++;
ans[1][cur]=now;
// cout<<cur<<endl;
if((1+len)*len/2+m-cur>k){
// cout<<cur<<endl;
cur--;
len--;
if(len>=1){
k-=(1+len)*len/2;
len=0;
now^=1;
}
else
break;
}
if(k==0&&cur==m){
flag=1;
break;
}
if(k==0)
break;
}
if(flag){
printf("Yes\n");
for(int i=2;i<=n;++i){
for(int j=1;j<=m;++j)
ans[i][j]=ans[i-1][j]^1;
}
for(int i=1;i<=n;++i){
for(int j=1;j<=m;++j)
printf("%d ",ans[i][j]);
printf("\n");
}
return;
}
}
if(n%4==0||(1+n)%4==0){
bool flag=0;
int cur=0,now=0,len=0,k=(1+n)*n/2;
while(cur<=n){
cur++,len++;
ans[cur][1]=now;
if((1+len)*len/2+n-cur>k){
cur--;
len--;
if(len>=1){
k-=(1+len)*len/2;
len=0;
now^=1;
}
else
break;
}
if(k==0&&cur==n){
flag=1;
break;
}
if(k==0)
break;
}
if(flag){
printf("Yes\n");
for(int j=2;j<=m;++j){
for(int i=1;i<=n;++i)
ans[i][j]=ans[i][j-1]^1;
}
for(int i=1;i<=n;++i){
for(int j=1;j<=m;++j)
printf("%d ",ans[i][j]);
printf("\n");
}
return;
}
}
printf("No\n");
}
signed main(){
int T;
cin>>T;
while(T--){
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 3788kb
input:
2 2 3 1 1
output:
Yes 0 1 0 1 0 1 No
result:
wrong answer 12 Mixed Submatrices Found, but 9 Expected (test case 1)