답안 #946276

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
946276 2024-03-14T13:17:12 Z thunopro Gardening (RMI21_gardening) C++14
11 / 100
15 ms 1068 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+j][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 15 ms 1068 KB Correct! Azusa and Laika like the garden :)
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 1068 KB Correct! Azusa and Laika like the garden :)
2 Correct 8 ms 980 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 15 ms 1068 KB Correct! Azusa and Laika like the garden :)
2 Correct 8 ms 980 KB Correct! Azusa and Laika like the garden :)
3 Correct 8 ms 604 KB Correct! Azusa and Laika like the garden :)
4 Failed 8 ms 604 KB Output contains values not between 1 and k
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Failed 11 ms 604 KB Output contains values not between 1 and k
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Failed 3 ms 348 KB Output contains values not between 1 and k
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 1068 KB Correct! Azusa and Laika like the garden :)
2 Correct 8 ms 980 KB Correct! Azusa and Laika like the garden :)
3 Correct 8 ms 604 KB Correct! Azusa and Laika like the garden :)
4 Failed 8 ms 604 KB Output contains values not between 1 and k
5 Halted 0 ms 0 KB -