Submission #668438

# Submission time Handle Problem Language Result Execution time Memory
668438 2022-12-03T22:15:38 Z YENGOYAN Red-blue table (IZhO19_stones) C++17
38 / 100
66 ms 2072 KB
#include <iostream>
#include <vector>

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 malSol(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;
    if (min(m, n) <= 3 || (n <= 4 && m <= 4)) {
        malSol(n, m);
        return;
    }
    if (n % 2) {
        if(max(n + (m + 1) / 2 - 1, m + (n + 1) / 2 - 1) > n + m - 2 - (1 - (m % 2))){
            malSol(n, m);
            return;
        }
        cout << n + m - 2 - (1 - (m % 2)) << endl;
    }
    else {
        if(max(n + (m + 1) / 2 - 1, m + (n + 1) / 2 - 1) > m - 1 - (1 - (m % 2)) + n - 2 ){
            malSol(n, m);
            return;
        }
        cout << m - 1 - (1 - (m % 2)) + n - 2 << endl;
    }
    vector<vector<char>> vec(n);
    for (int i = 0; i < m; i++) vec[0].push_back('-');
    if(n % 2 == 0) for(int i = 0; i < m; i++) vec[1].push_back('-');
    //cout << endl;
    for (int i = 1 + (1 - (n % 2)); i < n; i++) {
        if (i % 2) {
            for (int j = 1; j <= m / 2 + 1; j++) vec[i].push_back('+');
            for (int j = m / 2 + 2; j <= m; j++) vec[i].push_back('-');
        }
        else {
            for (int j = m / 2 + 2; j <= m; j++) vec[i].push_back('-');
            for (int j = 1; j <= m / 2 + 1; j++) vec[i].push_back('+');
        }
        //cout << endl;
    }
    //if ((n % 2 == 0 && calc(vec) != n - 1 + (m + 1) / 2 - 1) || (n %  2 && calc(vec) != n + m - 2 - (1 - (m % 2))))
    {
        //cout << calc(vec) << endl;
        for (int i = 0; i < vec.size(); i++) {
            for (int j = 0; j < vec[i].size(); j++) {
                cout << vec[i][j];
            }
            cout << endl;
        }
    }
    /*
        ----------------------------
        +++++++++++++++-------------
        -------------+++++++++++++++
        +++++++++++++++-------------
        -------------+++++++++++++++



    */
}

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

Compilation message

stones.cpp: In function 'int calc(std::vector<std::vector<char> >&)':
stones.cpp:8:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |     for (int i = 0; i < v.size(); i++) {
      |                     ~~^~~~~~~~~~
stones.cpp:10:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |         for (int j = 0; j < v[i].size(); j++) {
      |                         ~~^~~~~~~~~~~~~
stones.cpp:13:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |         if (c > v[i].size() / 2) cnt++;
      |             ~~^~~~~~~~~~~~~~~~~
stones.cpp:15:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     for (int j = 0; j < v[0].size(); j++) {
      |                     ~~^~~~~~~~~~~~~
stones.cpp:17:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |         for (int i = 0; i < v.size(); i++) {
      |                         ~~^~~~~~~~~~
stones.cpp:22:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |         if (c > v.size() / 2) cnt++;
      |             ~~^~~~~~~~~~~~~~
stones.cpp: In function 'void solve()':
stones.cpp:88:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |         for (int i = 0; i < vec.size(); i++) {
      |                         ~~^~~~~~~~~~~~
stones.cpp:89:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |             for (int j = 0; j < vec[i].size(); j++) {
      |                             ~~^~~~~~~~~~~~~~~
# 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 372 KB Wrong answer in test 38 5: 40 < 41
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 66 ms 1324 KB Output is correct
2 Correct 25 ms 1740 KB Output is correct
3 Correct 39 ms 2072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 42 ms 1324 KB Wrong answer in test 6 6: 8 < 9
2 Halted 0 ms 0 KB -
# 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 372 KB Wrong answer in test 38 5: 40 < 41
5 Halted 0 ms 0 KB -