Submission #857003

# Submission time Handle Problem Language Result Execution time Memory
857003 2023-10-05T07:48:08 Z alexdd Gardening (RMI21_gardening) C++17
100 / 100
16 ms 7260 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
vector<int> mat[200005];
int color;
bool verif(int n, int m, int k)
{
    if(n%2==1 || m%2==1)
        return 0;
    if(k > n*m/4)
        return 0;
    if(k < max(n,m)/2)
        return 0;
    if(k == n*m/4 - 1)
        return 0;
    if(n==m && k == max(n,m)/2 + 1)
        return 0;
    return 1;
}
void solve(int coltx, int colty, int n, int m, int k)
{
    if(n==0 || m==0)
        return;
    //cout<<coltx<<" "<<colty<<"   "<<n<<" "<<m<<"  "<<k<<"\n";
    if(n==2 && m==2)
    {
        color++;
        mat[coltx][colty]=color;
        mat[coltx][colty+1]=color;
        mat[coltx+1][colty]=color;
        mat[coltx+1][colty+1]=color;
        return;
    }
    if(n>2 && m>2 && verif(n-2,m-2,k-1))
    {
        color++;
        for(int i=0;i<m;i++)
        {
            mat[coltx][colty+i]=color;
            mat[coltx+n-1][colty+i]=color;
        }
        for(int i=0;i<n;i++)
        {
            mat[coltx+i][colty]=color;
            mat[coltx+i][colty+m-1]=color;
        }
        solve(coltx+1,colty+1,n-2,m-2,k-1);
        return;
    }
    if(verif((n/4)*2,m,k/2) && verif(n-(n/4)*2,m,k-k/2))
    {
        solve(coltx, colty, (n/4)*2, m, k/2);
        solve(coltx+(n/4)*2, colty, n-(n/4)*2, m, k-k/2);
        return;
    }
    if(verif(n,(m/4)*2,k/2) && verif(n,m-(m/4)*2,k-k/2))
    {
        solve(coltx,colty,n,(m/4)*2,k/2);
        solve(coltx,colty+(m/4)*2,n,m-(m/4)*2,k-k/2);
        return;
    }
    for(int i=2;i<=n-2;i+=2)
    {
        for(int kst=1;kst<k;kst++)
        {
            if(verif(i,m,kst) && verif(n-i,m,k-kst))
            {
                solve(coltx,colty,i,m,kst);
                solve(coltx+i,colty,n-i,m,k-kst);
                return;
            }
        }
    }
    for(int i=2;i<=m-2;i+=2)
    {
        for(int kst=1;kst<k;kst++)
        {
            if(verif(n,i,kst) && verif(n,m-i,k-kst))
            {
                solve(coltx,colty,n,i,kst);
                solve(coltx,colty+i,n,m-i,k-kst);
                return;
            }
        }
    }
    assert(1==0);
    while(1)
        n=0;
    //cout<<-1<<" zzz\n";
    return;
}
int cv[10];
int processed[200005];
bool visited[10][200005];
void dfs(int x, int y, int c, int n, int m)
{
    if(x<1 || x>n || y<1 || y>m)
        return;
    int i=x,j=y;
    if(mat[i][j]!=c || visited[i][j])
        return;
    visited[i][j]=1;
    dfs(i,j-1,c,n,m);
    dfs(i,j+1,c,n,m);
    dfs(i-1,j,c,n,m);
    dfs(i+1,j,c,n,m);
}
void check(int n, int m, int k)
{
    if(color!=k)
    {
        cout<<"k is not good\n";
    }
    for(int i=1;i<=k;i++)
        processed[i]=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            visited[i][j]=0;
            int cnt=0;
            if(i>1)cv[cnt++]=mat[i-1][j];
            if(i<n)cv[cnt++]=mat[i+1][j];
            if(j>1)cv[cnt++]=mat[i][j-1];
            if(j<m)cv[cnt++]=mat[i][j+1];
            if((cnt>=3 && cv[0]==cv[1] && cv[1]==cv[2]) || (cnt>=4 && cv[1]==cv[2] && cv[2]==cv[3]))
            {
                cout<<"too many same color neighbours\n";
            }
            if((cnt<2 || cv[0]!=cv[1]) && (cnt<3 && cv[1]!=cv[2]) && (cnt<4 || cv[2]!=cv[3]))
            {
                cout<<"too few same color neighbours\n";
            }
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(!visited[i][j])
            {
                if(processed[mat[i][j]])
                {
                    cout<<"color isn't connected  zzzzzzzzzzzzz\n";
                }
                processed[mat[i][j]]=1;
                dfs(i,j,mat[i][j],n,m);
            }
        }
    }
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    int t,n,m,k;
    cin>>t;
    while(t--)
    {
        cin>>n>>m>>k;
        if(!verif(n,m,k))
        {
            cout<<"NO\n";
        }
        else
        {
            cout<<"YES\n";
            for(int i=1;i<=n;i++)
                mat[i].resize(m+2);
            color=0;
            solve(1,1,n,m,k);
            //check(n,m,k);
            for(int i=1;i<=n;i++)
            {
                for(int j=1;j<=m;j++)cout<<mat[i][j]<<" ";cout<<"\n";
                mat[i].clear();
            }
        }
    }
    return 0;
}
/**
1
22 22 12
*/

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:174:17: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  174 |                 for(int j=1;j<=m;j++)cout<<mat[i][j]<<" ";cout<<"\n";
      |                 ^~~
