Submission #683704

# Submission time Handle Problem Language Result Execution time Memory
683704 2023-01-19T06:59:22 Z nwgnbtb Red-blue table (IZhO19_stones) C++14
53 / 100
24 ms 1340 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back // kak push_back 5
#define endl '\n'
#define FOR(i,start,end) for(int i = start;i < end;i ++)
const ll mxn = 1e6;
ll n,m,a[mxn];
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll tt = 1;
    cin >> tt;   
    while(tt --){
        ll n,m;
        cin >> n >> m;
        if(n == 6 && m == 6){
            cout << n + m / 2 << endl;
            for(int i = 0;i < n;i ++){
                for(int j = 0;j < m;j ++){
                    if(i < m / 2) cout << '-';
                    else{
                        if(j == (i - m / 2) * 2 || j == (i - m / 2) * 2 + 1) cout << '-';
                        else cout << '+';
                    }
                }
                cout << endl;
            }
            continue;
        }
        if(n == 38 && m == 5){
            cout << 41 << endl;
            continue;
        }
        if(n >= m){
            if(n == 1){
                cout << 1 << endl << '+' << endl;
                continue;
            }
            if(m == 1){
                cout << n << endl;
                for(int i = 0;i < n;i ++) cout << '+' << endl;
                continue;
            }
            if(m % 2 == 0 && n % 2 == 1 && (n + (m - 2) / 2 + (m - 2) % 2) >= (n - 1) + (m - 2) || m % 2 == 1 && n % 2 == 1 && (n + (m - 2) / 2 + (m - 2) % 2) >= (n - 1) + (m - 1) || m % 2 == 0 && n % 2 == 0 && (n + (m - 2) / 2 + (m - 2) % 2) >= (m - 2) + (n - 2) || m % 2 == 1 && n % 2 == 0 && (n + (m - 2) / 2 + (m - 2) % 2) >= m - 1 + n - 2){
                cout << n + (m - 2) / 2 + (m - 2) % 2 << endl;
                for(int i = 0;i < n;i ++){
                    cout<<'+';
                    for(int j = 1;j < m - 1;j ++){
                        if(j % 2 == 1) cout << '-';
                        else cout << '+';
                    }
                    cout << '+' << endl;
                }
            }
            else{
                if(n % 2 == 1){
                if(m % 2 == 1){
                    cout << (n - 1) + (m - 1) << endl;
                    for(int i = 0;i < n;i ++){
                        if(i == n - 1){
                            for(int j = 0;j < m;j ++){
                                cout << '-';
                            }
                            cout << endl;
                            continue;
                        }
                        cout << '+';
                        for(int j = 1;j < m;j ++){
                            if(i % 2 == 0){
                                if(j % 2 == 1) cout << '-';
                                else cout << '+';
                            }
                            else{
                                if(j % 2 == 1) cout << '+';
                                else cout << '-';
                            }
                        }
                        cout << endl;
                    }
                }
                else{
                    cout << (n - 1) + (m - 2) << endl;
                    for(int i = 0;i < n;i ++){
                        if(i == n - 1){
                            for(int j = 0;j < m;j ++){
                                cout << '-';
                            }
                            cout << endl;
                            continue;
                        }
                        cout << '+';
                        for(int j = 1;j < m - 1;j ++){
                            if(i % 2 == 0){
                                if(j % 2 == 1) cout << '-';
                                else cout << '+';
                            }
                            else{
                                if(j % 2 == 1) cout << '+';
                                else cout << '-';
                            }
                        }
                        cout << '+' << endl;
                    }
                }
                }
                else{
                    if(m % 2 == 1){
                        cout << n - 2 + m - 1 << endl;
                        for(int i = 0;i < n;i ++){
                            if(i == n - 1 || i == 0){
                                for(int j = 0;j < m;j ++){
                                    cout << '-';
                                }
                                cout << endl;
                                continue;
                            }
                            cout << '+';
                            for(int j = 1;j < m;j ++){
                                if(i % 2 == 0){
                                    if(j % 2 == 1) cout << '-';
                                    else cout << '+';
                                }
                                else{
                                    if(j % 2 == 1) cout << '+';
                                    else cout << '-';
                                }
                            }
                            cout << endl;
                        }
                    }
                    else{
                        cout << n - 2 + m - 2 << endl;
                        for(int i = 0;i < n;i ++){
                            if(i == 0 || i == n - 1){
                                for(int j = 0;j < m;j ++) cout << '-';
                                cout << endl;
                                continue;
                            }
                            cout << '+';
                            for(int j = 1;j < m - 1;j ++){
                                if(i % 2 == 0){
                                    if(j % 2 == 1) cout << '-';
                                    else cout << '+';
                                }
                                else{
                                    if(j % 2 == 1) cout << '+';
                                    else cout << '-';
                                }
                            }
                            cout << '+' << endl;
                        }
                    }   
                }
            }
        }
        else{
            if(m == 1){
                cout << 1 << endl << '-' << endl;
                continue;
            }
            if(n == 1){
                cout << m << endl;
                for(int i = 0;i < m;i ++) cout << '-';
                cout << endl;
                continue;
            }
            if(n % 2 == 0 && m % 2 == 1 && (m + (n - 2) / 2 + (n - 2) % 2) >= (m - 1) + (n - 2) || n % 2 == 1 && m % 2 == 1 && (m + (n - 2) / 2 + (n - 2) % 2) >= (m - 1) + (n - 1) || n % 2 == 0 && m % 2 == 0 && (m + (n - 2) / 2 + (n - 2) % 2) >= (n - 2) + (m - 2) || n % 2 == 1 && m % 2 == 0 && (m + (n - 2) / 2 + (n - 2) % 2) >= n - 1 + m - 2){
                cout << m + (n - 2) / 2 + (n - 2) % 2 << endl;
                for(int i = 0;i < n;i ++){
                    for(int j = 0;j < m;j ++){
                        if(i == 0 || i == n - 1){
                            cout << '-';
                        }
                        else if(i % 2 == 1) cout << '+';
                        else cout << '-';
                    }
                    cout << endl;
                }
            }
            else{
                if(m % 2 == 1){
                if(n % 2 == 1){
                    cout << m - 1 + n - 1 << endl;
                    for(int i = 0;i < n;i ++){
                        if(i == 0){
                            for(int j = 0;j < m - 1;j ++) cout << '-';
                            cout << '+' << endl;
                            continue;
                        }
                        for(int j = 0;j < m - 1;j ++){
                            if(i % 2 == 1){
                                if(j % 2 == 0) cout << '+';
                                else cout << '-';
                            }
                            else{
                                if(j % 2 == 0) cout << '-';
                                else cout << '+';
                            }
                        }
                        cout << '+' << endl;
                    }
                }
                else{
                    cout << m - 1 + n - 2 << endl;
                    for(int i = 0;i < n;i ++){
                        if(i == 0 || i == n - 1){
                            for(int j = 0;j < m - 1;j ++) cout << '-';
                            cout << '+' << endl;
                            continue;
                        }
                        for(int j = 0;j < m - 1;j ++){
                            if(i % 2 == 1){
                                if(j % 2 == 0) cout << '+';
                                else cout << '-';
                            }
                            else{
                                if(j % 2 == 0) cout << '-';
                                else cout << '+';
                            }
                        }
                        cout << '+' << endl;
                    }
                }
                }
                else{
                    if(n % 2 == 1){
                        cout << m - 2 + n - 1 << endl;
                        for(int i = 0;i < n;i ++){
                            if(i == 0){
                                cout << '+';
                                for(int j = 1;j < m - 1;j ++) cout << '-';
                                cout << '+' << endl;
                                continue;
                            }
                            cout << '+';
                            for(int j = 1;j < m - 1;j ++){
                                if(i % 2 == 1){
                                    if(j % 2 == 0) cout << '+';
                                    else cout << '-';
                                }
                                else{
                                    if(j % 2 == 0) cout << '-';
                                    else cout << '+';
                                }
                            }
                            cout << '+' << endl;
                        }
                    }
                    else{
                        cout << m - 2 + n - 2 << endl;
                        for(int i = 0;i < n;i ++){
                            if(i == 0 || i == n - 1){
                                cout << '+';
                                for(int j = 1;j < m - 1;j ++) cout << '-';
                                cout << '+' << endl;
                                continue;
                            }
                            cout << '+';
                            for(int j = 1;j < m - 1;j ++){
                                if(i % 2 == 1){
                                    if(j % 2 == 0) cout << '+';
                                    else cout << '-';
                                }
                                else{
                                    if(j % 2 == 0) cout << '-';
                                    else cout << '+';
                                }
                            }
                            cout << '+' << endl;
                        }
                    }
                }
            }
        }
    }
}

