Submission #742379

#TimeUsernameProblemLanguageResultExecution timeMemory
742379jamielimGardening (RMI21_gardening)C++14
100 / 100
199 ms18500 KiB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ii,ii> i4;
typedef vector<int> vi;
const int MOD=1000000007;
const int INF=1012345678;
const ll LLINF=1012345678012345678LL;
const double PI=3.1415926536;
const double EPS=1e-14;

int t;
ll n,m,k;

typedef pair<ii,int> i3;
map<i3,bool> memo;
map<i3,int> jump;

bool dp(int x,int y,int z){
	if(z==0)return 1;
	if(x==1||y==1)return 0; // x=1 or y=1 but z>0
	i3 p=mp(mp(x,y),z);
	if(memo.find(p)!=memo.end())return memo[p];
	if(z>=x+y-2){
		bool b=dp(x-1,y-1,z-(x+y-2));
		if(b){
			jump[p]=1;
			return memo[p]=1;
		}
	}
	if(dp(x,y-1,z)){
		jump[p]=2;
		return memo[p]=1;
	}else if(dp(x-1,y,z)){
		jump[p]=3;
		return memo[p]=1;
	}
	jump[p]=0;
	return memo[p]=0;
}

int main(){
	scanf("%d",&t);
	while(t--){
		scanf("%lld%lld%lld",&n,&m,&k);
		if(n%2==1||m%2==1||n*m<4*k||k<max(n,m)/2){
			printf("NO\n");
			continue;
		}
		int x=n/2,y=m/2,z=n*m/4-k;
		if(dp(x,y,z)){
			printf("YES\n");
			int arr[n][m]; memset(arr,-1,sizeof(arr));
			int sx=0,ex=n-1,sy=0,ey=m-1;
			while(z!=0){
				i3 p=mp(mp(x,y),z);
				if(jump[p]==1){
					for(int i=sx;i<=ex;i++){
						arr[i][sy]=k;
						arr[i][ey]=k;
					}
					for(int i=sy;i<=ey;i++){
						arr[sx][i]=k;
						arr[ex][i]=k;
					}
					sx++;ex--;sy++;ey--;
					x--;y--;z-=(x+y);
					k--;
				}else if(jump[p]==2){
					for(int i=0;i<x;i++){
						arr[sx+2*i][ey-1]=k;
						arr[sx+2*i+1][ey-1]=k;
						arr[sx+2*i][ey]=k;
						arr[sx+2*i+1][ey]=k;
						k--;
					}
					ey-=2;
					y--;
				}else{
					for(int i=0;i<y;i++){
						arr[ex-1][sy+2*i]=k;
						arr[ex-1][sy+2*i+1]=k;
						arr[ex][sy+2*i]=k;
						arr[ex][sy+2*i+1]=k;
						k--;
					}
					ex-=2;
					x--;
				}
			}
			for(int i=0;i<(ex-sx+1)/2;i++){
				for(int j=0;j<(ey-sy+1)/2;j++){
					arr[sx+2*i][sy+2*j]=k;
					arr[sx+2*i][sy+2*j+1]=k;
					arr[sx+2*i+1][sy+2*j]=k;
					arr[sx+2*i+1][sy+2*j+1]=k;
					k--;
				}
			}
			for(int i=0;i<n;i++){
				for(int j=0;j<m;j++){
					printf("%d ",arr[i][j]);
				}
				printf("\n");
			}
		}else printf("NO\n");
	}
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:51:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |  scanf("%d",&t);
      |  ~~~~~^~~~~~~~~
Main.cpp:53:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |   scanf("%lld%lld%lld",&n,&m,&k);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...