Submission #856850

# Submission time Handle Problem Language Result Execution time Memory
856850 2023-10-04T17:34:30 Z alexdd Gardening (RMI21_gardening) C++17
0 / 100
200 ms 4956 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 < m/2)
        return 0;
    return 1;
}
void solve(int coltx, int colty, int n, int m, int k)
{
    if(n==0 || m==0)
        return;
    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/2,m,k/2) && verif(n-n/2,m,k-k/2))
    {
        solve(coltx, colty, n/2, m, k/2);
        solve(coltx+n/2, colty, n-n/2, m, k-k/2);
        return;
    }
    if(verif(n,m/2,k/2) && verif(n,m-m/2,k-k/2))
    {
        solve(coltx,colty,n,m/2,k/2);
        solve(coltx,colty+m/2,n,m-m/2,k-k/2);
        return;
    }
    while(1)
        n=0;
    //cout<<-1<<" zzz\n";
    return;
}
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);
            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;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 1074 ms 4956 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1074 ms 4956 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1074 ms 4956 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1070 ms 4952 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1042 ms 4956 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1074 ms 4956 KB Time limit exceeded
2 Halted 0 ms 0 KB -