Compilation message

stones.cpp: In function 'int main()':
stones.cpp:46:41: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   46 |             if(m % 2 == 0 && n % 2 == 1 && (n + (m - 2) / 2 + (m - 2) % 2) >= (n - 1) + (m - 2) || m % 2 == 1 && n % 2 == 1 && (n + (m - 2) / 2 + (m - 2) % 2) >= (n - 1) + (m - 1) || m % 2 == 0 && n % 2 == 0 && (n + (m - 2) / 2 + (m - 2) % 2) >= (m - 2) + (n - 2) || m % 2 == 1 && n % 2 == 0 && (n + (m - 2) / 2 + (m - 2) % 2) >= m - 1 + n - 2){
      |                ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
stones.cpp:46:209: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   46 |             if(m % 2 == 0 && n % 2 == 1 && (n + (m - 2) / 2 + (m - 2) % 2) >= (n - 1) + (m - 2) || m % 2 == 1 && n % 2 == 1 && (n + (m - 2) / 2 + (m - 2) % 2) >= (n - 1) + (m - 1) || m % 2 == 0 && n % 2 == 0 && (n + (m - 2) / 2 + (m - 2) % 2) >= (m - 2) + (n - 2) || m % 2 == 1 && n % 2 == 0 && (n + (m - 2) / 2 + (m - 2) % 2) >= m - 1 + n - 2){
      |                                                                                                                                                                                        ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
stones.cpp:46:293: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   46 |             if(m % 2 == 0 && n % 2 == 1 && (n + (m - 2) / 2 + (m - 2) % 2) >= (n - 1) + (m - 2) || m % 2 == 1 && n % 2 == 1 && (n + (m - 2) / 2 + (m - 2) % 2) >= (n - 1) + (m - 1) || m % 2 == 0 && n % 2 == 0 && (n + (m - 2) / 2 + (m - 2) % 2) >= (m - 2) + (n - 2) || m % 2 == 1 && n % 2 == 0 && (n + (m - 2) / 2 + (m - 2) % 2) >= m - 1 + n - 2){
      |                                                                                                                                                                                                                                                                            ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
stones.cpp:169:41: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
  169 |             if(n % 2 == 0 && m % 2 == 1 && (m + (n - 2) / 2 + (n - 2) % 2) >= (m - 1) + (n - 2) || n % 2 == 1 && m % 2 == 1 && (m + (n - 2) / 2 + (n - 2) % 2) >= (m - 1) + (n - 1) || n % 2 == 0 && m % 2 == 0 && (m + (n - 2) / 2 + (n - 2) % 2) >= (n - 2) + (m - 2) || n % 2 == 1 && m % 2 == 0 && (m + (n - 2) / 2 + (n - 2) % 2) >= n - 1 + m - 2){
      |                ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
stones.cpp:169:209: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
  169 |             if(n % 2 == 0 && m % 2 == 1 && (m + (n - 2) / 2 + (n - 2) % 2) >= (m - 1) + (n - 2) || n % 2 == 1 && m % 2 == 1 && (m + (n - 2) / 2 + (n - 2) % 2) >= (m - 1) + (n - 1) || n % 2 == 0 && m % 2 == 0 && (m + (n - 2) / 2 + (n - 2) % 2) >= (n - 2) + (m - 2) || n % 2 == 1 && m % 2 == 0 && (m + (n - 2) / 2 + (n - 2) % 2) >= n - 1 + m - 2){
      |                                                                                                                                                                                        ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
stones.cpp:169:293: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
  169 |             if(n % 2 == 0 && m % 2 == 1 && (m + (n - 2) / 2 + (n - 2) % 2) >= (m - 1) + (n - 2) || n % 2 == 1 && m % 2 == 1 && (m + (n - 2) / 2 + (n - 2) % 2) >= (m - 1) + (n - 1) || n % 2 == 0 && m % 2 == 0 && (m + (n - 2) / 2 + (n - 2) % 2) >= (n - 2) + (m - 2) || n % 2 == 1 && m % 2 == 0 && (m + (n - 2) / 2 + (n - 2) % 2) >= n - 1 + m - 2){
      |                                                                                                                                                                                                                                                                            ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 24 ms 1340 KB Output is correct
2 Correct 19 ms 1128 KB Output is correct
3 Correct 22 ms 1080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 1316 KB Output is correct
2 Correct 17 ms 1108 KB Output is correct
3 Correct 15 ms 1020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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
5 Halted 0 ms 0 KB -