Submission #652576

# Submission time Handle Problem Language Result Execution time Memory
652576 2022-10-23T08:39:50 Z l3nl3 Red-blue table (IZhO19_stones) C++14
17 / 100
15 ms 212 KB
/* #pragma GCC optimize("O3")
#pragma GCC target ("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops") */

#include <bits/stdc++.h>

#define int long long

using namespace std;

int tc; 

signed main () {
 	ios_base::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	cin >> tc;
	while (tc--) {
		int n, m;
		cin >> n >> m;
		if (n <= 4 && m <= 4) {
			char a[n+1][m+1];
			int k = n*m;
			for (int i = 1; i <= n; i++) {
				for (int j = 1; j <= m; j++) {
					a[i][j] = '.';				
				}
			}
			int mx = -1, mxi = -1;
			for (int mask = 0; mask <= (1 << k); mask++) {
				bool ok = 1;
				for (int i = 0; i < n; i++) {
					for (int j = 0; j < m; j++) {
						if (mask & (1 << (i*m+j))) {
							a[i+1][j+1] = '+';
						} else {
							a[i+1][j+1] = '-';
							ok = 0;
						}
					}
				}
				int cnt = 0;
				for (int i = 1; i <= n; i++) {
					int r = 0, b = 0;
					for (int j = 1; j <= m; j++) {
						if (a[i][j] == '+') {
							r++;
						} else {
							b++;
						}
					}
					if (r > b) cnt++;
				}
				for (int j = 1; j <= m; j++) {
					int r = 0, b = 0;
					for (int i = 1; i <= n; i++) {
						if (a[i][j] == '+') {
							r++;
						} else {
							b++;
						}
					}
					if (r < b) cnt++;					
				}
				if (cnt > mx) {
					mx = cnt;
					mxi = mask;
				}
				for (int i = 1; i <= n; i++) {
					for (int j = 1; j <= m; j++) {
						a[i][j] = '.';				
					}
				}
			}
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < m; j++) {
					if (mxi & (1 << (i*m+j))) {
						a[i+1][j+1] = '+';
					} else {
						a[i+1][j+1] = '-';
					}
				}
			}
			int cnt = 0;
			for (int i = 1; i <= n; i++) {
				int r = 0, b = 0;
				for (int j = 1; j <= m; j++) {
					if (a[i][j] == '+') {
						r++;
					} else {
						b++;
					}
				}
				if (r > b) cnt++;
			}
			for (int j = 1; j <= m; j++) {
				int r = 0, b = 0;
				for (int i = 1; i <= n; i++) {
					if (a[i][j] == '+') {
						r++;
					} else {
						b++;
					}
				}
				if (r < b) cnt++;					
			}
			cout << cnt << '\n';
			for (int i = 1; i <= n; i++) {
				for (int j = 1; j <= m; j++) {
					cout << a[i][j];
				}
				cout << '\n';
			}           				
		}
	}		
}                          	

Compilation message

stones.cpp: In function 'int main()':
stones.cpp:32:10: warning: variable 'ok' set but not used [-Wunused-but-set-variable]
   32 |     bool ok = 1;
      |          ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 15 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 212 KB Wrong answer
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 15 ms 212 KB Output is correct
3 Incorrect 2 ms 212 KB Wrong answer
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Wrong answer
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 212 KB Wrong answer
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 15 ms 212 KB Output is correct
3 Incorrect 2 ms 212 KB Wrong answer
4 Halted 0 ms 0 KB -