답안 #179791

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
179791 2020-01-08T11:04:12 Z tselmegkh Red-blue table (IZhO19_stones) C++14
100 / 100
55 ms 2296 KB
#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';
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 4 ms 376 KB Output is correct
4 Correct 6 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 1528 KB Output is correct
2 Correct 47 ms 2012 KB Output is correct
3 Correct 46 ms 2052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 1440 KB Output is correct
2 Correct 44 ms 1840 KB Output is correct
3 Correct 39 ms 1688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 4 ms 376 KB Output is correct
4 Correct 6 ms 376 KB Output is correct
5 Correct 51 ms 1528 KB Output is correct
6 Correct 47 ms 2012 KB Output is correct
7 Correct 46 ms 2052 KB Output is correct
8 Correct 55 ms 1440 KB Output is correct
9 Correct 44 ms 1840 KB Output is correct
10 Correct 39 ms 1688 KB Output is correct
11 Correct 16 ms 508 KB Output is correct
12 Correct 44 ms 1848 KB Output is correct
13 Correct 45 ms 2004 KB Output is correct
14 Correct 38 ms 1700 KB Output is correct
15 Correct 55 ms 2296 KB Output is correct
16 Correct 38 ms 1788 KB Output is correct
17 Correct 20 ms 1272 KB Output is correct