QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#181240#5438. Half Mixedysghwzp#WA 0ms3632kbC++141.2kb2023-09-16 17:03:092023-09-16 17:03:09

Judging History

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

  • [2023-09-16 17:03:09]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3632kb
  • [2023-09-16 17:03:09]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

int T,n,m;
vector<int>ans,pans;
bool solve(int n,long long m){
    if(m<n)return 0;
    if(m==n){
        for(int i=0;i<n;++i)
            ans.push_back(i);
        return 1;
    }
    //x*x+(n-x)*(n-x) >= m
    int u=sqrt(m);
    while((long long)u*u+(long long)(n-u)*(n-u)<=m)++u;
    for(int i=u;i>=1;--i){
        ans.push_back(i);
        if(solve(n-i,m-(long long)i*i))
            return 1;
        ans.pop_back();
    }
    return 0;
}

void work(int n,int m,int flag=0){
    int z=flag?m:n;
    ans.clear();
    solve(z,(long long)z*(z-1)/2);
    int op=1;
    pans.clear();
    for(int i:ans){
        op^=1;
        for(int j=0;j<i;++j)
            pans.push_back(op);
    }
    for(int i=0;i<n;++i)
        for(int j=0;j<m;++j)
            cout<<pans[flag?j:i]<<" \n"[j==m-1];

}

int main(){
    ios::sync_with_stdio(0);
    for(cin>>T;T --> 0;){
        cin>>n>>m;
        int s=0;
        if(n%4==3||n%4==0)
            work(n,m);
        else
        if(m%4==3||m%4==0)
            work(n,m,1);
        else{
            cout<<"NO"<<endl;
            continue;
        }

    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3632kb

input:

2
2 3
1 1

output:

1 0 0
1 0 0
NO

result:

wrong answer Token "1" doesn't correspond to pattern "Yes|No" (test case 1)