QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#534491 | #5438. Half Mixed | Sound_Medium | WA | 0ms | 3620kb | C++23 | 1.9kb | 2024-08-27 12:00:11 | 2024-08-27 12:00:11 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n, m;
void solve () {
cin>>n>>m;
int v1=n*(n+1)/2,v2=m*(m+1)/2;
if(v1%2==1&&v2%2==1){
cout<<"No\n";
return ;
}
vector ans(n,vector<int>(m));
if(v1%2==0){
int r1=n*(n+1)/4,r2=n;
vector<int>len;
while(1){
int l=1,r=n;
while(l<r){
int mid=l+r+1>>1;
if(mid*(mid+1)/2+r2-mid<=r1){
l=mid;
}
else r=mid-1;
}
r1-=l*(l+1)/2,r2=r2-l;
len.push_back(l);
if(r1==0)break;
}
int v=1;
vector<int>a;
for(int i=0;i<len.size();i++){
for(int j=1;j<=len[i];j++){
a.push_back(v);
}
v^=1;
}
cout<<"Yes\n";
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cout<<a[i-1]<<" ";
}
cout<<"\n";
}
return ;
}
int r1=m*(m+1)/4,r2=m;
vector<int>len;
while(1){
int l=1,r=r2;
while(l<r){
int mid=l+r+1>>1;
if(mid*(mid+1)/2+r2-mid<=r1)l=mid;
else r=mid-1;
}
r2-=l,r1-=l*(l+1)/2;
len.push_back(l);
if(r1==0)break;
}
vector<int>a;
int v=1;
for(int i=0;i<len.size();i++){
for(int j=1;j<=len[i];j++){
a.push_back(v);
}
v^=1;
}
cout<<"Yes\n";
for(int i=1;i<=n;i++){
for(auto v:a){
cout<<v<<" ";
}
cout<<"\n";
}
}
signed main () {
int T = 1;
std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
// cin>>T;
while (T --) solve ();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3620kb
input:
2 2 3 1 1
output:
No
result:
wrong answer Wrong Verdict (test case 1)