답안 #746558

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
746558 2023-05-22T18:46:27 Z Denkata Red-blue table (IZhO19_stones) C++14
27 / 100
23 ms 1412 KB
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
int i,j,p,q,n,m,k;
int T;
char  ans[1006][1006];
int  do_count()
{
    int otg = 0;
    for(i=1; i<=n; i++)
    {
        int br = 0;
        for(j=1; j<=m; j++)
        {
            // cout<<ans[i][j]<<" "<<br<<endl;
            if(ans[i][j]=='+')
                br++;
        }
        // cout<<i<<" "<<br<<endl;
        if(br>=m/2+1)otg++;
    }
    for(i=1; i<=m; i++)
    {
        int br = 0;
        for(j=1; j<=n; j++)
        {
            if(ans[j][i]=='-')
                br++;

        }
        if(br>=n/2+1)otg++;
    }
    return otg;
}
void solve()
{
    cin>>n>>m;
    for(i=1; i<=n; i++)
    {
        for(j=1; j<=m; j++)
        {
            ans[i][j] = '&';
        }
    }
    if(n==1)
    {
        cout<<m<<endl;
        for(j=1; j<=m; j++)
            cout<<'-';
        cout<<endl;
        return ;
    }
    if(m==1)
    {
        cout<<n<<endl;
        for(j=1; j<=n; j++)
            cout<<'+'<<endl;
        return ;
    }
    if(n==2 || m==2)
    {
        char znak = '+';
        if(m>n)znak = '-';
        for(i=1; i<=n; i++)
            for(j=1; j<=m; j++)
                ans[i][j]=znak;
        cout<<do_count()<<endl;
        for(i=1; i<=n; i++)
        {
            for(j=1; j<=m; j++)
                cout<<ans[i][j];
            cout<<endl;
        }
        return ;
    }
    int br = 0;
    if(n%2!=m%2)
        br = n+m-3;
    if(n%2==0 && m%2==0)
        br = n+m-4;
    if(n+m-m/2-1>=m+n-n/2-1 && n+m-m/2-1>br)
    {
        cout<<n+m-m/2-1<<endl;
        for(i=1; i<=n; i++)
            for(j=1; j<=m/2+1; j++)
                ans[i][j]='+';
        for(i=1; i<=n; i++)
            for(j=m/2+2; j<=m; j++)
                ans[i][j]='-';
        for(i=1; i<=n; i++)
        {
            for(j=1; j<=m; j++)
                cout<<ans[i][j];
            cout<<endl;
        }
        return ;
    }
    else if(n+m-m/2-1<=m+n-n/2-1 && m+n-n/2-1>br)
    {
        cout<<m+n-n/2-1<<endl;
        for(i=1; i<=m; i++)
            for(j=1; j<=n/2+1; j++)
                ans[j][i]='-';
        for(i=1; i<=m; i++)
            for(j=n/2+2; j<=n; j++)
                ans[j][i]='+';
        for(i=1; i<=n; i++)
        {
            for(j=1; j<=m; j++)
                cout<<ans[i][j];
            cout<<endl;
        }
        return ;
    }
    int non_dom = n/2;
    int non_domm = m/2;
    if(m%2==0)
        non_domm--;
    if(n%2==0)
        non_dom--;
    for(i=1; i<=non_dom; i++)
    {
        for(j=1; j<=m/2+1; j++)
            ans[i][j]='+';
    }
    for(i=non_dom+1; i<=n; i++)
    {
        for(j=1; j<=non_domm; j++)
            ans[i][j]='-';
    }
    for(i=1; i<=n/2+1; i++)
    {
        for(j=m/2+2; j<=m; j++)
            ans[i][j]='-';
    }

    for(i=1; i<=n; i++)
    {
        for(j=1; j<=m; j++)
        {
            if(ans[i][j]=='&')
                ans[i][j]='+';

        }
    }
    cout<<do_count()<<endl;
    for(i=1; i<=n; i++)
    {
        for(j=1; j<=m; j++)
            cout<<ans[i][j];
        cout<<endl;
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>T;
    while(T--)
        solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Incorrect 2 ms 340 KB Wrong answer in test 5 29: 31 < 32
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 23 ms 1396 KB Wrong answer in test 97 21: 107 < 116
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 22 ms 1412 KB Wrong answer in test 19 19: 28 < 36
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Incorrect 2 ms 340 KB Wrong answer in test 5 29: 31 < 32
5 Halted 0 ms 0 KB -