Main.cpp:174:59: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  174 |                 for(int j=1;j<=m;j++)cout<<mat[i][j]<<" ";cout<<"\n";
      |                                                           ^~~~
# Verdict Execution time Memory Grader output
1 Correct 15 ms 6732 KB Correct! Azusa and Laika like the garden :)
# Verdict Execution time Memory Grader output
1 Correct 15 ms 6732 KB Correct! Azusa and Laika like the garden :)
2 Correct 12 ms 7000 KB Correct! Azusa and Laika like the garden :)
3 Correct 8 ms 6748 KB Correct! Azusa and Laika like the garden :)
# Verdict Execution time Memory Grader output
1 Correct 15 ms 6732 KB Correct! Azusa and Laika like the garden :)
2 Correct 12 ms 7000 KB Correct! Azusa and Laika like the garden :)
3 Correct 8 ms 6748 KB Correct! Azusa and Laika like the garden :)
4 Correct 8 ms 6748 KB Correct! Azusa and Laika like the garden :)
5 Correct 12 ms 7260 KB Correct! Azusa and Laika like the garden :)
# Verdict Execution time Memory Grader output
1 Correct 7 ms 6748 KB Correct! Azusa and Laika like the garden :)
2 Correct 7 ms 6744 KB Correct! Azusa and Laika like the garden :)
3 Correct 7 ms 6748 KB Correct! Azusa and Laika like the garden :)
4 Correct 8 ms 6744 KB Correct! Azusa and Laika like the garden :)
5 Correct 10 ms 6744 KB Correct! Azusa and Laika like the garden :)
6 Correct 7 ms 6748 KB Correct! Azusa and Laika like the garden :)
7 Correct 8 ms 6748 KB Correct! Azusa and Laika like the garden :)
8 Correct 7 ms 6712 KB Correct! Azusa and Laika like the garden :)
9 Correct 7 ms 6744 KB Correct! Azusa and Laika like the garden :)
10 Correct 8 ms 6748 KB Correct! Azusa and Laika like the garden :)
11 Correct 8 ms 6748 KB Correct! Azusa and Laika like the garden :)
12 Correct 7 ms 6748 KB Correct! Azusa and Laika like the garden :)
13 Correct 7 ms 6748 KB Correct! Azusa and Laika like the garden :)
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6492 KB Correct! Azusa and Laika like the garden :)
2 Correct 3 ms 6492 KB Correct! Azusa and Laika like the garden :)
3 Correct 3 ms 6524 KB Correct! Azusa and Laika like the garden :)
4 Correct 5 ms 6568 KB Correct! Azusa and Laika like the garden :)
5 Correct 5 ms 6492 KB Correct! Azusa and Laika like the garden :)
6 Correct 4 ms 6492 KB Correct! Azusa and Laika like the garden :)
7 Correct 4 ms 6488 KB Correct! Azusa and Laika like the garden :)
8 Correct 5 ms 6492 KB Correct! Azusa and Laika like the garden :)
9 Correct 5 ms 6492 KB Correct! Azusa and Laika like the garden :)
10 Correct 4 ms 6492 KB Correct! Azusa and Laika like the garden :)
11 Correct 3 ms 6456 KB Correct! Azusa and Laika like the garden :)
12 Correct 4 ms 6488 KB Correct! Azusa and Laika like the garden :)
13 Correct 4 ms 6492 KB Correct! Azusa and Laika like the garden :)
14 Correct 6 ms 6448 KB Correct! Azusa and Laika like the garden :)
15 Correct 4 ms 6492 KB Correct! Azusa and Laika like the garden :)
16 Correct 4 ms 6536 KB Correct! Azusa and Laika like the garden :)
17 Correct 5 ms 6488 KB Correct! Azusa and Laika like the garden :)
# Verdict Execution time Memory Grader output
1 Correct 15 ms 6732 KB Correct! Azusa and Laika like the garden :)
2 Correct 12 ms 7000 KB Correct! Azusa and Laika like the garden :)
3 Correct 8 ms 6748 KB Correct! Azusa and Laika like the garden :)
4 Correct 8 ms 6748 KB Correct! Azusa and Laika like the garden :)
5 Correct 12 ms 7260 KB Correct! Azusa and Laika like the garden :)
6 Correct 7 ms 6748 KB Correct! Azusa and Laika like the garden :)
7 Correct 7 ms 6744 KB Correct! Azusa and Laika like the garden :)
8 Correct 7 ms 6748 KB Correct! Azusa and Laika like the garden :)
9 Correct 8 ms 6744 KB Correct! Azusa and Laika like the garden :)
10 Correct 10 ms 6744 KB Correct! Azusa and Laika like the garden :)
11 Correct 7 ms 6748 KB Correct! Azusa and Laika like the garden :)
12 Correct 8 ms 6748 KB Correct! Azusa and Laika like the garden :)
13 Correct 7 ms 6712 KB Correct! Azusa and Laika like the garden :)
14 Correct 7 ms 6744 KB Correct! Azusa and Laika like the garden :)
15 Correct 8 ms 6748 KB Correct! Azusa and Laika like the garden :)
16 Correct 8 ms 6748 KB Correct! Azusa and Laika like the garden :)
17 Correct 7 ms 6748 KB Correct! Azusa and Laika like the garden :)
18 Correct 7 ms 6748 KB Correct! Azusa and Laika like the garden :)
19 Correct 4 ms 6492 KB Correct! Azusa and Laika like the garden :)
20 Correct 3 ms 6492 KB Correct! Azusa and Laika like the garden :)
21 Correct 3 ms 6524 KB Correct! Azusa and Laika like the garden :)
22 Correct 5 ms 6568 KB Correct! Azusa and Laika like the garden :)
23 Correct 5 ms 6492 KB Correct! Azusa and Laika like the garden :)
24 Correct 4 ms 6492 KB Correct! Azusa and Laika like the garden :)
25 Correct 4 ms 6488 KB Correct! Azusa and Laika like the garden :)
26 Correct 5 ms 6492 KB Correct! Azusa and Laika like the garden :)
27 Correct 5 ms 6492 KB Correct! Azusa and Laika like the garden :)
28 Correct 4 ms 6492 KB Correct! Azusa and Laika like the garden :)
29 Correct 3 ms 6456 KB Correct! Azusa and Laika like the garden :)
30 Correct 4 ms 6488 KB Correct! Azusa and Laika like the garden :)
31 Correct 4 ms 6492 KB Correct! Azusa and Laika like the garden :)
32 Correct 6 ms 6448 KB Correct! Azusa and Laika like the garden :)
33 Correct 4 ms 6492 KB Correct! Azusa and Laika like the garden :)
34 Correct 4 ms 6536 KB Correct! Azusa and Laika like the garden :)
35 Correct 5 ms 6488 KB Correct! Azusa and Laika like the garden :)
36 Correct 10 ms 6748 KB Correct! Azusa and Laika like the garden :)
37 Correct 10 ms 6748 KB Correct! Azusa and Laika like the garden :)
38 Correct 10 ms 6748 KB Correct! Azusa and Laika like the garden :)
39 Correct 10 ms 6748 KB Correct! Azusa and Laika like the garden :)
40 Correct 10 ms 6744 KB Correct! Azusa and Laika like the garden :)
41 Correct 15 ms 6924 KB Correct! Azusa and Laika like the garden :)
42 Correct 12 ms 6748 KB Correct! Azusa and Laika like the garden :)
43 Correct 10 ms 6960 KB Correct! Azusa and Laika like the garden :)
44 Correct 16 ms 6748 KB Correct! Azusa and Laika like the garden :)
45 Correct 10 ms 7116 KB Correct! Azusa and Laika like the garden :)
46 Correct 10 ms 6748 KB Correct! Azusa and Laika like the garden :)
47 Correct 11 ms 6748 KB Correct! Azusa and Laika like the garden :)
48 Correct 14 ms 6756 KB Correct! Azusa and Laika like the garden :)
49 Correct 11 ms 6744 KB Correct! Azusa and Laika like the garden :)
50 Correct 11 ms 6744 KB Correct! Azusa and Laika like the garden :)
51 Correct 9 ms 6744 KB Correct! Azusa and Laika like the garden :)
52 Correct 10 ms 6748 KB Correct! Azusa and Laika like the garden :)
53 Correct 10 ms 6748 KB Correct! Azusa and Laika like the garden :)
54 Correct 11 ms 6832 KB Correct! Azusa and Laika like the garden :)
55 Correct 10 ms 6796 KB Correct! Azusa and Laika like the garden :)
56 Correct 14 ms 6748 KB Correct! Azusa and Laika like the garden :)
57 Correct 10 ms 6744 KB Correct! Azusa and Laika like the garden :)
58 Correct 10 ms 6748 KB Correct! Azusa and Laika like the garden :)
59 Correct 10 ms 7000 KB Correct! Azusa and Laika like the garden :)
60 Correct 11 ms 6748 KB Correct! Azusa and Laika like the garden :)