Submission #1112800

#TimeUsernameProblemLanguageResultExecution timeMemory
1112800snpmrnhlolGardening (RMI21_gardening)C++17
100 / 100
62 ms1176 KiB
#include<bits/stdc++.h> using namespace std; vector <vector<int>> ans; bool check(int n, int m, int k){ ///checks if (n, m, k) is true ///works for like 99% of cases ///(i hope) if(n > m)swap(n, m); if(n%2 == 1 || m%2 == 1)return 0; if(n == m && k == n/2 + 1)return 0; ///i sense a pattern and so i bullshit int l = max(n, m)/2, r = n*m/4; return l <= k && k <= r && k != r - 1; } int colcnt; void constructsol(int n, int m, int k, int dx, int dy){ if(n == 0 || m == 0)return; if(!check(n, m, k))return; ///idk what to do lol ///im trying like 3 cases if(check(n, m - 2, k - n/2)){ constructsol(n, m - 2, k - n/2, dx, dy); for(int i = 0;i < n;i+=2){ ans[i + dx][m - 2 + dy] = colcnt; ans[i + dx][m - 1 + dy] = colcnt; ans[i + 1 + dx][m - 2 + dy] = colcnt; ans[i + 1 + dx][m - 1 + dy] = colcnt; colcnt++; } }else if(check(n - 2, m, k - m/2)){ constructsol(n - 2, m, k - m/2, dx, dy); for(int j = 0;j < m;j+=2){ ans[n - 2 + dx][j + dy] = colcnt; ans[n - 2 + dx][j + 1 + dy] = colcnt; ans[n - 1 + dx][j + dy] = colcnt; ans[n - 1 + dx][j + 1 + dy] = colcnt; colcnt++; } }else if(check(n - 2, m - 2, k - 1)){ constructsol(n - 2, m - 2, k - 1, dx + 1, dy + 1); for(int i = 0;i < n;i++){ ans[i + dx][0 + dy] = colcnt; ans[i + dx][m - 1 + dy] = colcnt; } for(int i = 0;i < m;i++){ ans[0 + dx][i + dy] = colcnt; ans[n - 1 + dx][i + dy] = colcnt; } colcnt++; } } void solve(){ int n, m, k; cin>>n>>m>>k; ///I REALLY HATE MY LIFE ans.assign(n, vector<int>(m, 0)); colcnt = 1; if(check(n, m, k)){ cout<<"YES\n"; constructsol(n, m, k, 0, 0); for(int i = 0;i < n;i++){ for(int j = 0;j < m;j++){ cout<<ans[i][j]<<' '; } cout<<'\n'; } }else{ cout<<"NO\n"; } } int main(){ //ios_base::sync_with_stdio(0); //cin.tie(0); int t; cin>>t; while(t--)solve(); return 0; }
#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...