Submission #992957

# Submission time Handle Problem Language Result Execution time Memory
992957 2024-06-05T08:35:22 Z vivkostov Red-blue table (IZhO19_stones) C++14
100 / 100
37 ms 3156 KB
#include<bits/stdc++.h>
#define endl "\n"
using namespace std;
void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

struct cell
{
    int br,in;
};
bool cmp(cell a1,cell a2)
{
    return a1.br<a2.br;
}
int t,n,m,h;
char a1,a2;
string s[1005];
cell a[1005];
void print(int br)
{
    cout<<br<<endl;
    if(h)
    {
        for(int i=1; i<=m; i++)
        {
            for(int j=1; j<=n; j++)
            {
                cout<<s[j][i-1];
            }
            cout<<endl;
        }
        return;
    }
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
        {
            cout<<s[i][j-1];
        }
        cout<<endl;
    }
}
void fil(int i)
{
    for(int j=1;j<=m;j++)s[i]+=a1;
}
void prea2()
{
    int gr=(((m-1)/2)*n)/(n/2+1);
    for(int i=m-gr+1;i<=m;i++)
    {
        a[i].in=i;
        a[i].br=0;
    }
}
void fila2(int i)
{
    int gr=(((m-1)/2)*n)/(n/2+1);
    sort(a+m-gr+1,a+m+1,cmp);
    for(int j=1;j<=(m-1)/2;j++)
    {
        //cout<<a[m-gr+j].in<<" ";
        s[i][a[m-gr+j].in-1]=a2;
        a[m-gr+j].br++;
    }
    //cout<<endl;
}
void old()
{
    int br=0;
    if(false);
    else
    {
        for(int i=1; i<=n; i++)
        {
            for(int j=1; j<=m/2+1; j++)
            {
                s[i]+=a1;
            }
            for(int j=m/2+2; j<=m; j++)
            {
                s[i]+=a2;
            }
            br++;
        }
        br+=(m-1)/2;
    }
    print(br);
}
void resheven()
{
    prea2();
    if(n<=3||m<=3)
    {
        old();
        return;
    }
    int br=n+(((m-1)/2)*n)/(n/2+1),pos=m,gr=(((m-1)/2)*n)/(n/2+1);
    //cout<<(((m-1)/2)*n)/(n/2+1)<<" "<<br<<endl;
    for(int i=1;i<=n;i++)
    {
        fil(i);
        fila2(i);
        pos--;
        if(pos<=m-gr)pos=m;
    }
    print(br);
}
void resh()
{
    int br=0;
    for(int i=1; i<=(n-1)/2; i++)
    {
        for(int j=1; j<=m/2+1; j++)
        {
            s[i]+=a1;
        }
        for(int j=m/2+2; j<=m; j++)
        {
            s[i]+=a2;
        }
        br++;
    }
    for(int i=(n-1)/2+1; i<=n-1; i++)
    {
        for(int j=1; j<=(m-1)/2; j++)
        {
            s[i]+=a2;
        }
        for(int j=(m-1)/2+1; j<=m; j++)
        {
            s[i]+=a1;
        }
        br++;
    }
    if(m>2)
    {
        for(int i=1; i<=m; i++)
        {
            s[n]+=a2;
        }
        br+=((m-1)/2)*2;
    }
    else
    {
        for(int i=1; i<=m; i++)
        {
            s[n]+=a1;
        }
        br++;
    }
    print(br);
}
void read()
{
    cin>>t;
    for(int z=1; z<=t; z++)
    {
        cin>>n>>m;
        if(n<m)
        {

            swap(n,m);
            a1='-';
            a2='+';
            h=1;
        }
        else
        {
            a1='+';
            a2='-';
        }
        if(n%2==0)resheven();
        else resh();
        h=0;
        for(int i=1; i<=n; i++)s[i].clear();
    }
}
int main()
{
    speed();
    read();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 1368 KB Output is correct
2 Correct 17 ms 2136 KB Output is correct
3 Correct 16 ms 2140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 1368 KB Output is correct
2 Correct 20 ms 1884 KB Output is correct
3 Correct 18 ms 1736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 19 ms 1368 KB Output is correct
6 Correct 17 ms 2136 KB Output is correct
7 Correct 16 ms 2140 KB Output is correct
8 Correct 23 ms 1368 KB Output is correct
9 Correct 20 ms 1884 KB Output is correct
10 Correct 18 ms 1736 KB Output is correct
11 Correct 5 ms 604 KB Output is correct
12 Correct 16 ms 1852 KB Output is correct
13 Correct 36 ms 1976 KB Output is correct
14 Correct 22 ms 1368 KB Output is correct
15 Correct 37 ms 3156 KB Output is correct
16 Correct 26 ms 1880 KB Output is correct
17 Correct 6 ms 1116 KB Output is correct