Submission #598987

# Submission time Handle Problem Language Result Execution time Memory
598987 2022-07-19T08:41:45 Z Jomnoi Red-blue table (IZhO19_stones) C++17
17 / 100
24 ms 1364 KB
#include <bits/stdc++.h>
using namespace std;

const int MAX_N = 1005;

int a[MAX_N][MAX_N], b[MAX_N][MAX_N];

void solve(int N, int M) {
    int ans = 0;
    if(N <= 4 and M <= 4) {
        for(int mask = 0; mask < (1<<(N * M)); mask++) {
            int sum = 0;
            for(int i = 0; i < N; i++) {
                for(int j = 0; j < M; j++) {
                    if(mask & (1<<(i * M + j))) {
                        a[i][j] = 1;
                    }
                    else {
                        a[i][j] = 0;
                    }
                }
            }

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

                sum += (cnt1 > M - cnt1);
            }
            for(int j = 0; j < M; j++) {
                int cnt1 = 0;
                for(int i = 0; i < N; i++) {
                    cnt1 += a[i][j];
                }

                sum += (N - cnt1 > cnt1);
            }

            if(ans < sum) {
                ans = sum;
                for(int i = 0; i < N; i++) {
                    for(int j = 0; j < M; j++) {
                        b[i][j] = a[i][j];
                    }
                }
            }
        }
    }
    else {
        // do nothing
    }

    cout << ans << '\n';
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < M; j++) {
            if(b[i][j] == 1) {
                cout << '+';
            }
            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 1 ms 340 KB Output is correct
2 Correct 4 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 332 KB in the table A+B is not equal to 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 4 ms 328 KB Output is correct
3 Incorrect 2 ms 332 KB in the table A+B is not equal to 0
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 1344 KB in the table A+B is not equal to 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 1364 KB in the table A+B is not equal to 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 4 ms 328 KB Output is correct
3 Incorrect 2 ms 332 KB in the table A+B is not equal to 0
4 Halted 0 ms 0 KB -