Submission #859547

# Submission time Handle Problem Language Result Execution time Memory
859547 2023-10-10T10:01:31 Z lucri Gardening (RMI21_gardening) C++17
11 / 100
25 ms 848 KB
#include <bits/stdc++.h>
using namespace std;
int test,n,m,k;
vector<vector<int>>a;
void completeaza(int i,int j,int ii,int jj,int k)
{
    int n=ii-i+1;
    int m=jj-j+1;
    if(k<n*m/4-n-m)
    {
        for(int l=i;l<=ii;++l)
            a[l][j]=a[l][jj]=k;
        for(int c=j;c<=jj;++c)
            a[i][c]=a[ii][c]=k;
        completeaza(i+1,j+1,ii-1,jj-1,k-1);
        return;
    }
    if(k<n*m/4)
    {
        int sum=8,iii,jjj;
        while((n*m-(k-1)*4-sum)/2>m-2)
            sum+=4;
        iii=i-1+sum/2;
        jjj=j-1+(n*m-(k-1)*4-sum)/2+2;
        if(iii>ii||jjj>jj)
            exit(1);
        for(int l=i;l<=iii;++l)
            a[l][j]=a[l][jjj]=k;
        for(int c=j;c<=jjj;++c)
            a[i][c]=a[iii][c]=k;
        --k;
    }
    for(int l=i;l<=ii;++l)
        for(int c=j;c<=jj;++c)
        {
            if(a[l][c]==0)
            {
                a[l][c]=a[l][c+1]=a[l+1][c]=a[l+1][c+1]=k;
                --k;
            }
        }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>test;
    while(test--)
    {
        cin>>n>>m>>k;
        a.clear();
        a.resize(n+5);
        for(int i=1;i<=n;++i)
            a[i].resize(m+5);
        if(n%2==1||m%2==1||k==n*m/4-1||n==m&&k==n/2-1||k>n*m/4||k<max(n/2,m/2))
        {
            cout<<"NO\n";
            continue;
        }
        completeaza(1,1,n,m,k);
        cout<<"YES\n";
        for(int i=1;i<=n;++i)
        {
            for(int j=1;j<=m;++j)
            {
                cout<<a[i][j]<<' ';
                a[i][j]=0;
            }
            cout<<'\n';
        }
    }
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:56:44: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   56 |         if(n%2==1||m%2==1||k==n*m/4-1||n==m&&k==n/2-1||k>n*m/4||k<max(n/2,m/2))
      |                                        ~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 25 ms 848 KB Correct! Azusa and Laika like the garden :)
# Verdict Execution time Memory Grader output
1 Correct 25 ms 848 KB Correct! Azusa and Laika like the garden :)
2 Correct 12 ms 604 KB Correct! Azusa and Laika like the garden :)
3 Correct 7 ms 604 KB Correct! Azusa and Laika like the garden :)
# Verdict Execution time Memory Grader output
1 Correct 25 ms 848 KB Correct! Azusa and Laika like the garden :)
2 Correct 12 ms 604 KB Correct! Azusa and Laika like the garden :)
3 Correct 7 ms 604 KB Correct! Azusa and Laika like the garden :)
4 Runtime error 0 ms 348 KB Execution failed because the return code was nonzero
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 348 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 348 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 25 ms 848 KB Correct! Azusa and Laika like the garden :)
2 Correct 12 ms 604 KB Correct! Azusa and Laika like the garden :)
3 Correct 7 ms 604 KB Correct! Azusa and Laika like the garden :)
4 Runtime error 0 ms 348 KB Execution failed because the return code was nonzero
5 Halted 0 ms 0 KB -