Submission #946294

#TimeUsernameProblemLanguageResultExecution timeMemory
946294thunoproGardening (RMI21_gardening)C++14
100 / 100
14 ms976 KiB
#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 (stderr)

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) ;
      |  ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#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...