Submission #859611

# Submission time Handle Problem Language Result Execution time Memory
859611 2023-10-10T11:17:58 Z lucri Gardening (RMI21_gardening) C++17
100 / 100
15 ms 1116 KB
#include <bits/stdc++.h>
using namespace std;
int test,n,m,k;
vector<vector<int>>a;
bool 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/2-m/2)
    {
        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;
        return completeaza(i+1,j+1,ii-1,jj-1,k-1);
    }
    else if(k==n*m/4-n/2-m/2+1)
    {
        int iii=ii,jjj=jj;
        if(iii-i>jjj-j)
            iii-=2;
        else
            jjj-=2;
        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+1;l<=i+4;++l)
            a[l][j+1]=a[l][j+4]=k;
        for(int c=j+1;c<=j+4;++c)
            a[i+1][c]=a[i+4][c]=k;
        --k;
    }
    else if(k<n*m/4)
    {
        int iii=ii,jjj=jj;
        while((n*m-(k-1)*4)!=(iii-i)*2+(jjj-j)*2)
        {
            if(iii-i>jjj-j)
                iii-=2;
            else
                jjj-=2;
        }
        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)
            {
                if(a[l][c+1]||a[l+1][c]||a[l+1][c+1])
                    return false;
                a[l][c]=a[l][c+1]=a[l+1][c]=a[l+1][c+1]=k;
                --k;
            }
        }
    return true;
}
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:77:44: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   77 |         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 15 ms 860 KB Correct! Azusa and Laika like the garden :)
# Verdict Execution time Memory Grader output
1 Correct 15 ms 860 KB Correct! Azusa and Laika like the garden :)
2 Correct 7 ms 600 KB Correct! Azusa and Laika like the garden :)
3 Correct 8 ms 604 KB Correct! Azusa and Laika like the garden :)
# Verdict Execution time Memory Grader output
1 Correct 15 ms 860 KB Correct! Azusa and Laika like the garden :)
2 Correct 7 ms 600 KB Correct! Azusa and Laika like the garden :)
3 Correct 8 ms 604 KB Correct! Azusa and Laika like the garden :)
4 Correct 7 ms 604 KB Correct! Azusa and Laika like the garden :)
5 Correct 7 ms 716 KB Correct! Azusa and Laika like the garden :)
# Verdict Execution time Memory Grader output
1 Correct 7 ms 856 KB Correct! Azusa and Laika like the garden :)
2 Correct 7 ms 604 KB Correct! Azusa and Laika like the garden :)
3 Correct 6 ms 604 KB Correct! Azusa and Laika like the garden :)
4 Correct 8 ms 860 KB Correct! Azusa and Laika like the garden :)
5 Correct 6 ms 856 KB Correct! Azusa and Laika like the garden :)
6 Correct 6 ms 600 KB Correct! Azusa and Laika like the garden :)
7 Correct 7 ms 860 KB Correct! Azusa and Laika like the garden :)
8 Correct 6 ms 604 KB Correct! Azusa and Laika like the garden :)
9 Correct 6 ms 604 KB Correct! Azusa and Laika like the garden :)
10 Correct 6 ms 856 KB Correct! Azusa and Laika like the garden :)
11 Correct 6 ms 604 KB Correct! Azusa and Laika like the garden :)
12 Correct 6 ms 604 KB Correct! Azusa and Laika like the garden :)
13 Correct 6 ms 604 KB Correct! Azusa and Laika like the garden :)
# Verdict Execution time Memory Grader output
1 Correct 3 ms 600 KB Correct! Azusa and Laika like the garden :)
2 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
3 Correct 2 ms 600 KB Correct! Azusa and Laika like the garden :)
4 Correct 3 ms 456 KB Correct! Azusa and Laika like the garden :)
5 Correct 4 ms 600 KB Correct! Azusa and Laika like the garden :)
6 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
7 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
8 Correct 3 ms 496 KB Correct! Azusa and Laika like the garden :)
9 Correct 3 ms 600 KB Correct! Azusa and Laika like the garden :)
10 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
11 Correct 2 ms 348 KB Correct! Azusa and Laika like the garden :)
12 Correct 4 ms 456 KB Correct! Azusa and Laika like the garden :)
13 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
14 Correct 3 ms 600 KB Correct! Azusa and Laika like the garden :)
15 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
16 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
17 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
# Verdict Execution time Memory Grader output
1 Correct 15 ms 860 KB Correct! Azusa and Laika like the garden :)
2 Correct 7 ms 600 KB Correct! Azusa and Laika like the garden :)
3 Correct 8 ms 604 KB Correct! Azusa and Laika like the garden :)
4 Correct 7 ms 604 KB Correct! Azusa and Laika like the garden :)
5 Correct 7 ms 716 KB Correct! Azusa and Laika like the garden :)
6 Correct 7 ms 856 KB Correct! Azusa and Laika like the garden :)
7 Correct 7 ms 604 KB Correct! Azusa and Laika like the garden :)
8 Correct 6 ms 604 KB Correct! Azusa and Laika like the garden :)
9 Correct 8 ms 860 KB Correct! Azusa and Laika like the garden :)
10 Correct 6 ms 856 KB Correct! Azusa and Laika like the garden :)
11 Correct 6 ms 600 KB Correct! Azusa and Laika like the garden :)
12 Correct 7 ms 860 KB Correct! Azusa and Laika like the garden :)
13 Correct 6 ms 604 KB Correct! Azusa and Laika like the garden :)
14 Correct 6 ms 604 KB Correct! Azusa and Laika like the garden :)
15 Correct 6 ms 856 KB Correct! Azusa and Laika like the garden :)
16 Correct 6 ms 604 KB Correct! Azusa and Laika like the garden :)
17 Correct 6 ms 604 KB Correct! Azusa and Laika like the garden :)
18 Correct 6 ms 604 KB Correct! Azusa and Laika like the garden :)
19 Correct 3 ms 600 KB Correct! Azusa and Laika like the garden :)
20 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
21 Correct 2 ms 600 KB Correct! Azusa and Laika like the garden :)
22 Correct 3 ms 456 KB Correct! Azusa and Laika like the garden :)
23 Correct 4 ms 600 KB Correct! Azusa and Laika like the garden :)
24 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
25 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
26 Correct 3 ms 496 KB Correct! Azusa and Laika like the garden :)
27 Correct 3 ms 600 KB Correct! Azusa and Laika like the garden :)
28 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
29 Correct 2 ms 348 KB Correct! Azusa and Laika like the garden :)
30 Correct 4 ms 456 KB Correct! Azusa and Laika like the garden :)
31 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
32 Correct 3 ms 600 KB Correct! Azusa and Laika like the garden :)
33 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
34 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
35 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
36 Correct 9 ms 860 KB Correct! Azusa and Laika like the garden :)
37 Correct 9 ms 856 KB Correct! Azusa and Laika like the garden :)
38 Correct 9 ms 860 KB Correct! Azusa and Laika like the garden :)
39 Correct 9 ms 860 KB Correct! Azusa and Laika like the garden :)
40 Correct 9 ms 860 KB Correct! Azusa and Laika like the garden :)
41 Correct 9 ms 860 KB Correct! Azusa and Laika like the garden :)
42 Correct 9 ms 860 KB Correct! Azusa and Laika like the garden :)
43 Correct 9 ms 860 KB Correct! Azusa and Laika like the garden :)
44 Correct 9 ms 1112 KB Correct! Azusa and Laika like the garden :)
45 Correct 9 ms 860 KB Correct! Azusa and Laika like the garden :)
46 Correct 9 ms 860 KB Correct! Azusa and Laika like the garden :)
47 Correct 10 ms 860 KB Correct! Azusa and Laika like the garden :)
48 Correct 9 ms 932 KB Correct! Azusa and Laika like the garden :)
49 Correct 9 ms 860 KB Correct! Azusa and Laika like the garden :)
50 Correct 9 ms 860 KB Correct! Azusa and Laika like the garden :)
51 Correct 9 ms 856 KB Correct! Azusa and Laika like the garden :)
52 Correct 9 ms 1024 KB Correct! Azusa and Laika like the garden :)
53 Correct 9 ms 856 KB Correct! Azusa and Laika like the garden :)
54 Correct 9 ms 860 KB Correct! Azusa and Laika like the garden :)
55 Correct 8 ms 856 KB Correct! Azusa and Laika like the garden :)
56 Correct 10 ms 860 KB Correct! Azusa and Laika like the garden :)
57 Correct 9 ms 860 KB Correct! Azusa and Laika like the garden :)
58 Correct 9 ms 860 KB Correct! Azusa and Laika like the garden :)
59 Correct 9 ms 860 KB Correct! Azusa and Laika like the garden :)
60 Correct 14 ms 1116 KB Correct! Azusa and Laika like the garden :)