Submission #170763

# Submission time Handle Problem Language Result Execution time Memory
170763 2019-12-26T09:49:08 Z DanGolov Red-blue table (IZhO19_stones) C++17
27 / 100
48 ms 1524 KB
#include <iostream>
#include <vector>

using namespace std;

namespace Solution {

    int n, m;
    char field[1013][1013];

    int countAns() {
        vector<int> rows (n, 0), columns (m, 0);
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (field[i][j] == '+') {
                    rows[i]++, columns[j]++;
                } else {
                    rows[i]--, columns[j]--;
                }
            }
        }
        int res = 0;
        for (int i = 0; i < n; i++) {
            if (rows[i] > 0) ++res;
        }
        for (int i = 0; i < m; i++) {
            if (columns[i] < 0) ++res;
        }
        return res;
    }

    void solve() {
        cin >> n >> m;
        int ans = max(n + m / 2 - (m % 2 == 0), m + n / 2 - (n % 2 == 0));
        if (ans == n + m / 2 - (m % 2 == 0)) {
            for (int i = 0; i < n; i++) fill(field[i], field[i] + m, '+');
            for (int i = 0; i < m / 2 - (m % 2 == 0); i++) {
                for (int j = 0; j < n / 2 + 1; j++) {
                    field[(i + j) % n][i] = '-';
                }
            }
        } else {
            for (int i = 0; i < n; i++) fill(field[i], field[i] + m, '-');
            for (int i = 0; i < n / 2 - (n % 2 == 0); i++) {
                for (int j = 0; j < m / 2 + 1; j++) {
                    field[i][(i + j) % m] = '+';
                }
            }
        }
        cout << countAns() << '\n';
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                cout << field[i][j];
            }
            cout << '\n';
        }
    }

}


int main() {
    int t;
    cin >> t;
    while (t--) {
        Solution::solve();
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 4 ms 376 KB Output is correct
4 Incorrect 6 ms 376 KB Wrong answer in test 5 29: 31 < 32
# Verdict Execution time Memory Grader output
1 Incorrect 48 ms 1388 KB Wrong answer in test 97 21: 107 < 116
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 46 ms 1524 KB Wrong answer in test 24 24: 35 < 44
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 4 ms 376 KB Output is correct
4 Incorrect 6 ms 376 KB Wrong answer in test 5 29: 31 < 32