Submission #200169

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

int tt,n,m,cur[1005],ans;

char a[1005][1005];

void solve(){
	cin >> n >> m;
	if(n <= m){
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= m; j++){
				a[i][j] = '-';
			}
		}
		ans = m;
		for(int i = 1; i <= n; i++){
			int mn = n;
			for(int j = 1; j <= m; j++){
				mn = min(mn,cur[j]);
			}
			int need = m / 2 + 1;
			if(mn + 1 < (n + 1) / 2){
				for(int j = 1; j <= m; j++){
					if(cur[j] == mn && need > 0){
						a[i][j] = '+';
						cur[j]++;
						need--;
					}
				}
				mn = n;
				for(int j = 1; j <= m; j++){
					mn = min(mn,cur[j]);	
				}
				if(mn + 1 < (n + 1) / 2){
					for(int j = 1; j <= m; j++){
						if(cur[j] == mn && need > 0){
							a[i][j] = '+';
							cur[j]++;
							need--;
						}
					}
				}
			}
			if(need == 0) ans++;
		}
		for(int j = 1; j <= m; j++){
			cur[j] = 0;	
		}
	}
	else{
		ans = n;
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= m; j++){
				a[i][j] = '+';
			}
		}
		for(int j = 1; j <= m; j++){
			int mn = m;
			for(int i = 1; i <= n; i++){
				mn = min(mn,cur[i]);
			}
			int need = n / 2 + 1;
			if(mn + 1 < (m + 1) / 2){
				 for(int i = 1; i <= n; i++){
				 	if(cur[i] == mn && need > 0){
				 		a[i][j] = '-';
				 		cur[i]++;
				 		need--;
				 	}
				 }
				 mn = m;
				 for(int i = 1; i <= n; i++){
				 	mn = min(mn,cur[i]);
				 }
				 if(mn + 1 < (m + 1) / 2){
				 	for(int i = 1; i <= n; i++){
				 		if(cur[i] == mn && need > 0){
				 			a[i][j] = '-';
				 			cur[i]++;
				 			need--;
				 		}
				 	}
				 }
			}
			if(need == 0) ans++; 	
		}
		for(int i = 1; i <= n; i++){
			cur[i] = 0;
		}
	}
	cout << ans << endl;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			cout << a[i][j];
		}
		cout << endl;
	}
	ans = 0;
}

int main(){
    cin >> tt;
    while(tt--){
    	solve();
    }
	return 0;
}
#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...