Submission #640510

# Submission time Handle Problem Language Result Execution time Memory
640510 2022-09-14T19:29:48 Z Tenis0206 Gardening (RMI21_gardening) C++11
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

int a[1005][1005];

int cul = 0;

bool ok(int n,int m, int c)
{
    if(n%2==1 || m%2==1)
    {
        return false;
    }
    if(c == (n / 2) * (m / 2) - 1)
    {
        return false;
    }
    if(c < max(n / 2, m / 2))
    {
        return false;
    }
    if(c > (n / 2) * (m / 2))
    {
        return false;
    }
    if(n==m && c==max(n / 2, m / 2) + 1)
    {
        return false;
    }
    return true;
}

void border(int x, int y, int n, int m)
{
    if(n<=0 || m<=0)
    {
        return;
    }
    ++cul;
    for(int i=x;i<=x+n-1;i++)
    {
        a[i][y] = a[i][y + m - 1] = cul;
    }
    for(int j=y;j<=y+m-1;j++)
    {
        a[x][j] = a[x + n - 1][j] = cul;
    }
}

void Fill(int x, int y, int n, int m)
{
    if(n<=0 || m<=0)
    {
        return;
    }
    for(int i=x;i<=x+n-1;i+=2)
    {
        for(int j=y;j<=y+m-1;j+=2)
        {
            ++cul;
            a[i][j] = a[i+1][j] = a[i][j+1] = a[i+1][j+1] = cul;
        }
    }
}

void afis(int n, int m)
{
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            cout<<a[i][j]<<' ';
        }
        cout<<'\n';
    }
}

void clear_mat(int n, int m)
{
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            a[i][j] = 0;
        }
    }
}

void solve_test()
{
    int n,m,c;
    cin>>n>>m>>c;
    if(!ok(n,m,c))
    {
        cout<<"NO"<<'\n';
        return;
    }
    cout<<"YES"<<'\n';
    clear_mat(n,m);
    cul = 0;
    int auxn = n;
    int auxm = m;
    int nr = (n / 2) * (m / 2);
    vector<int> s;
    s.push_back(nr);
    while(n && m)
    {
        nr -= (n / 2) + (m / 2) - 2;
        n -= 2;
        m -= 2;
        s.push_back(nr);
    }
    int poz = 0;
    for(int i=0;i<s.size();i++)
    {
        if(c <= s[i])
        {
            poz = i;
        }
    }
    n = auxn;
    m = auxm;
    int x = 1, y = 1;
    for(int i=1;i<=poz;i++)
    {
        border(x,y,n,m);
        ++x;
        ++y;
        n -= 2;
        m -= 2;
    }
    if(c == s[poz])
    {
        Fill(x,y,n,m);
        afis(auxn,auxm);
        return;
    }
    if(c == s[poz] - 1)
    {
        --cul;
        n += 2;
        m += 2;
        --x;
        --y;
        if(n < m)
        {
            Fill(x,y,n,2);
            border(x,y+2,n,m-2);
            Fill(x+1,y+3,n-2,m-8);
            Fill(x+1,y+m-5,n-6,4);
            border(x+n-5,y+m-5,4,4);
            Fill(x+n-4,y+m-4,2,2);
        }
        else
        {
            Fill(x,y,2,m);
            border(x+2,y,n-2,m);
            Fill(x+3,y+1,n-8,m-2);
            Fill(x+n-5,y+1,4,m-6);
            border(x+n-5,y+m-5,4,4);
            Fill(x+n-4,y+m-4,2,2);
        }
        afis(auxn,auxm);
        return;
    }
    int nr_dif = s[poz] - c;
    int l_dif = 4 + 2 * (nr_dif - 2);
    int c_dif = 4;
    if(l_dif > n)
    {
        c_dif += (l_dif - n);
        l_dif = n;
    }
    Fill(x,y,n,m - c_dif);
    Fill(x,y + m - c_dif,n - l_dif,c_dif);
    border(x + n - l_dif, y + m - c_dif, l_dif, c_dif);
    Fill(x + n - l_dif + 1, y + m - c_dif + 1, l_dif - 2, c_dif - 2);
    afis(auxn,auxm);
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    for(int test=1;test<=t;test++)
    {
        solve_test();
    }
    return 0;
}
#include <bits/stdc++.h>

using namespace std;

int a[1005][1005];

int cul = 0;

bool ok(int n,int m, int c)
{
    if(n%2==1 || m%2==1)
    {
        return false;
    }
    if(c == (n / 2) * (m / 2) - 1)
    {
        return false;
    }
    if(c < max(n / 2, m / 2))
    {
        return false;
    }
    if(c > (n / 2) * (m / 2))
    {
        return false;
    }
    if(n==m && c==max(n / 2, m / 2) + 1)
    {
        return false;
    }
    return true;
}

void border(int x, int y, int n, int m)
{
    if(n<=0 || m<=0)
    {
        return;
    }
    ++cul;
    for(int i=x;i<=x+n-1;i++)
    {
        a[i][y] = a[i][y + m - 1] = cul;
    }
    for(int j=y;j<=y+m-1;j++)
    {
        a[x][j] = a[x + n - 1][j] = cul;
    }
}

void Fill(int x, int y, int n, int m)
{
    if(n<=0 || m<=0)
    {
        return;
    }
    for(int i=x;i<=x+n-1;i+=2)
    {
        for(int j=y;j<=y+m-1;j+=2)
        {
            ++cul;
            a[i][j] = a[i+1][j] = a[i][j+1] = a[i+1][j+1] = cul;
        }
    }
}

void afis(int n, int m)
{
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            cout<<a[i][j]<<' ';
        }
        cout<<'\n';
    }
}

