답안 #946294

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
946294 2024-03-14T13:25:48 Z thunopro Gardening (RMI21_gardening) C++14
100 / 100
14 ms 976 KB
#include<bits/stdc++.h>
using namespace std ; 
#define maxn 200009 
#define ll long long 
#define fi first 
#define se second 
#define pb push_back 
#define left id<<1
#define right id<<1|1 
#define re exit(0); 
#define _lower(x) lower_bound(v.begin(),v.end(),x)-v.begin()
#define TIME 1.0*clock()/CLOCKS_PER_SEC

const int mod = 1e9+7; 
const int INF = 1e9; 

typedef vector<int> vi; 
typedef pair<int,int> pii;
typedef vector<pii> vii;  
typedef vector<ll> vl;

void add ( int &a , int b ) 
{
	a += b ; 
	if ( a > mod ) a -= mod ; 
	if ( a < 0 ) a += mod ; 
}

template <typename T> void chkmin ( T &a , T b ) { if ( a > b ) a = b ; }
template <typename T> void chkmax ( T &a , T b ) { if ( a < b ) a = b ; }

int _pow ( int a , int n ) 
{
	if ( n == 0 ) return 1 ;
	int res = _pow (a,n/2) ; 
	if ( n % 2 ) return 1ll*res*res%mod*a%mod ; 
	else return 1ll*res*res%mod ; 
}

void rf () 
{
	freopen ("bai1.inp","r",stdin) ;
}

vector<vector<int>> ans ; 
int c ; 

bool ok ( int rows , int cols , int grps ) 
{
	int mxg = rows * cols / 4 , mng = max ( rows/2 , cols/2 ) ; 
	return ! ( rows&1 || cols&1 || grps < mng || grps > mxg || grps == mxg - 1 || ( rows == cols && grps == mng+1 ) ) ; 
}

void solve ( int rows , int cols , int grps , int rind , int cind ) 
{
	if ( rows == 2 ) 
	{
		for ( int k = 0 ; k < cols ; k += 2 ) 
		{
			c ++ ; 
			for ( int i = 0 ; i < 2 ; i ++ ) 
			{
				for ( int j = 0 ; j < 2 ; j ++ ) 
				{
					ans [rind+i][cind+k+j] = c ; 
				}
			}
		}
	}
	else if ( cols == 2 ) 
	{
		for ( int k = 0 ; k < rows ; k += 2 ) 
		{
			c ++ ; 
			for ( int i = 0 ; i < 2 ; i ++ ) 
			{
				for ( int j = 0 ; j < 2 ; j ++ ) 
				{
					ans [rind+k+i][cind+j] = c ; 
				}
			}
		}
	}
	else if ( ok (rows-2,cols-2,grps-1)) 
	{
		c ++ ; 
		for ( int i = 0 ; i < rows ; i ++ ) ans [rind+i][cind] = ans [rind+i][cind+cols-1] = c ; 
		for ( int i = 0 ; i < cols ; i ++ ) ans [rind][cind+i] = ans [rind+rows-1][cind+i] = c ; 
		solve (rows-2,cols-2,grps-1,rind+1,cind+1) ; 
	}
	else if ( ok (rows,cols-2,grps-rows/2)) 
	{
		for ( int k = 0 ; k < rows ; k += 2 ) 
		{
			c ++ ; 
			for ( int i = 0 ; i < 2 ; i ++ ) 
			{
				for ( int j = 0 ; j < 2 ; j ++ ) 
				{
					ans [rind+k+i][cind+j] = c ; 
				}
			}
		}
		solve (rows,cols-2,grps-rows/2,rind,cind+2) ; 
	} 
	else
	{
		for ( int k = 0 ; k < cols ; k += 2 ) 
		{
			c ++ ; 
			for ( int i = 0 ; i < 2 ; i ++ ) 
			{
				for ( int j = 0 ; j < 2 ; j ++ ) 
				{
					ans [rind+i][cind+k+j] = c ; 
				}
			}
		}
		solve (rows-2,cols,grps-cols/2,rind+2,cind) ; 
	}
}
int main () 
{
	ios_base::sync_with_stdio(0); 
	cin.tie(0);cout.tie(0);
//	rf () ; 
	int test ; cin >> test ; 
	while ( test -- ) 
	{
		int rows , cols , grps ; cin >> rows >> cols >> grps ; 
		if ( !ok (rows,cols,grps) ) 
		{
			cout << "NO\n" ; 
			continue ; 
		}
		ans = vector<vector<int>> (rows,vector<int>(cols)) ; 
		c = 0 ; 
		solve (rows,cols,grps,0,0) ; 
		cout << "YES\n" ; 
		for ( int i = 0 ; i < rows ; i ++ )
		{
			for ( int j = 0 ; j < cols ; j ++ ) 
			{
				cout << ans [i][j] << " " ; 
			}
			cout << "\n" ; 
		}
	}
	
}

