Submission #737087

# Submission time Handle Problem Language Result Execution time Memory
737087 2023-05-06T15:21:08 Z ibm2006 Gardening (RMI21_gardening) C++14
100 / 100
30 ms 852 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll n,m,i,j,x,y,k,t,e,r,l;
vector<vector<ll>> a;
void f(ll x,ll y,ll z,ll w,ll k)
{
    //printf("%lld %lld %lld %lld %lld \n",x,y,z,w,k);
    ll i,j,n,m,q;
    n=z-x+1;
    m=w-y+1;
    if(n==2)
    {
        for(j=y;j<=w;j+=2)
        {
            t++;
            a[x][j]=t;
            a[z][j]=t;
            a[x][j+1]=t;
            a[z][j+1]=t;
        }
        return;
    }
    q=-1;
    for(i=0;i<=n-4;i+=2)
    {
        /*if(1+i/2*m/2+m/2-1<=k&&k<=1+i/2*m/2+(n/2-i-1)*(m/2-1)&&k!=m/2*i/2+(n/2-i-1)*(m/2-1))
        {
            q=i;
            break;
        }*/
        if(m==n-i)
        {
            if(1+i/2*m/2+m/2-1<=k&&k<=1+i/2*m/2+(n/2-i  /2-1)*(m/2-1)&&k!=m/2*i/2+(n/2-i/2-1)*(m/2-1)&&/*(1+i/2*m/2+m/2>k||1+i/2*m/2+m<=k)*/k!=1+i/2*m/2+m/2)
        {
            q=i;
            break;
        }
        }
        else
        {
            if(1+i/2*m/2+m/2-1<=k&&k<=1+i/2*m/2+(n/2-i/2-1)*(m/2-1)&&k!=m/2*i/2+(n/2-i/2-1)*(m/2-1))
        {
            q=i;
            break;
        }
        }
    }
    //printf("%lld\n",q);
    for(i=y;i<=w;i+=2)
    {
        for(j=0;j<q;j+=2)
        {
            t++;
            a[x+j][i]=t;
            a[x+j+1][i+1]=t;
            a[x+j][i+1]=t;
            a[x+j+1][i]=t;
        }
    }
    if(q!=-1)
    {t++;
    for(i=y;i<=w;i++)
    {

        a[x+q][i]=t;
        a[z][i]=t;

    }
    for(i=x+q;i<=z;i++)
    {
        a[i][y]=t;
        a[i][w]=t;
    }}
    if(q!=-1)
    {
        f(x+q+1,y+1,z-1,w-1,k-1-m/2*q/2);
        return;
    }
    for(i=0;i<=m-4;i+=2)
    {
        if(n==m-i)
        {
            if(1+i/2*n/2+n/2-1<=k&&k<=1+i/2*n/2+(m/2-i/2-1)*(n/2-1)&&k!=n/2*i/2+(m/2-i/2-1)*(n/2-1)&&/*(1+i/2*n/2+n/2>k||1+i/2*n/2+n<=k)*/1+i/2*n/2+n/2!=k)
        {
            q=i;
            break;
        }
        }
        else
        {
            if(1+i/2*n/2+n/2-1<=k&&k<=1+i/2*n/2+(m/2-i/2-1)*(n/2-1)&&k!=n/2*i/2+(m/2-i/2-1)*(n/2-1))
        {
            q=i;
            break;
        }
        }
    }
    if(q!=-1)
    {for(i=x;i<=z;i+=2)
        for(j=0;j<q;j+=2)
    {
        t++;
        a[i][j+y]=t;
        a[i+1][j+y+1]=t;
        a[i][j+y+1]=t;
        a[i+1][j+y]=t;
    }
    t++;
    for(i=x;i<=z;i++)
    {
        a[i][w]=t;
        a[i][y+q]=t;
    }
    for(i=y+q;i<=w;i++)
    {
        a[z][i]=t;
        a[x][i]=t;
    }
    //printf("%lld\n",q);
    f(x+1,y+q+1,z-1,w-1,k-1-n/2*q/2);
    return;
    }
    q=n-4;
    for(i=y;i<=w;i+=2)
    {
        for(j=0;j<q;j+=2)
        {
            t++;
            a[x+j][i]=t;
            a[x+j+1][i+1]=t;
            a[x+j][i+1]=t;
            a[x+j+1][i]=t;
        }
    }
    k-=q/2*m/2;
    k-=m/2;
    q=m-k*2;
    if(q!=0)
    t++;
    for(i=z-3;i<=z;i++)
        for(j=0;j<q;j++)
    {
        a[i][j+y]=t;
    }
    for(i=z-3;i<=z;i+=2)
        for(j=y+q;j<=w;j+=2)
    {
        t++;
        a[i][j]=t;
        a[i][j+1]=t;
        a[i+1][j]=t;
        a[i+1][j+1]=t;
    }
    for(j=0;j<q-2;j+=2)
    {
        t++;
        a[z-2][y+1+j]=t;
        a[z-1][y+1+j]=t;
        a[z-2][y+2+j]=t;
        a[z-1][y+2+j]=t;
    }
    return;
}
int main()
{
    //m=6;
    scanf("%lld",&e);
    //e=100;
    for(l=0;l<e;l++)
    {
        r=0;
        t=0;

        scanf("%lld %lld %lld",&n,&m,&k);
        //n=6;    k=l;
        a.clear();
        a.resize(n+1);
        for(i=1;i<=n;i++)
            a[i].resize(m+1);
        if(n%2==1||m%2==1)
        {
            printf("NO\n");
            continue;
        }
        if(k==n/2*m/2)
        {
            for(i=1;i<=n;i+=2)
            {
                for(j=1;j<=m;j+=2)
                {
                    t++;
                    a[i][j]=t;
                    a[i][j+1]=t;
                    a[i+1][j]=t;
                    a[i+1][j+1]=t;
                }
            }
            printf("YES\n");
            for(i=1;i<=n;i++)
            {
                for(j=1;j<=m;j++)
                    printf("%lld ",a[i][j]);
                printf("\n");
            }
            continue;
        }
        if(n==m)
        {
            /*if(k!=n/2)
            {
                if(k<n||k>=(n*m/4-1))
                {
                    printf("NO\n");
                    continue;
                }
            }*/
            if(k<n/2||k>=(n*m/4-1)||k==n/2+1)
            {
                printf("NO\n");
                continue;
            }
            f(1,1,n,m,k);
        }
        else
        {
            if(n>m)
            {
                n^=m^=n^=m;
                r=1;
            }
            a.clear();
        a.resize(n+1);
        for(i=1;i<=n;i++)
            a[i].resize(m+1);
            if(k<max(n/2,m/2)||k>=(n*m/4-1))
            {
                printf("NO\n");
                continue;
            }
            f(1,1,n,m,k);
        }
        printf("YES\n");
        if(r==0)
        {for(i=1;i<=n;i++)
        {for(j=1;j<=m;j++)
        printf("%lld ",a[i][j]);
        printf("\n");
        }
        }
        else
        {
            for(i=1;i<=m;i++)
                {for(j=1;j<=n;j++)
            {
                printf("%lld ",a[j][i]);
            }
            printf("\n");
                }
        }
    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:234:9: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  234 |         for(i=1;i<=n;i++)
      |         ^~~
Main.cpp:236:13: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  236 |             if(k<max(n/2,m/2)||k>=(n*m/4-1))
      |             ^~
Main.cpp:168:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  168 |     scanf("%lld",&e);
      |     ~~~~~^~~~~~~~~~~
Main.cpp:175:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  175 |         scanf("%lld %lld %lld",&n,&m,&k);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 30 ms 716 KB Correct! Azusa and Laika like the garden :)
# Verdict Execution time Memory Grader output
1 Correct 30 ms 716 KB Correct! Azusa and Laika like the garden :)
2 Correct 11 ms 556 KB Correct! Azusa and Laika like the garden :)
3 Correct 14 ms 540 KB Correct! Azusa and Laika like the garden :)
# Verdict Execution time Memory Grader output
1 Correct 30 ms 716 KB Correct! Azusa and Laika like the garden :)
2 Correct 11 ms 556 KB Correct! Azusa and Laika like the garden :)
3 Correct 14 ms 540 KB Correct! Azusa and Laika like the garden :)
4 Correct 13 ms 596 KB Correct! Azusa and Laika like the garden :)
5 Correct 16 ms 572 KB Correct! Azusa and Laika like the garden :)
# Verdict Execution time Memory Grader output
1 Correct 11 ms 596 KB Correct! Azusa and Laika like the garden :)
2 Correct 10 ms 592 KB Correct! Azusa and Laika like the garden :)
3 Correct 10 ms 596 KB Correct! Azusa and Laika like the garden :)
4 Correct 16 ms 596 KB Correct! Azusa and Laika like the garden :)
5 Correct 11 ms 596 KB Correct! Azusa and Laika like the garden :)
6 Correct 11 ms 596 KB Correct! Azusa and Laika like the garden :)
7 Correct 12 ms 596 KB Correct! Azusa and Laika like the garden :)
8 Correct 10 ms 596 KB Correct! Azusa and Laika like the garden :)
9 Correct 10 ms 596 KB Correct! Azusa and Laika like the garden :)
10 Correct 10 ms 644 KB Correct! Azusa and Laika like the garden :)
11 Correct 12 ms 636 KB Correct! Azusa and Laika like the garden :)
12 Correct 12 ms 576 KB Correct! Azusa and Laika like the garden :)
13 Correct 9 ms 596 KB Correct! Azusa and Laika like the garden :)
# Verdict Execution time Memory Grader output
1 Correct 4 ms 468 KB Correct! Azusa and Laika like the garden :)
2 Correct 5 ms 340 KB Correct! Azusa and Laika like the garden :)
3 Correct 5 ms 424 KB Correct! Azusa and Laika like the garden :)
4 Correct 6 ms 468 KB Correct! Azusa and Laika like the garden :)
5 Correct 6 ms 468 KB Correct! Azusa and Laika like the garden :)
6 Correct 5 ms 468 KB Correct! Azusa and Laika like the garden :)
7 Correct 5 ms 388 KB Correct! Azusa and Laika like the garden :)
8 Correct 5 ms 468 KB Correct! Azusa and Laika like the garden :)
9 Correct 5 ms 468 KB Correct! Azusa and Laika like the garden :)
10 Correct 6 ms 468 KB Correct! Azusa and Laika like the garden :)
11 Correct 3 ms 340 KB Correct! Azusa and Laika like the garden :)
12 Correct 5 ms 468 KB Correct! Azusa and Laika like the garden :)
13 Correct 5 ms 420 KB Correct! Azusa and Laika like the garden :)
14 Correct 5 ms 448 KB Correct! Azusa and Laika like the garden :)
15 Correct 5 ms 468 KB Correct! Azusa and Laika like the garden :)
16 Correct 6 ms 468 KB Correct! Azusa and Laika like the garden :)
17 Correct 6 ms 496 KB Correct! Azusa and Laika like the garden :)
# Verdict Execution time Memory Grader output
1 Correct 30 ms 716 KB Correct! Azusa and Laika like the garden :)
2 Correct 11 ms 556 KB Correct! Azusa and Laika like the garden :)
3 Correct 14 ms 540 KB Correct! Azusa and Laika like the garden :)
4 Correct 13 ms 596 KB Correct! Azusa and Laika like the garden :)
5 Correct 16 ms 572 KB Correct! Azusa and Laika like the garden :)
6 Correct 11 ms 596 KB Correct! Azusa and Laika like the garden :)
7 Correct 10 ms 592 KB Correct! Azusa and Laika like the garden :)
8 Correct 10 ms 596 KB Correct! Azusa and Laika like the garden :)
9 Correct 16 ms 596 KB Correct! Azusa and Laika like the garden :)
10 Correct 11 ms 596 KB Correct! Azusa and Laika like the garden :)
11 Correct 11 ms 596 KB Correct! Azusa and Laika like the garden :)
12 Correct 12 ms 596 KB Correct! Azusa and Laika like the garden :)
13 Correct 10 ms 596 KB Correct! Azusa and Laika like the garden :)
14 Correct 10 ms 596 KB Correct! Azusa and Laika like the garden :)
15 Correct 10 ms 644 KB Correct! Azusa and Laika like the garden :)
16 Correct 12 ms 636 KB Correct! Azusa and Laika like the garden :)
17 Correct 12 ms 576 KB Correct! Azusa and Laika like the garden :)
18 Correct 9 ms 596 KB Correct! Azusa and Laika like the garden :)
19 Correct 4 ms 468 KB Correct! Azusa and Laika like the garden :)
20 Correct 5 ms 340 KB Correct! Azusa and Laika like the garden :)
21 Correct 5 ms 424 KB Correct! Azusa and Laika like the garden :)
22 Correct 6 ms 468 KB Correct! Azusa and Laika like the garden :)
23 Correct 6 ms 468 KB Correct! Azusa and Laika like the garden :)
24 Correct 5 ms 468 KB Correct! Azusa and Laika like the garden :)
25 Correct 5 ms 388 KB Correct! Azusa and Laika like the garden :)
26 Correct 5 ms 468 KB Correct! Azusa and Laika like the garden :)
27 Correct 5 ms 468 KB Correct! Azusa and Laika like the garden :)
28 Correct 6 ms 468 KB Correct! Azusa and Laika like the garden :)
29 Correct 3 ms 340 KB Correct! Azusa and Laika like the garden :)
30 Correct 5 ms 468 KB Correct! Azusa and Laika like the garden :)
31 Correct 5 ms 420 KB Correct! Azusa and Laika like the garden :)
32 Correct 5 ms 448 KB Correct! Azusa and Laika like the garden :)
33 Correct 5 ms 468 KB Correct! Azusa and Laika like the garden :)
34 Correct 6 ms 468 KB Correct! Azusa and Laika like the garden :)
35 Correct 6 ms 496 KB Correct! Azusa and Laika like the garden :)
36 Correct 15 ms 724 KB Correct! Azusa and Laika like the garden :)
37 Correct 15 ms 724 KB Correct! Azusa and Laika like the garden :)
38 Correct 19 ms 784 KB Correct! Azusa and Laika like the garden :)
39 Correct 16 ms 784 KB Correct! Azusa and Laika like the garden :)
40 Correct 17 ms 724 KB Correct! Azusa and Laika like the garden :)
41 Correct 15 ms 788 KB Correct! Azusa and Laika like the garden :)
42 Correct 21 ms 724 KB Correct! Azusa and Laika like the garden :)
43 Correct 20 ms 800 KB Correct! Azusa and Laika like the garden :)
44 Correct 16 ms 684 KB Correct! Azusa and Laika like the garden :)
45 Correct 15 ms 728 KB Correct! Azusa and Laika like the garden :)
46 Correct 15 ms 700 KB Correct! Azusa and Laika like the garden :)
47 Correct 18 ms 724 KB Correct! Azusa and Laika like the garden :)
48 Correct 16 ms 724 KB Correct! Azusa and Laika like the garden :)
49 Correct 15 ms 724 KB Correct! Azusa and Laika like the garden :)
50 Correct 16 ms 852 KB Correct! Azusa and Laika like the garden :)
51 Correct 14 ms 724 KB Correct! Azusa and Laika like the garden :)
52 Correct 15 ms 812 KB Correct! Azusa and Laika like the garden :)
53 Correct 16 ms 852 KB Correct! Azusa and Laika like the garden :)
54 Correct 15 ms 724 KB Correct! Azusa and Laika like the garden :)
55 Correct 14 ms 700 KB Correct! Azusa and Laika like the garden :)
56 Correct 19 ms 748 KB Correct! Azusa and Laika like the garden :)
57 Correct 15 ms 724 KB Correct! Azusa and Laika like the garden :)
58 Correct 15 ms 724 KB Correct! Azusa and Laika like the garden :)
59 Correct 17 ms 808 KB Correct! Azusa and Laika like the garden :)
60 Correct 21 ms 724 KB Correct! Azusa and Laika like the garden :)