답안 #645593

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
645593 2022-09-27T12:08:02 Z TimDee Gardening (RMI21_gardening) C++17
11 / 100
19 ms 852 KB
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for (int i=0;i<n;++i)
#define prn {cout<<"NO\n";return;}
#define pry cout<<"YES\n";

void f(int n, int m, int k, int depth) {
	int l=((n+2)/4)*(m/2), r=(n/2)*(m/2);
	if (k-depth>r) prn;
	if (n==0) prn;
	int x=k-depth;
	if (l<=x && x<=r && (x!=(r-1))) {
		pry;
		int y=(n/2)*(m/2)-x;
		vector<vector<int>> a(n+2*depth,vector<int>(m+2*depth,1));
		for (int i=0; i<depth; ++i) {
			for (int j=i; j<m+2*depth; ++j) a[i][j]=a[n+2*depth-1-i][j]=i+1;
			for (int j=i; j<n+2*depth; ++j) a[j][i]=a[j][m+2*depth-1-i]=i+1;
		}

		int col=depth+1;
		int last=depth;
		for (int i=0; i+3<n; i+=4) {
			int need=min(2*y,m);
			for (int j=0; j<need; ++j) a[depth+i][depth+j]=a[depth+i+3][depth+j]=col;
			a[depth+i+1][depth]=a[depth+i+2][depth]=a[depth+i+1][depth+need-1]=a[depth+i+2][depth+need-1]=col;
			col++;
			for (int j=1; j<need-1; j+=2) {
				a[depth+i+1][depth+j]=a[depth+i+2][depth+j]=a[depth+i+1][depth+j+1]=a[depth+i+2][depth+j+1]=col;
				col++;
			}
			y-=need/2;

			for (int j=need; j<m; ++j) {
				a[depth+i][depth+j]=a[depth+i][depth+j+1]=a[depth+i+1][depth+j]=a[depth+i+1][depth+j+1]=col++;
				a[depth+i+2][depth+j]=a[depth+i+2][depth+j+1]=a[depth+i+3][depth+j]=a[depth+i+3][depth+j+1]=col++;
			}
			last=i+4;
		}
		for (int j=0; j<m; j+=2) {
			a[depth+last][depth+j]=a[depth+last][depth+j+1]=a[depth+last+1][depth+j]=a[depth+last+1][depth+j+1]=col++;
		}

		for (auto p:a) {
			for (auto v:p) cout<<v<<' ' ;cout<<'\n';
		}
		return;
	}
	f(n-2,m-2,k,depth+1);
}

void solve() {
	int n,m,k; cin>>n>>m>>k;
	int s=n*m;
	if (k>(s/4)) prn;
	if (n&1 || m&1) prn;
	vector<vector<int>> a(n,vector<int>(m,-1));

	if (n==2) {
		if (k!=m/2) prn;
		pry;
		forn(k,2) {
			for (int i=0; i<m; i+=2) {
				cout<<(i/2)+1<<' '<<(i/2)+1<<' ';
			}
			cout<<'\n';
		}
		return;
	}
	if (n==4) {
		if (k<(m/2) || k>m) prn;
		if (k==m-1) prn;
		pry;
		int y=m-k;
		assert(y!=1);
		if (y) {
			a[1][0]=a[2][0]=1;
			a[1][2*y-1]=a[2][2*y-1]=1;
		}
		int cnt=(y>0)+1;
		for (int i=0; i<2*y; ++i) {
			a[0][i]=a[3][i]=1;
		}
		for (int j=1; j<2*y-1; j+=2) {
			a[1][j]=a[1][j+1]=a[2][j]=a[2][j+1]=cnt++;
		}
		for (int i=2*y; i<m; i+=2) {
			a[0][i]=a[0][i+1]=a[1][i]=a[1][i+1]=cnt++;
			a[2][i]=a[2][i+1]=a[3][i]=a[3][i+1]=cnt++;
		}
		for (auto x:a) {
			for (auto y:x) cout<<y<<' '; 
			cout<<'\n';
		}
		return;
	}

	if (m==4) {
		swap(m,n);
		a.assign(n,vector<int>(m,-1));
		if (k<(m/2) || k>m) prn;
		if (k==m-1) prn;
		pry;
		int y=m-k;
		assert(y!=1);
		if (y) {
			a[1][0]=a[2][0]=1;
			a[1][2*y-1]=a[2][2*y-1]=1;
		}
		int cnt=(y>0)+1;
		for (int i=0; i<2*y; ++i) {
			a[0][i]=a[3][i]=1;
		}
		for (int j=1; j<2*y-1; j+=2) {
			a[1][j]=a[1][j+1]=a[2][j]=a[2][j+1]=cnt++;
		}
		for (int i=2*y; i<m; i+=2) {
			a[0][i]=a[0][i+1]=a[1][i]=a[1][i+1]=cnt++;
			a[2][i]=a[2][i+1]=a[3][i]=a[3][i+1]=cnt++;
		}
		swap(n,m);
		for (int i=0; i<n; ++i) {
			for (int j=0; j<m; ++j) {
				cout<<a[j][i]<<' ';
			}
			cout<<'\n';
		}
		return;
	}

	if (m==2) {
		swap(n,m);
		if (k!=m/2) prn;
		pry;
		for (int i=0; i<m; i+=2) {
			forn(k,2) cout<<(i/2)+1<<' '<<(i/2)+1<<'\n';
		}
		return;
	}

	if (n==m) {
		f(n,m,k,0);
	}

}

int32_t main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int t; cin>>t;
	while (t--) solve();
	return 0;
}

Compilation message

Main.cpp: In function 'void f(int, int, int, int)':
Main.cpp:45:4: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   45 |    for (auto v:p) cout<<v<<' ' ;cout<<'\n';
      |    ^~~
Main.cpp:45:33: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   45 |    for (auto v:p) cout<<v<<' ' ;cout<<'\n';
      |                                 ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 852 KB Correct! Azusa and Laika like the garden :)
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 852 KB Correct! Azusa and Laika like the garden :)
2 Correct 11 ms 588 KB Correct! Azusa and Laika like the garden :)
3 Correct 12 ms 596 KB Correct! Azusa and Laika like the garden :)
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 852 KB Correct! Azusa and Laika like the garden :)
2 Correct 11 ms 588 KB Correct! Azusa and Laika like the garden :)
3 Correct 12 ms 596 KB Correct! Azusa and Laika like the garden :)
4 Runtime error 1 ms 468 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 852 KB Correct! Azusa and Laika like the garden :)
2 Correct 11 ms 588 KB Correct! Azusa and Laika like the garden :)
3 Correct 12 ms 596 KB Correct! Azusa and Laika like the garden :)
4 Runtime error 1 ms 468 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -