답안 #859715

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
859715 2023-10-10T14:14:25 Z alexia_726 Gardening (RMI21_gardening) C++14
11 / 100
15 ms 7000 KB
#include<bits/stdc++.h>

using namespace std;

#define int long long

vector<int> mat[200005];

int t,n,m,k;

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;

    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;
    }

    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;
            }
        }
    }

    return;
}
int cv[10];

int done[200005];

bool viz[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 || viz[i][j])
        return;

    viz[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)
{


    for(int i=1;i<=k;i++)
        done[i]=0;

    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            viz[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];

        }
    }

    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(!viz[i][j])
            {
                done[mat[i][j]]=1;
                dfs(i,j,mat[i][j],n,m);
            }
        }
    }
}
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);


    cin>>t;

    for(int i=1;i<=t;++i)
    {
        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";
            }
        }
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 7000 KB Correct! Azusa and Laika like the garden :)
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 7000 KB Correct! Azusa and Laika like the garden :)
2 Correct 8 ms 6716 KB Correct! Azusa and Laika like the garden :)
3 Correct 9 ms 6744 KB Correct! Azusa and Laika like the garden :)
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 7000 KB Correct! Azusa and Laika like the garden :)
2 Correct 8 ms 6716 KB Correct! Azusa and Laika like the garden :)
3 Correct 9 ms 6744 KB Correct! Azusa and Laika like the garden :)
4 Failed 9 ms 6748 KB Incorrect output
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Failed 8 ms 6744 KB Incorrect output
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Failed 6 ms 6860 KB Incorrect output
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 7000 KB Correct! Azusa and Laika like the garden :)
2 Correct 8 ms 6716 KB Correct! Azusa and Laika like the garden :)
3 Correct 9 ms 6744 KB Correct! Azusa and Laika like the garden :)
4 Failed 9 ms 6748 KB Incorrect output
5 Halted 0 ms 0 KB -