Submission #599028

# Submission time Handle Problem Language Result Execution time Memory
599028 2022-07-19T09:16:59 Z Jomnoi Red-blue table (IZhO19_stones) C++17
15 / 100
57 ms 3916 KB
#include <bits/stdc++.h>
using namespace std;

const int MAX_N = 1005;

int cnt1[MAX_N];
int b[MAX_N][MAX_N];

void solve(int N, int M) {
    bool is_swap = false;
    if(N < M) {
        is_swap = true;
        swap(N, M);
    }

    for(int i = 0; i < N; i++) {
        for(int j = 0; j < M; j++) {
            b[i][j] = 1;
        }
        cnt1[i] = M;
    }

    int A = N, maxab = N, to = -1;
    for(int j = 0; j < M; j++) {
        priority_queue <pair <int, int>> pq;
        for(int i = 0; i < N; i++) {
            pq.emplace(cnt1[i], i);
        }

        int cnt = N / 2 + 1;
        while(cnt--) {
            auto [cn, i] = pq.top();
            pq.pop();

            if(cnt1[i]-- == M / 2 + 1) {
                A--;
            }

            b[i][j] = 0;
        }

        if(maxab < A + j + 1) {
            maxab = A + j + 1;
            to = j;
        }
    }

    cout << maxab << '\n';
    if(is_swap == false) {
        for(int i = 0; i < N; i++) {
            for(int j = 0; j < M; j++) {
                if(j <= to) {
                    cout << (b[i][j] == 1 ? '+' : '-');
                }
                else {
                    cout << '+';
                }
            }
            cout << '\n';
        }
    }
    else {
        for(int j = 0; j < M; j++) {
            for(int i = 0; i < N; i++) {
                if(i <= to) {
                    cout << (b[j][i] == 1 ? '-' : '+');
                }
                else {
                    cout << '-';
                }
            }
            cout << '\n';
        }
    }
}

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    int T;
    cin >> T;
    
    while(T--) {
        int N, M;
        cin >> N >> M;

        solve(N, M);
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 340 KB in the table A+B is not equal to 5
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 468 KB in the table A+B is not equal to 46
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 340 KB in the table A+B is not equal to 5
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 53 ms 1628 KB in the table A+B is not equal to 78
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 57 ms 1852 KB Output is correct
2 Correct 49 ms 3916 KB Output is correct
3 Correct 45 ms 3276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 340 KB in the table A+B is not equal to 5
3 Halted 0 ms 0 KB -