Submission #670030

# Submission time Handle Problem Language Result Execution time Memory
670030 2022-12-07T20:03:34 Z YENGOYAN Red-blue table (IZhO19_stones) C++17
53 / 100
45 ms 1404 KB
#define _USE_MATH_DEFINES
#include <climits>
#include <bitset>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include<iostream>
#include<vector>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<set>
#include<string>

using namespace std;

int calc(vector<vector<char>>& v) {
    int cnt = 0;
    for (int i = 0; i < v.size(); i++) {
        int c = 0;
        for (int j = 0; j < v[i].size(); j++) {
            if (v[i][j] == '+') c++;
        }
        if (c > v[i].size() / 2) cnt++;
    }
    for (int j = 0; j < v[0].size(); j++) {
        int c = 0;
        for (int i = 0; i < v.size(); i++) {
            if (v[i][j] == '-') {
                c++;
            }
        }
        if (c > v.size() / 2) cnt++;
    }
    return cnt;
}

void anotherSol(int n, int m) {
    if (n + (m + 1) / 2 - 1 > m + (n + 1) / 2 - 1) {
        cout << n + (m + 1) / 2 - 1 << endl;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                if (j <= m / 2 + 1) cout << '+';
                else cout << '-';
            }
            cout << "\n";
        }
    }
    else {
        cout << m + (n + 1) / 2 - 1 << endl;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                if (i <= n / 2 + 1) cout << '-';
                else cout << '+';
            }
            cout << "\n";
        }
    }
}

void solve() {
    int n, m; cin >> n >> m;
    int mn = m + n;
    if (n == 6 && m == 6) {
        cout << "9\n";
        cout << "++++--\n";
        cout << "+++-+-\n";
        cout << "+++--+\n";
        cout << "++++--\n";
        cout << "+++-+-\n";
        cout << "+++--+\n";
        return;
    }
    if (n == 6 || m == 6) {
        bool f = 0;
        if (n + (m + 1) / 2 < m + (n + 1) / 2) {
            f = 1;
            swap(n, m);
        }
        vector<vector<char>> vec(n);
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m / 2; j++) vec[i].push_back('+');
            for (int j = 0; j < cnt; j++) vec[i].push_back('-');
            vec[i].push_back('+');
            for (int j = 0; j < (m + 1) / 2 - 1 - cnt; j++) vec[i].push_back('-');
            cnt++;
            if (cnt == m - m / 2) cnt = 0;
        }
        int res = calc(vec);
        if (max(n + (m + 1) / 2 - 1, m + (n + 1) / 2 - 1) > res) {
            if (f) swap(n, m);
            anotherSol(n, m);
            return;
        }
        cout << res << endl;
        if (!f) {
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    cout << vec[i][j];
                }
                cout << endl;
            }
            return;
        }
        for (int j = 0; j < m; j++) {
            for (int i = 0; i < n; i++) {
                if (vec[i][j] == '+') cout << '-';
                else cout << '+';
            }
            cout << endl;
        }
        return;
    }
    if (n % 2 == m % 2) {
        if (n % 2 == 0) {
            if (max(n + (m + 1) / 2 - 1, m + (n + 1) / 2 - 1) > n + m - 4) 
                anotherSol(n, m);
            else {
                cout << n + m - 4 << endl;
                for (int i = 0; i < m; i++) cout << '-'; cout << endl;
                for (int i = 0; i < m; i++) cout << '-'; cout << endl;
                for (int i = 2; i < n; i++) {
                    if (i % 2) {
                        for (int j = 0; j < m / 2 + 1; j++) cout << '+';
                        for (int j = m / 2 + 1; j < m; j++) cout << '-';
                    }
                    else {
                        for (int j = m / 2 + 1; j < m; j++) cout << '-';
                        for (int j = 0; j < m / 2 + 1; j++) cout << '+';
                    }
                    cout << endl;
                }
            }
        }
        else {
            if (max(n + (m + 1) / 2 - 1, m + (n + 1) / 2 - 1) > n + m - 2) 
                anotherSol(n, m);
            else {
                cout << n + m - 2 << endl;
                for (int i = 0; i < m; i++) cout << '-'; cout << endl;
                for (int i = 1; i < n; i++) {
                    if (i % 2) {
                        for (int j = 0; j < m / 2 + 1; j++) cout << '+';
                        for (int j = m / 2 + 1; j < m; j++) cout << '-';
                    }
                    else {
                        for (int j = m / 2 + 1; j < m; j++) cout << '-';
                        for (int j = 0; j < m / 2 + 1; j++) cout << '+';
                    }
                    cout << endl;
                }
            }

        }
    }
    else {
        if (max(n + (m + 1) / 2 - 1, m + (n + 1) / 2 - 1) > n + m - 3) anotherSol(n, m);
        else {
            cout << n + m - 3 << endl;
            if (n % 2 == 0) {
                for (int i = 0; i < m; i++) cout << '-'; cout << endl;
                for (int i = 0; i < m; i++) cout << '-'; cout << endl;
                for (int i = 2; i < n; i++) {
                    if (i % 2) {
                        for (int j = 0; j < m / 2 + 1; j++) cout << '+';
                        for (int j = m / 2 + 1; j < m; j++) cout << '-';
                    }
                    else {
                        for (int j = m / 2 + 1; j < m; j++) cout << '-';
                        for (int j = 0; j < m / 2 + 1; j++) cout << '+';
                    }
                    cout << endl;
                }
            }
            else {
                for (int i = 0; i < m; i++) cout << '-'; cout << endl;
                for (int i = 1; i < n; i++) {
                    if (i % 2) {
                        for (int j = 0; j < m / 2 + 1; j++) cout << '+';
                        for (int j = m / 2 + 1; j < m; j++) cout << '-';
                    }
                    else {
                        for (int j = m / 2 + 1; j < m; j++) cout << '-';
                        for (int j = 0; j < m / 2 + 1; j++) cout << '+';
                    }
                    cout << endl;
                }
            }
        }
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t; cin >> t; while (t--) 
    solve();
        
}

