답안 #781409

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
781409 2023-07-13T05:36:41 Z ZHIRDILBILDIZ Red-blue table (IZhO19_stones) C++14
27 / 100
55 ms 1236 KB
#include<bits/stdc++.h>
using namespace std ;
int main()
{
    ios_base::sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
    int t ;
    cin >> t ;
    while(t--)
    {
        int n, m, mx = 0 ;
        cin >> n >> m ;
        char c[n][m], ans[n][m] ;
        if(n * m <= 16)
        {
            for(int x = 0 ; x < (1 << (n * m)) ; x++)
            {
                int st[m] = {}, str[n] = {}, sum = 0 ;
                for(int i = 0 ; i < n ; i++)
                    for(int j = 0 ; j < m ; j++)
                        if(x & (1 << (i * m + j)))
                        {
                            str[i]++ ;
                            c[i][j] = '+' ;
                        }
                        else
                        {
                            st[j]++ ;
                            c[i][j] = '-' ;
                        }
                for(int i = 0 ; i < n ; i++)
                    if(str[i] > m / 2)sum++ ;
                for(int i = 0 ; i < m ; i++)
                    if(st[i] > n / 2)sum++ ;
                if(mx < sum)
                {
                    for(int i = 0 ; i < n ; i++)
                        for(int j = 0 ; j < m ; j++)
                            ans[i][j] = c[i][j] ;
                }
                mx = max(mx, sum) ;
            }
            cout << mx << '\n' ;
            for(int i = 0 ; i < n ; i++)
            {
                for(int j = 0 ; j < m ; j++)
                    cout << ans[i][j] ;
                cout << '\n' ;
            }
            continue ;
        }
        if(min(n, m) == 1)
        {
            if(n == 1)
            {
                cout << m << '\n' ;
                for(int i = 0 ; i < m ; i++)
                    ans[0][i] = '-' ;
            }
            else
            {
                cout << n << '\n' ;
                for(int i = 0 ; i < n ; i++)
                    ans[i][0] = '+' ;
            }
            for(int i = 0 ; i < n ; i++)
            {
                for(int j = 0 ; j < m ; j++)
                    cout << ans[i][j];
                cout << '\n' ;
            }
            continue ;
        }
        if(min(n, m) == 2)
        {
            if(n == 2)
            {
                cout << m << '\n' ;
                for(int i = 0 ; i < n ; i++)
                    for(int j = 0 ; j < m ; j++)
                        ans[i][j] = '-' ;
            }
            else
            {
                cout << n << '\n' ;
                for(int i = 0 ; i < n ; i++)
                    for(int j = 0 ; j < m ; j++)
                        ans[i][j] = '+' ;
            }
            for(int i = 0 ; i < n ; i++)
            {
                for(int j = 0 ; j < m ; j++)
                    cout << ans[i][j];
                cout << '\n' ;
            }
            continue ;
        }
        if(min(n, m) == 3)
        {
            if(n == 3)
            {
                for(int i = 0 ; i < n - 1 ; i++)
                    for(int j = 0 ; j < m ; j++)
                        ans[i][j] = '-' ;
                for(int i = 0 ; i < m ; i++)
                    ans[n - 1][i] = '+' ;
            }
            else
            {
                for(int i = 0 ; i < n ; i++)
                    for(int j = 0 ; j < m - 1 ; j++)
                        ans[i][j] = '+' ;
                for(int i = 0 ; i < n ; i++)
                    ans[i][m - 1] = '-' ;
            }
            cout << max(n, m) + 1 << '\n' ;
            for(int i = 0 ; i < n ; i++)
            {
                for(int j = 0 ; j < m ; j++)
                    cout << ans[i][j] ;
                cout << '\n' ;
            }
            continue ;
        }
        if(min(n, m) == 4)
        {
            if(n == 4)
            {
                for(int i = 0 ; i < n - 1 ; i++)
                    for(int j = 0 ; j < m ; j++)
                        ans[i][j] = '-' ;
                for(int i = 0 ; i < m ; i++)
                    ans[n - 1][i] = '+' ;
            }
            else
            {
                for(int i = 0 ; i < n ; i++)
                    for(int j = 0 ; j < m - 1 ; j++)
                        ans[i][j] = '+' ;
                for(int i = 0 ; i < n ; i++)
                    ans[i][m - 1] = '-' ;
            }
            cout << max(n, m) + 1 << '\n' ;
            for(int i = 0 ; i < n ; i++)
            {
                for(int j = 0 ; j < m ; j++)
                    cout << ans[i][j] ;
                cout << '\n' ;
            }
            continue ;
        }
        if(min(n, m) == 5)
        {
            if(n == 5)
            {
                for(int i = 0 ; i < n - 1 ; i++)
                    for(int j = 0 ; j < m ; j++)
                        ans[i][j] = '-' ;
                for(int i = 0 ; i < m ; i++)
                    ans[n - 1][i] = ans[0][i] = '+' ;
            }
            else
            {
                for(int i = 0 ; i < n ; i++)
                    for(int j = 0 ; j < m - 1 ; j++)
                        ans[i][j] = '+' ;
                for(int i = 0 ; i < n ; i++)
                    ans[i][m - 1] = ans[i][0] = '-' ;
            }
            cout << max(n, m) + 2 << '\n' ;
            for(int i = 0 ; i < n ; i++)
            {
                for(int j = 0 ; j < m ; j++)
                    cout << ans[i][j] ;
                cout << '\n' ;
            }
            continue ;
        }
        if(n % 2 && m % 2)
        {
            mx = max(n + m / 2, m + n / 2) ;
            if(n > m)
            {
                for(int i = 0 ; i < n ; i++)
                    for(int j = 0 ; j < m ; j++)
                        if(j % 2 == 0)ans[i][j] = '+' ;
                        else ans[i][j] = '-' ;
            }
            else
            {
                for(int i = 0 ; i < n ; i++)
                    for(int j = 0 ; j < m ; j++)
                        if(i % 2)ans[i][j] = '+' ;
                        else ans[i][j] = '-' ;
            }
            cout << mx << '\n' ;
            for(int i = 0 ; i < n ; i++)
            {
                for(int j = 0 ; j < m ; j++)
                    cout << ans[i][j] ;
                cout << '\n' ;
            }
            continue ;
        }
    }
    return 0 ;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 6 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 6 ms 212 KB Output is correct
3 Correct 42 ms 212 KB Output is correct
4 Incorrect 55 ms 320 KB Wrong answer in test 5 29: 31 < 32
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 18 ms 1236 KB Wrong answer in test 97 21: 107 < 116
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 14 ms 772 KB Wrong answer
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 6 ms 212 KB Output is correct
3 Correct 42 ms 212 KB Output is correct
4 Incorrect 55 ms 320 KB Wrong answer in test 5 29: 31 < 32
5 Halted 0 ms 0 KB -