답안 #200169

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
200169 2020-02-05T15:34:06 Z a1_N Red-blue table (IZhO19_stones) C++14
100 / 100
91 ms 2296 KB
#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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 248 KB Output is correct
3 Correct 14 ms 376 KB Output is correct
4 Correct 22 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 91 ms 1528 KB Output is correct
2 Correct 48 ms 1948 KB Output is correct
3 Correct 50 ms 2168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 70 ms 1528 KB Output is correct
2 Correct 44 ms 1916 KB Output is correct
3 Correct 40 ms 1656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 248 KB Output is correct
3 Correct 14 ms 376 KB Output is correct
4 Correct 22 ms 376 KB Output is correct
5 Correct 91 ms 1528 KB Output is correct
6 Correct 48 ms 1948 KB Output is correct
7 Correct 50 ms 2168 KB Output is correct
8 Correct 70 ms 1528 KB Output is correct
9 Correct 44 ms 1916 KB Output is correct
10 Correct 40 ms 1656 KB Output is correct
11 Correct 44 ms 636 KB Output is correct
12 Correct 43 ms 1908 KB Output is correct
13 Correct 47 ms 2040 KB Output is correct
14 Correct 48 ms 1784 KB Output is correct
15 Correct 52 ms 2296 KB Output is correct
16 Correct 38 ms 1912 KB Output is correct
17 Correct 22 ms 1400 KB Output is correct