Submission #640513

#TimeUsernameProblemLanguageResultExecution timeMemory
640513Tenis0206Gardening (RMI21_gardening)C++11
100 / 100
19 ms2496 KiB
#include <bits/stdc++.h> using namespace std; int a[1005][1005]; int cul = 0; bool ok(int n,int m, int c) { if(n%2==1 || m%2==1) { return false; } if(c == (n / 2) * (m / 2) - 1) { return false; } if(c < max(n / 2, m / 2)) { return false; } if(c > (n / 2) * (m / 2)) { return false; } if(n==m && c==max(n / 2, m / 2) + 1) { return false; } return true; } void border(int x, int y, int n, int m) { if(n<=0 || m<=0) { return; } ++cul; for(int i=x;i<=x+n-1;i++) { a[i][y] = a[i][y + m - 1] = cul; } for(int j=y;j<=y+m-1;j++) { a[x][j] = a[x + n - 1][j] = cul; } } void Fill(int x, int y, int n, int m) { if(n<=0 || m<=0) { return; } for(int i=x;i<=x+n-1;i+=2) { for(int j=y;j<=y+m-1;j+=2) { ++cul; a[i][j] = a[i+1][j] = a[i][j+1] = a[i+1][j+1] = cul; } } } void afis(int n, int m) { for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { cout<<a[i][j]<<' '; } cout<<'\n'; } } void clear_mat(int n, int m) { for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { a[i][j] = 0; } } } void solve_test() { int n,m,c; cin>>n>>m>>c; if(!ok(n,m,c)) { cout<<"NO"<<'\n'; return; } cout<<"YES"<<'\n'; clear_mat(n,m); cul = 0; int auxn = n; int auxm = m; int nr = (n / 2) * (m / 2); vector<int> s; s.push_back(nr); while(n && m) { nr -= (n / 2) + (m / 2) - 2; n -= 2; m -= 2; s.push_back(nr); } int poz = 0; for(int i=0;i<s.size();i++) { if(c <= s[i]) { poz = i; } } n = auxn; m = auxm; int x = 1, y = 1; for(int i=1;i<=poz;i++) { border(x,y,n,m); ++x; ++y; n -= 2; m -= 2; } if(c == s[poz]) { Fill(x,y,n,m); afis(auxn,auxm); return; } if(c == s[poz] - 1) { --cul; n += 2; m += 2; --x; --y; if(n < m) { Fill(x,y,n,2); border(x,y+2,n,m-2); Fill(x+1,y+3,n-2,m-8); Fill(x+1,y+m-5,n-6,4); border(x+n-5,y+m-5,4,4); Fill(x+n-4,y+m-4,2,2); } else { Fill(x,y,2,m); border(x+2,y,n-2,m); Fill(x+3,y+1,n-8,m-2); Fill(x+n-5,y+1,4,m-6); border(x+n-5,y+m-5,4,4); Fill(x+n-4,y+m-4,2,2); } afis(auxn,auxm); return; } int nr_dif = s[poz] - c; int l_dif = 4 + 2 * (nr_dif - 2); int c_dif = 4; if(l_dif > n) { c_dif += (l_dif - n); l_dif = n; } Fill(x,y,n,m - c_dif); Fill(x,y + m - c_dif,n - l_dif,c_dif); border(x + n - l_dif, y + m - c_dif, l_dif, c_dif); Fill(x + n - l_dif + 1, y + m - c_dif + 1, l_dif - 2, c_dif - 2); afis(auxn,auxm); } int main() { ios::sync_with_stdio(false); cin.tie(0); int t; cin>>t; for(int test=1;test<=t;test++) { solve_test(); } return 0; }

Compilation message (stderr)

Main.cpp: In function 'void solve_test()':
Main.cpp:115:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  115 |     for(int i=0;i<s.size();i++)
      |                 ~^~~~~~~~~
#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...