Submission #376609

# Submission time Handle Problem Language Result Execution time Memory
376609 2021-03-11T19:47:16 Z ijxjdjd Red-blue table (IZhO19_stones) C++14
0 / 100
2000 ms 388 KB
#include <bits/stdc++.h>
#define FR(i, N) for (int i = 0; i < int(N); i++)
#define all(x) begin(x), end(x)

using namespace std;

using ll = long long;

int conv(int i) {
    if (i%2 == 0) {
        return (i-2);
    }
    else {
        return i-1;
    }
}
int brute(int N, int M) {
    int mx = 0;
    for (int b = 0; b < (1<<(N*M)); b++) {
        int cnt = 0;
        for (int k = 0; k < N; k++) {
            int R = 0, B = 0;
            for (int j = 0; j < M; j++) {
                if (b&(1<<(k*M + j))) {
                    R++;
                }
                else {
                    B++;
                }
            }
            if (R > B) {
                cnt++;
            }
        }
        for (int k = 0; k < M; k++) {
            int R = 0, B = 0;
            for (int j = 0; j < N; j++) {
                if (b&(1<<(j*M + k))) {
                    R++;
                }
                else {
                    B++;
                }
            }
            if (R < B) {
                cnt++;
            }
        }
//        if (cnt > mx) {
//            cout << cnt << ": " << bitset<16>(b) << '\n';
//        }
        mx = max(mx, cnt);
    }
    return mx;
}
int main() {
	cin.tie(0);
	cin.sync_with_stdio(0);
	int T;
	cin >> T;
	while (T-->0) {
        int N, M;
        cin >> N >> M;
        cout << "Ans: " << brute(N, M) << '\n';
        char board[N][M];
        if (max(N, M) + (min(N, M)-1)/2 >= conv(N)+conv(M)) {
            for (int i = 0; i < N; i++) {
                for (int j = 0; j < M; j++) {
                    board[i][j] = (N >= M ? '+' : '-');
                }
            }
            if (N >= M) {
                for (int i = 0; i < N; i++) {
                    for (int j = 0; j < (M-1)/2; j++) {
                        board[i][j]='-';
                    }
                }
            }
            else {
                for (int i = 0; i < (N-1)/2; i++) {
                    for (int j = 0; j < M; j++) {
                        board[i][j] = '+';
                    }
                }
            }
        }
        else {
            for (int i = conv(N); i < N; i++) {
                for (int j = 0; j < M; j++) {
                    board[i][j] = '-';
                }
            }
            for (int j = conv(M); j < M; j++) {
                for (int i = 0; i < N; i++) {
                    board[i][j] = '+';
                }
            }
            for (int i = 0; i < conv(N); i++) {
                for (int j = 0; j < conv(M); j++) {
                    board[i][j] = ((i + j)%2 ? '+' : '-');
                }
            }
        }
        cout << max(max(N, M) + (min(N, M)-1)/2, conv(N) + conv(M)) << '\n';
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < M; j++) {
                cout << board[i][j];
            }
            cout << '\n';
        }
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Expected integer, but "Ans:" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2085 ms 364 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Expected integer, but "Ans:" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2076 ms 364 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2079 ms 388 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Expected integer, but "Ans:" found
2 Halted 0 ms 0 KB -