Compilation message

Main.cpp: In function 'void rf()':
Main.cpp:42:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |  freopen ("bai1.inp","r",stdin) ;
      |  ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 860 KB Correct! Azusa and Laika like the garden :)
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 860 KB Correct! Azusa and Laika like the garden :)
2 Correct 7 ms 604 KB Correct! Azusa and Laika like the garden :)
3 Correct 8 ms 604 KB Correct! Azusa and Laika like the garden :)
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 860 KB Correct! Azusa and Laika like the garden :)
2 Correct 7 ms 604 KB Correct! Azusa and Laika like the garden :)
3 Correct 8 ms 604 KB Correct! Azusa and Laika like the garden :)
4 Correct 11 ms 604 KB Correct! Azusa and Laika like the garden :)
5 Correct 8 ms 692 KB Correct! Azusa and Laika like the garden :)
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 768 KB Correct! Azusa and Laika like the garden :)
2 Correct 7 ms 604 KB Correct! Azusa and Laika like the garden :)
3 Correct 8 ms 860 KB Correct! Azusa and Laika like the garden :)
4 Correct 10 ms 612 KB Correct! Azusa and Laika like the garden :)
5 Correct 7 ms 604 KB Correct! Azusa and Laika like the garden :)
6 Correct 7 ms 604 KB Correct! Azusa and Laika like the garden :)
7 Correct 7 ms 604 KB Correct! Azusa and Laika like the garden :)
8 Correct 9 ms 604 KB Correct! Azusa and Laika like the garden :)
9 Correct 9 ms 624 KB Correct! Azusa and Laika like the garden :)
10 Correct 8 ms 700 KB Correct! Azusa and Laika like the garden :)
11 Correct 7 ms 604 KB Correct! Azusa and Laika like the garden :)
12 Correct 7 ms 604 KB Correct! Azusa and Laika like the garden :)
13 Correct 6 ms 644 KB Correct! Azusa and Laika like the garden :)
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 348 KB Correct! Azusa and Laika like the garden :)
2 Correct 2 ms 348 KB Correct! Azusa and Laika like the garden :)
3 Correct 2 ms 348 KB Correct! Azusa and Laika like the garden :)
4 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
5 Correct 4 ms 600 KB Correct! Azusa and Laika like the garden :)
6 Correct 2 ms 348 KB Correct! Azusa and Laika like the garden :)
7 Correct 3 ms 512 KB Correct! Azusa and Laika like the garden :)
8 Correct 3 ms 452 KB Correct! Azusa and Laika like the garden :)
9 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
10 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
11 Correct 2 ms 348 KB Correct! Azusa and Laika like the garden :)
12 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
13 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
14 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
15 Correct 3 ms 348 KB Correct! Azusa and Laika like the garden :)
16 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
17 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 860 KB Correct! Azusa and Laika like the garden :)
2 Correct 7 ms 604 KB Correct! Azusa and Laika like the garden :)
3 Correct 8 ms 604 KB Correct! Azusa and Laika like the garden :)
4 Correct 11 ms 604 KB Correct! Azusa and Laika like the garden :)
5 Correct 8 ms 692 KB Correct! Azusa and Laika like the garden :)
6 Correct 7 ms 768 KB Correct! Azusa and Laika like the garden :)
7 Correct 7 ms 604 KB Correct! Azusa and Laika like the garden :)
8 Correct 8 ms 860 KB Correct! Azusa and Laika like the garden :)
9 Correct 10 ms 612 KB Correct! Azusa and Laika like the garden :)
10 Correct 7 ms 604 KB Correct! Azusa and Laika like the garden :)
11 Correct 7 ms 604 KB Correct! Azusa and Laika like the garden :)
12 Correct 7 ms 604 KB Correct! Azusa and Laika like the garden :)
13 Correct 9 ms 604 KB Correct! Azusa and Laika like the garden :)
14 Correct 9 ms 624 KB Correct! Azusa and Laika like the garden :)
15 Correct 8 ms 700 KB Correct! Azusa and Laika like the garden :)
16 Correct 7 ms 604 KB Correct! Azusa and Laika like the garden :)
17 Correct 7 ms 604 KB Correct! Azusa and Laika like the garden :)
18 Correct 6 ms 644 KB Correct! Azusa and Laika like the garden :)
19 Correct 3 ms 348 KB Correct! Azusa and Laika like the garden :)
20 Correct 2 ms 348 KB Correct! Azusa and Laika like the garden :)
21 Correct 2 ms 348 KB Correct! Azusa and Laika like the garden :)
22 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
23 Correct 4 ms 600 KB Correct! Azusa and Laika like the garden :)
24 Correct 2 ms 348 KB Correct! Azusa and Laika like the garden :)
25 Correct 3 ms 512 KB Correct! Azusa and Laika like the garden :)
26 Correct 3 ms 452 KB Correct! Azusa and Laika like the garden :)
27 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
28 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
29 Correct 2 ms 348 KB Correct! Azusa and Laika like the garden :)
30 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
31 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
32 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
33 Correct 3 ms 348 KB Correct! Azusa and Laika like the garden :)
34 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
35 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
36 Correct 14 ms 860 KB Correct! Azusa and Laika like the garden :)
37 Correct 10 ms 912 KB Correct! Azusa and Laika like the garden :)
38 Correct 10 ms 860 KB Correct! Azusa and Laika like the garden :)
39 Correct 14 ms 860 KB Correct! Azusa and Laika like the garden :)
40 Correct 10 ms 860 KB Correct! Azusa and Laika like the garden :)
41 Correct 10 ms 860 KB Correct! Azusa and Laika like the garden :)
42 Correct 10 ms 860 KB Correct! Azusa and Laika like the garden :)
43 Correct 10 ms 860 KB Correct! Azusa and Laika like the garden :)
44 Correct 12 ms 860 KB Correct! Azusa and Laika like the garden :)
45 Correct 10 ms 832 KB Correct! Azusa and Laika like the garden :)
46 Correct 11 ms 860 KB Correct! Azusa and Laika like the garden :)
47 Correct 10 ms 860 KB Correct! Azusa and Laika like the garden :)
48 Correct 10 ms 860 KB Correct! Azusa and Laika like the garden :)
49 Correct 10 ms 860 KB Correct! Azusa and Laika like the garden :)
50 Correct 10 ms 860 KB Correct! Azusa and Laika like the garden :)
51 Correct 9 ms 860 KB Correct! Azusa and Laika like the garden :)
52 Correct 14 ms 860 KB Correct! Azusa and Laika like the garden :)
53 Correct 10 ms 860 KB Correct! Azusa and Laika like the garden :)
54 Correct 10 ms 976 KB Correct! Azusa and Laika like the garden :)
55 Correct 12 ms 860 KB Correct! Azusa and Laika like the garden :)
56 Correct 10 ms 860 KB Correct! Azusa and Laika like the garden :)
57 Correct 10 ms 876 KB Correct! Azusa and Laika like the garden :)
58 Correct 10 ms 860 KB Correct! Azusa and Laika like the garden :)
59 Correct 10 ms 860 KB Correct! Azusa and Laika like the garden :)
60 Correct 10 ms 860 KB Correct! Azusa and Laika like the garden :)