Submission #179791

#TimeUsernameProblemLanguageResultExecution timeMemory
179791tselmegkhRed-blue table (IZhO19_stones)C++14
100 / 100
55 ms2296 KiB
#include<bits/stdc++.h>
using namespace std;

int cnt[1005];
char ans[1005][1005];

int go1(int n, int m){
	memset(cnt, 0, sizeof cnt);
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			ans[i][j] = '-';
			cnt[j] = n;
		}
	}

	int l = 1, tot = m;

	for(int i = 1; i <= n; i++){
		int need = m / 2 + 1, cur = l;
		while(need > 0){
			if(cnt[cur] > n / 2 + 1){
				cnt[cur]--;
				need--;
				ans[i][cur] = '+';
			}
			cur++;
			if(cur > m)cur -= m;
			if(cur == l)break;
		}
		if(need == 0){
			tot++;
			l = cur;
		}else break;
	}
	return tot;
}
int go2(int n, int m){
	memset(cnt, 0, sizeof cnt);
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			ans[i][j] = '+';
		}
		cnt[i] = m;
	}

	int l = 1, tot = n;

	for(int j = 1; j <= m; j++){
		int need = n / 2 + 1, cur = l;
		while(need > 0){
			if(cnt[cur] > m / 2 + 1){
				cnt[cur]--;
				need--;
				ans[cur][j] = '-';
			}
			cur++;
			if(cur > n)cur -= n;
			if(cur == l)break;
		}
		if(need == 0){
			tot++;
			l = cur;
		}else break;
	}
	return tot;
}
int main(){
	int t;
	cin >> t;
	while(t--){
		int n, m;
		cin >> n >> m;
		if(go1(n, m) > go2(n, m)){
			cout << go1(n, m) << '\n';
		}else{
			cout << go2(n, m) << '\n';
		}
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= m; j++){
				cout << ans[i][j];
			}
			cout << '\n';
		}
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...