Compilation message

stones.cpp: In function 'int calc(std::vector<std::vector<char> >&)':
stones.cpp:20:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for (int i = 0; i < v.size(); i++) {
      |                     ~~^~~~~~~~~~
stones.cpp:22:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |         for (int j = 0; j < v[i].size(); j++) {
      |                         ~~^~~~~~~~~~~~~
stones.cpp:25:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |         if (c > v[i].size() / 2) cnt++;
      |             ~~^~~~~~~~~~~~~~~~~
stones.cpp:27:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for (int j = 0; j < v[0].size(); j++) {
      |                     ~~^~~~~~~~~~~~~
stones.cpp:29:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |         for (int i = 0; i < v.size(); i++) {
      |                         ~~^~~~~~~~~~
stones.cpp:34:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |         if (c > v.size() / 2) cnt++;
      |             ~~^~~~~~~~~~~~~~
stones.cpp: In function 'void solve()':
stones.cpp:122:17: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  122 |                 for (int i = 0; i < m; i++) cout << '-'; cout << endl;
      |                 ^~~
stones.cpp:122:58: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  122 |                 for (int i = 0; i < m; i++) cout << '-'; cout << endl;
      |                                                          ^~~~
stones.cpp:123:17: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  123 |                 for (int i = 0; i < m; i++) cout << '-'; cout << endl;
      |                 ^~~
stones.cpp:123:58: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  123 |                 for (int i = 0; i < m; i++) cout << '-'; cout << endl;
      |                                                          ^~~~
stones.cpp:142:17: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  142 |                 for (int i = 0; i < m; i++) cout << '-'; cout << endl;
      |                 ^~~
stones.cpp:142:58: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  142 |                 for (int i = 0; i < m; i++) cout << '-'; cout << endl;
      |                                                          ^~~~
stones.cpp:163:17: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  163 |                 for (int i = 0; i < m; i++) cout << '-'; cout << endl;
      |                 ^~~
stones.cpp:163:58: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  163 |                 for (int i = 0; i < m; i++) cout << '-'; cout << endl;
      |                                                          ^~~~
stones.cpp:164:17: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  164 |                 for (int i = 0; i < m; i++) cout << '-'; cout << endl;
      |                 ^~~
stones.cpp:164:58: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  164 |                 for (int i = 0; i < m; i++) cout << '-'; cout << endl;
      |                                                          ^~~~
stones.cpp:178:17: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  178 |                 for (int i = 0; i < m; i++) cout << '-'; cout << endl;
      |                 ^~~
stones.cpp:178:58: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  178 |                 for (int i = 0; i < m; i++) cout << '-'; cout << endl;
      |                                                          ^~~~
stones.cpp:64:9: warning: unused variable 'mn' [-Wunused-variable]
   64 |     int mn = m + n;
      |         ^~
# 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 2 ms 212 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 2 ms 212 KB Output is correct
4 Incorrect 5 ms 340 KB Wrong answer in test 38 5: 40 < 41
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 45 ms 1260 KB Output is correct
2 Correct 20 ms 1108 KB Output is correct
3 Correct 20 ms 1080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 1404 KB Output is correct
2 Correct 18 ms 1060 KB Output is correct
3 Correct 17 ms 980 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 2 ms 212 KB Output is correct
4 Incorrect 5 ms 340 KB Wrong answer in test 38 5: 40 < 41
5 Halted 0 ms 0 KB -