void clear_mat(int n, int m)
{
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            a[i][j] = 0;
        }
    }
}

void solve_test()
{
    int n,m,c;
    cin>>n>>m>>c;
    if(!ok(n,m,c))
    {
        cout<<"NO"<<'\n';
        return;
    }
    cout<<"YES"<<'\n';
    clear_mat(n,m);
    cul = 0;
    int auxn = n;
    int auxm = m;
    int nr = (n / 2) * (m / 2);
    vector<int> s;
    s.push_back(nr);
    while(n && m)
    {
        nr -= (n / 2) + (m / 2) - 2;
        n -= 2;
        m -= 2;
        s.push_back(nr);
    }
    int poz = 0;
    for(int i=0;i<s.size();i++)
    {
        if(c <= s[i])
        {
            poz = i;
        }
    }
    n = auxn;
    m = auxm;
    int x = 1, y = 1;
    for(int i=1;i<=poz;i++)
    {
        border(x,y,n,m);
        ++x;
        ++y;
        n -= 2;
        m -= 2;
    }
    if(c == s[poz])
    {
        Fill(x,y,n,m);
        afis(auxn,auxm);
        return;
    }
    if(c == s[poz] - 1)
    {
        --cul;
        n += 2;
        m += 2;
        --x;
        --y;
        if(n < m)
        {
            Fill(x,y,n,2);
            border(x,y+2,n,m-2);
            Fill(x+1,y+3,n-2,m-8);
            Fill(x+1,y+m-5,n-6,4);
            border(x+n-5,y+m-5,4,4);
            Fill(x+n-4,y+m-4,2,2);
        }
        else
        {
            Fill(x,y,2,m);
            border(x+2,y,n-2,m);
            Fill(x+3,y+1,n-8,m-2);
            Fill(x+n-5,y+1,4,m-6);
            border(x+n-5,y+m-5,4,4);
            Fill(x+n-4,y+m-4,2,2);
        }
        afis(auxn,auxm);
        return;
    }
    int nr_dif = s[poz] - c;
    int l_dif = 4 + 2 * (nr_dif - 2);
    int c_dif = 4;
    if(l_dif > n)
    {
        c_dif += (l_dif - n);
        l_dif = n;
    }
    Fill(x,y,n,m - c_dif);
    Fill(x,y + m - c_dif,n - l_dif,c_dif);
    border(x + n - l_dif, y + m - c_dif, l_dif, c_dif);
    Fill(x + n - l_dif + 1, y + m - c_dif + 1, l_dif - 2, c_dif - 2);
    afis(auxn,auxm);
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    for(int test=1;test<=t;test++)
    {
        solve_test();
    }
    return 0;
}

Compilation message

Main.cpp: In function 'void solve_test()':
Main.cpp:115:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  115 |     for(int i=0;i<s.size();i++)
      |                 ~^~~~~~~~~
Main.cpp: At global scope:
Main.cpp:198:5: error: redefinition of 'int a [1005][1005]'
  198 | int a[1005][1005];
      |     ^
Main.cpp:5:5: note: 'int a [1005][1005]' previously declared here
    5 | int a[1005][1005];
      |     ^
Main.cpp:200:5: error: redefinition of 'int cul'
  200 | int cul = 0;
      |     ^~~
Main.cpp:7:5: note: 'int cul' previously defined here
    7 | int cul = 0;
      |     ^~~
Main.cpp:202:6: error: redefinition of 'bool ok(int, int, int)'
  202 | bool ok(int n,int m, int c)
      |      ^~
Main.cpp:9:6: note: 'bool ok(int, int, int)' previously defined here
    9 | bool ok(int n,int m, int c)
      |      ^~
Main.cpp:227:6: error: redefinition of 'void border(int, int, int, int)'
  227 | void border(int x, int y, int n, int m)
      |      ^~~~~~
Main.cpp:34:6: note: 'void border(int, int, int, int)' previously defined here
   34 | void border(int x, int y, int n, int m)
      |      ^~~~~~
Main.cpp:244:6: error: redefinition of 'void Fill(int, int, int, int)'
  244 | void Fill(int x, int y, int n, int m)
      |      ^~~~
Main.cpp:51:6: note: 'void Fill(int, int, int, int)' previously defined here
   51 | void Fill(int x, int y, int n, int m)
      |      ^~~~
Main.cpp:260:6: error: redefinition of 'void afis(int, int)'
  260 | void afis(int n, int m)
      |      ^~~~
Main.cpp:67:6: note: 'void afis(int, int)' previously defined here
   67 | void afis(int n, int m)
      |      ^~~~
Main.cpp:272:6: error: redefinition of 'void clear_mat(int, int)'
  272 | void clear_mat(int n, int m)
      |      ^~~~~~~~~
Main.cpp:79:6: note: 'void clear_mat(int, int)' previously defined here
   79 | void clear_mat(int n, int m)
      |      ^~~~~~~~~
Main.cpp:283:6: error: redefinition of 'void solve_test()'
  283 | void solve_test()
      |      ^~~~~~~~~~
Main.cpp:90:6: note: 'void solve_test()' previously defined here
   90 | void solve_test()
      |      ^~~~~~~~~~
Main.cpp: In function 'void solve_test()':
Main.cpp:308:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  308 |     for(int i=0;i<s.size();i++)
      |                 ~^~~~~~~~~
Main.cpp: At global scope:
Main.cpp:375:5: error: redefinition of 'int main()'
  375 | int main()
      |     ^~~~
Main.cpp:182:5: note: 'int main()' previously defined here
  182 | int main()
      |     ^~~~