답안 #500600

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
500600 2021-12-31T14:00:34 Z kusmetliq Red-blue table (IZhO19_stones) C++14
38 / 100
66 ms 2032 KB
#include<bits/stdc++.h>
using namespace std;
vector<char>anss[1002];
void sollve(int n,int m)
{
    {
        for(int i=0;i<n;i++)
        {
            if(i<n/2)
            {
                for(int j=0;j<m/2+1;j++)anss[i].push_back('+');
                for(int j=m/2+1;j<m;j++)anss[i].push_back('-');
            }
            else if(i==n/2)
            {
                for(int j=0;j<m;j++)anss[i].push_back('-');
            }
            else
            {
                for(int j=m/2+1;j<m;j++)anss[i].push_back('-');
                for(int j=0;j<m/2+1;j++)anss[i].push_back('+');
            }
        }
    }
}
void solve()
{
    int n,m;
    cin>>n>>m;
    if(n==1){cout<<m<<endl;for(int i=0;i<m;i++)cout<<'-';cout<<endl;return;}
    if(m==1){cout<<n<<endl;for(int i=0;i<n;i++)cout<<'+'<<endl;return;}
    if(n%2==1 && m%2==1)
    {
        sollve(n,m);
        cout<<m-1+n-1<<endl;
            for(int i=0;i<n;i++)
            {
                for(int j=0;j<m;j++)cout<<anss[i][j];
                cout<<endl;
                anss[i].clear();
            }
        return;
    }
    char ans1[n][m],ans2[n][m];
    int a1=n,a2=m;
    vector<int>v1(n,0),v2(m,0);
    for(int j=0;j<m;j++)
    {
        int cnt=0;
        for(int i=0;i<n;i++)
        {
            if(v1[i]<(m+1)/2-1)cnt++;
        }
        if(cnt>n/2)
        {
            a1++;
            int num=n/2+1;
            for(int i=0;i<n;i++)
            {
                if(v1[i]<m/2 && num!=0)
                {
                    v1[i]++;
                    num--;
                    ans1[i][j]='-';
                }
                else ans1[i][j]='+';
            }
        }
        else for(int i=0;i<n;i++)ans1[i][j]='+';
    }
    for(int i=0;i<n;i++)
    {
        int cnt=0;
        for(int j=0;j<m;j++)
        {
            if(v2[j]<(n+1)/2-1)cnt++;
        }
        if(cnt>m/2)
        {
            a2++;
            int num=m/2+1;
            for(int j=0;j<m;j++)
            {
                if(v2[j]<n/2 && num!=0)
                {
                    v2[j]++;
                    num--;
                    ans2[i][j]='+';
                }
                else ans2[i][j]='-';
            }
        }
        else for(int j=0;j<m;j++)ans2[i][j]='-';
    }
    cout<<max(a1,a2)<<endl;
    if(a2>a1)
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<m;j++)
                cout<<ans2[i][j];
            cout<<endl;
        }
    else
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<m;j++)
                cout<<ans1[i][j];
            cout<<endl;
        }
}
int main()
{
    int t;
    cin>>t;
    while(t--)solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 8 ms 272 KB Output is correct
4 Incorrect 15 ms 332 KB Wrong answer in test 38 5: 40 < 41
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 1340 KB Output is correct
2 Correct 33 ms 1844 KB Output is correct
3 Correct 37 ms 2032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 66 ms 1396 KB Wrong answer in test 24 24: 35 < 44
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 8 ms 272 KB Output is correct
4 Incorrect 15 ms 332 KB Wrong answer in test 38 5: 40 < 41