QOJ.ac

QOJ

ID提交记录ID题目HackerOwner结果提交时间测评时间
#433#69202#2808. GardeningHanx16MsgrQQHFailed.2023-11-07 17:17:542023-11-07 17:17:55

詳細信息

Extra Test:

Accepted
time: 13ms
memory: 14032kb

input:

1
71184 2 35592

output:

YES
35592 35592 
35592 35592 
35591 35591 
35591 35591 
35590 35590 
35590 35590 
35589 35589 
35589 35589 
35588 35588 
35588 35588 
35587 35587 
35587 35587 
35586 35586 
35586 35586 
35585 35585 
35585 35585 
35584 35584 
35584 35584 
35583 35583 
35583 35583 
35582 35582 
35582 35582 
35581 3558...

result:

ok Correct! Azusa and Laika like the garden :) (1 test case)

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#69202#2808. GardeningQQH100 ✓19ms8408kbC++141.8kb2022-12-25 12:09:422022-12-25 12:09:45

answer

#include<bits/stdc++.h>
#define pb push_back
#define MP make_pair
#define pii pair<int,int>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define fi first
#define se second
using namespace std;
typedef long long ll;
template<typename T>void readmain(T &x){
    bool neg=false;unsigned int c=getchar();
    for(;(c^48)>9;c=getchar())if(c=='-')neg=true;
    for(x=0;(c^48)<10;c=getchar())x=(x<<3)+(x<<1)+(c^48);
    if(neg)x=-x;
}
template<typename T>T& read(T &x){readmain(x);return x;}
template<typename T,typename ...Tr>void read(T &x,Tr&... r){readmain(x);read(r...);}
constexpr int N=200005;
int T,n,m,K,num;
vector<int> ans[N];
bool dfs(int n,int m,int K,int sx,int sy){
    int l=max(n,m)/2,r=n*m/4;
    if(n<0||m<0||K<l||K>r||K==r-1||(n==m&&K==l+1))return 0;
    if(!n&&!m)return 1;
    if(dfs(n-2,m-2,K-1,sx+1,sy+1)){
        ++num;
        for(int i=sy+1;i<=sy+m;i++)ans[sx+1][i]=ans[sx+n][i]=num;
        for(int i=sx+1;i<=sx+n;i++)ans[i][sy+1]=ans[i][sy+m]=num;
        return 1;
    }
    if(n<m){
        dfs(n,m-2,K-(n>>1),sx,sy+2);
        for(int i=1;i<=n;i++){
            num+=(i&1);
            ans[sx+i][sy+1]=ans[sx+i][sy+2]=num;
        }
        return 1;
    }
    else{
        dfs(n-2,m,K-(m>>1),sx+2,sy);
        for(int i=1;i<=m;i++){
            num+=(i&1);
            ans[sx+1][sy+i]=ans[sx+2][sy+i]=num;
        }
        return 1;
    }
}
void clear(){num=0;for(int i=1;i<=n;i++)ans[i].resize(m+2);}
void solve(){
    read(n,m,K);clear();
    if((n&1)||(m&1))return puts("NO"),void();
    if(dfs(n,m,K,0,0)){
        puts("YES");
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++)printf("%d ",ans[i][j]);
            puts("");
        }
    }
    else puts("NO");
}
int main(){
    read(T);
    while(T--)solve();
    return 0;
}