Submission #954640

# Submission time Handle Problem Language Result Execution time Memory
954640 2024-03-28T09:20:27 Z atom Red-blue table (IZhO19_stones) C++17
27 / 100
44 ms 600 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;

    	if (n <= 4 && m <= 4) {
    		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;
		    	}

		    	// debug(A, B, msk);
		    	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 = i / m;
					int c = i % 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";
	    	}
	    	continue;
	    }

	    // sub2
	    if (n <= 5 || m <= 5) {

	    	int op1 = m + (n + 1) / 2;
	    	int op2 = n + (m + 1) / 2; 
	    	if (op2 <= op1) {
	    		int r = n / 2;
	    		if (n % 2 == 0) --r;
	    		cout << (m + r) << "\n";
	    		for (int i = 1; i <= r; ++i) {
	    			for (int j = 1; j <= m; ++j)
	    				cout << "+";
	    			cout << "\n";
	    		}

	    		for (int i = r + 1; i <= n; ++i) {
	    			for (int j = 1; j <= m; ++j)
	    				cout << "-";
	    			cout << "\n";
	    		}
	    		continue;
	    	}

	    	if (op1 <= op2) {
	    		int c = m / 2;
	    		if (m % 2 == 0) --c;
	    		cout << (n + c) << "\n";
	    		for (int i = 1; i <= n; ++i) {
	    			for (int j = 1; j <= m; ++j) {
	    				cout << (j <= c? "-" : "+");
	    			}
	    			cout << "\n";
	    		}
	    		continue;
	    	}
	    }



    }
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 448 KB Output is correct
2 Correct 22 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 448 KB Output is correct
2 Correct 22 ms 344 KB Output is correct
3 Correct 3 ms 348 KB Output is correct
4 Incorrect 44 ms 600 KB Wrong answer in test 5 29: 31 < 32
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Wrong answer
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 460 KB Wrong answer
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 448 KB Output is correct
2 Correct 22 ms 344 KB Output is correct
3 Correct 3 ms 348 KB Output is correct
4 Incorrect 44 ms 600 KB Wrong answer in test 5 29: 31 < 32
5 Halted 0 ms 0 KB -