Submission #334525

# Submission time Handle Problem Language Result Execution time Memory
334525 2020-12-09T10:11:47 Z Gurban Red-blue table (IZhO19_stones) C++17
11 / 100
44 ms 3180 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

const int maxn=1e3+5;
int tt;
int n,m,jog,st,num,num1,nw,nw1;
char c[maxn][maxn],p[maxn][maxn];

int cnt(){
	int jg = 0;
	for(int i = 1;i <= n;i++){
		int b = 0,w=0;
		for(int j = 1;j <= m;j++){
			if(c[i][j]=='+') w++;
			else b++;
		}
		if(w > b) jg++;
	}
	for(int i = 1;i <= m;i++){
		int b =0,w=0;
		for(int j = 1;j <= n;j++){
			if(c[j][i]=='-') b++;
			else w++;
		}
		if(b > w) jg++;
	}
	return jg;
}

void f(){

	for(int i = 1;i <= n;i++) for(int j = 1;j <= m;j++) c[i][j]='+';
	for(int i = m;i > num1;i--) for(int j = 1;j <= nw1;j++) c[j][i]='-';
	st = 1; if(m % 2 == 0) st=2;
	for(int i = num1;i > st;i--) for(int j = n;j > nw1;j--) c[j][i]='-';
	for(int i = 1;i <= m;i++) c[nw1][i]='-';
	
	int ps = cnt(); jog = n + num;
	if(ps > jog) return;

	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= num1;j++) c[i][j] = '+';
		for(int j = num1+1;j <= m;j++) c[i][j] = '-';
	}
}

void f1(){

	for(int i = 1;i <= n;i++) for(int j = 1;j <= m;j++) c[i][j]='-';
	for(int i = 1;i < num1;i++) for(int j = nw1+1;j <= n;j++) c[j][i]='+';
	st = 1; if(n % 2 == 0) st = 2;
	for(int i = num1+1;i <= m;i++) for(int j = nw1;j > st;j--) c[j][i]='+';
	for(int i = 1;i <= n;i++) c[num1][i] = '+';

	int ps = cnt(); jog = m + nw;
	if(ps > jog) return;

	for(int i = 1;i <= m;i++){
		for(int j = 1;j <= nw1;j++) c[j][i]='-';
		for(int j=nw1+1;j <= n;j++) c[j][i]='-';
	}
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> tt;
	while(tt--){
		cin >> n >> m;
		num = (m - 1)/2,num1 = m-num;
		nw = (n - 1) / 2,nw1 = n - nw;
		
		f();
		for(int i = 1;i <= n;i++) for(int j = 1;j <= m;j++) p[i][j]=c[i][j];
		int rnow = cnt();
		f1();
		if(rnow > cnt()){
			cout<<rnow<<'\n';
			for(int i = 1;i <= n;i++){
				for(int j = 1;j <= m;j++) cout<<p[i][j];
				cout<<'\n';
			}
		}
		else {
			cout<<cnt()<<'\n';
			for(int i = 1;i <= n;i++){
				for(int j = 1;j <= m;j++) cout<<c[i][j];
				cout<<'\n';
			}
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Wrong answer in test 3 4: 4 < 5
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 492 KB Wrong answer in test 3 6: 6 < 7
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Wrong answer in test 3 4: 4 < 5
# Verdict Execution time Memory Grader output
1 Correct 44 ms 1516 KB Output is correct
2 Correct 38 ms 2668 KB Output is correct
3 Correct 38 ms 3180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 43 ms 1644 KB Wrong answer in test 24 24: 35 < 44
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Wrong answer in test 3 4: 4 < 5