답안 #954476

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
954476 2024-03-28T03:06:42 Z atom Red-blue table (IZhO19_stones) C++17
0 / 100
2000 ms 464 KB
#include "bits/stdc++.h"
// @JASPER'S BOILERPLATE
using namespace std;
using ll = long long;

#ifdef JASPER
#include "debug.h"
#else
#define debug(...) 166
#endif

signed main() {
    cin.tie(0) -> sync_with_stdio(0);
    
    #ifdef JASPER
        freopen("in1", "r", stdin);
    #endif

    int T; 
    cin >> T;
    while (T--) {
    	int n, m;
    	cin >> n >> m;

    	int sz = (n * m);
    	int opt = -1;
    	int ans = 0;

    	for (int msk = 0; msk < (1 << sz); ++msk) {
    		vector <vector <int>> a(n, vector <int> (m));
    		for (int i = 0; i < sz; ++i) {
    			if (msk & (1 << i)) {
    				int r = i / m;
    				int c = i % m;
    				a[r][c] = 1;
    			}
    		}

    		int A = 0, B = 0;
	    	for (int i = 0; i < n; ++i) {
	    		int r = 0, b = 0;
	    		for (int j = 0; j < m; ++j) {
	    			if (a[i][j]) ++r;
	    			else ++b;
	    		}
	    		if (r > b) ++A;
	    	}

	    	for (int j = 0; j < m; ++j) {
	    		int r = 0, b = 0;
	    		for (int i = 0; i < n; ++i) {
	    			if (a[i][j]) ++r;
	    			else ++b;
	    		}
	    		if (b > r) ++B;
	    	}

	    	if (A + B > ans) {
	    		ans = A + B;
	    		opt = msk;
	    	}
    	}

    	vector <vector <int>> a(n, vector <int> (m));
    	for (int i = 0; i < sz; ++i) {
    		if (opt& (1 << i)) {
    			int r = opt / m;
				int c = opt % m;
				a[r][c] = 1;
    		}
    	}

    	cout << ans << "\n";
    	for (int i = 0; i < n; ++i) {
    		for (int j = 0; j < m; ++j) {
    			cout << (a[i][j]? "+" : "-");
    		}
    		cout << "\n";
    	}
    }
    
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB in the table A+B is not equal to 4
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 613 ms 432 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB in the table A+B is not equal to 4
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2031 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1713 ms 464 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB in the table A+B is not equal to 4
2 Halted 0 ms 0 KB -