Submission #171205

#TimeUsernameProblemLanguageResultExecution timeMemory
171205donentsetoRed-blue table (IZhO19_stones)C++14
100 / 100
30 ms1428 KiB
#include <bits/stdc++.h>
using namespace std;
int main (){

    ios::sync_with_stdio (false);
    cin.tie (0);

    int t;
    cin >> t;
    while (t --){
        int n, m;
        cin >> n >> m;
        if (n <= 2 && m >= n){
            cout << m << '\n';
            for (int i = 0; i < n; i ++){
                for (int j = 0; j < m; j ++) cout << '-';
                cout << '\n';
            }
        }
        else if (m <= 2){
            cout << n << '\n';
            for (int i = 0; i < n; i ++){
                for (int j = 0; j < m; j ++) cout << '+';
                cout << '\n';
            }
        }
        /*else if (n <= 4 && m >= n){
            cout << m + 1 << '\n';
            for (int i = 0; i < m; i ++) cout << '+';
            cout << '\n';
            for (int i = 1; i < n; i ++){
                for (int i = 0; i < m; i ++) cout << '-';
                cout << '\n';
            }
        }
        else if (m <= 4){
            cout << n + 1 << '\n';
            for (int i = 0; i < n; i ++){
                cout << '-';
                for (int j = 1; j < m; j ++) cout << '+';
                cout << '\n';
            }
        }*/
        else if (m % 2 == 0 && (n - 1 >> 1) << 1 <= (m >> 1) + 1){
            cout << m + n - 3 + n % 2 << '\n';
            for (int i = 0; i < n - 1 >> 1; i ++){
                for (int j = 0; j <= m >> 1; j ++){
                    if (j >> 1 == i) cout << '+';
                    else cout << '-';
                }
                for (int j = 1; j < m >> 1; j ++) cout << '+';
                cout << '\n';
            }
            for (int i = n & 1; i < 3; i ++){
                for (int j = 0; j < m; j ++) cout << '-';
                cout << '\n';
            }
            for (int i = 1; i < n - 1 >> 1; i ++){
                for (int j = 0; j <= m >> 1; j ++) cout << '+';
                for (int j = 1; j < m >> 1; j ++) cout << '-';
                cout << '\n';
            }
        }
        else if (n % 2 == 0 && (m - 1 >> 1) << 1 <= (n >> 1) + 1){
           cout << m + n - 3 + m % 2 << '\n';
           for (int i = 0; i <= n >> 1; i ++){
               for (int j = 0; j < m - 1 >> 1; j ++){
                   if (i >> 1 == j) cout << '-';
                   else cout << '+';
               }
               for (int j = m & 1; j < 3; j ++) cout << '+';
               for (int j = 1; j < m - 1 >> 1; j ++) cout << '-';
               cout << '\n';
           }
           for (int i = 1; i < n >> 1; i ++){
               for (int j = 0; j < m - 1 >> 1; j ++) cout << '-';
               for (int j = 0; j <= m >> 1; j ++) cout << '+';
               cout << '\n';
           }
        }
        else{
            cout << n - 2 + n % 2 + m - 2 + m % 2 << '\n';
            for (int i = 0; i < n; i ++){
                for (int j = 0; j < m; j ++){
                    if (i <= n >> 1 && j < m - 1 >> 1) cout << '-';
                    else if (i >= n - 1 >> 1 && j > m >> 1) cout << '-';
                    else cout << '+';
                }
                cout << '\n';
            }
        }
    }

}

Compilation message (stderr)

stones.cpp: In function 'int main()':
stones.cpp:44:35: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
         else if (m % 2 == 0 && (n - 1 >> 1) << 1 <= (m >> 1) + 1){
                                 ~~^~~
stones.cpp:46:35: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
             for (int i = 0; i < n - 1 >> 1; i ++){
                                 ~~^~~
stones.cpp:58:35: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
             for (int i = 1; i < n - 1 >> 1; i ++){
                                 ~~^~~
stones.cpp:64:35: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
         else if (n % 2 == 0 && (m - 1 >> 1) << 1 <= (n >> 1) + 1){
                                 ~~^~~
stones.cpp:67:38: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
                for (int j = 0; j < m - 1 >> 1; j ++){
                                    ~~^~~
stones.cpp:72:38: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
                for (int j = 1; j < m - 1 >> 1; j ++) cout << '-';
                                    ~~^~~
stones.cpp:76:38: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
                for (int j = 0; j < m - 1 >> 1; j ++) cout << '-';
                                    ~~^~~
stones.cpp:85:46: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
                     if (i <= n >> 1 && j < m - 1 >> 1) cout << '-';
                                            ~~^~~
stones.cpp:86:37: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
                     else if (i >= n - 1 >> 1 && j > m >> 1) cout << '-';
                                   ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...