Submission #1093921

# Submission time Handle Problem Language Result Execution time Memory
1093921 2024-09-28T05:17:55 Z Muhammet Red-blue table (IZhO19_stones) C++17
0 / 100
2000 ms 1116 KB
#include <bits/stdc++.h>

using namespace std;

#define sz(s) (int)s.size()
#define ff first
#define ss second
#define ll long long

const int N = 2e3 + 5;
const ll M = 1e9 + 7;

int T, n, m, a[N], b[N][N], k = 0, c[N][N], k1;

void f(int x){
	if(x == n*m+1){
		for(int i = 1; i <= n*m; i++){
			b[(i+m-1)/m][(i % m == 0 ? m : i%m)] = a[i];
		}
		int ans = 0;
		for(int i = 1; i <= n; i++){
			int a1 = 0, b1 = 0;
			for(int j = 1; j <= m; j++){
				if(b[i][j] == 1) a1++;
				else b1++;
			}
			ans += (a1 > b1);
		}
		int ans1 = ans;
		for(int j = 1; j <= m; j++){
			int a1 = 0, b1 = 0;
			for(int i = 1; i <= n; i++){
				if(b[i][j] == 1) a1++;
				else b1++;
			}
			ans += (b1 > a1);
		}
		if(ans >= k){
			k = ans;
			k1 = ans1;
			for(int i = 1; i <= n; i++){
				for(int j = 1; j <= m; j++){
					c[i][j] = b[i][j];
				}
			}
		}
		return;
	}
	for(int i = 0; i < 2; i++){
		a[x] = i;
		f(x+1);
	}
}

int main(){
	ios::sync_with_stdio(false); cin.tie(nullptr);
	cin >> T;
	while(T--){
		cin >> n >> m;
		f(1);
		cout << k << '\n';
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= m; j++){
				cout << (c[i][j] == 1 ? '+' : '-');
			}
			cout << '\n';
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 10 ms 348 KB in the table A+B is not equal to 4
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2075 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 10 ms 348 KB in the table A+B is not equal to 4
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 1116 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2088 ms 604 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 10 ms 348 KB in the table A+B is not equal to 4
3 Halted 0 ms 0 KB -