답안 #525314

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
525314 2022-02-11T09:51:17 Z Magi Red-blue table (IZhO19_stones) C++14
100 / 100
28 ms 2392 KB
#include <iostream>
#define NMAX 1000

using namespace std;

char a[NMAX+10][NMAX+10];

void solve(){

	int n, m;
	cin >> n >> m;

	int badColumns = 0;
	int ans = max(n, m), p = 0;
	if(n > m)
		p = n;

	for(int i=1; i<=n; i++){
		int cnt = (m / 2 + 1) * i;
		if(cnt > (m - badColumns) * (((n + 1) / 2) - 1) + badColumns * i){
			if(badColumns == m)
				break;
			i--;
			badColumns++;
			continue;
		}
		if(i + (m - badColumns) > ans){
			ans = i + (m - badColumns);
			p = i;
		}
	}

	badColumns = 0;
	while(1){
		int cnt = (m / 2 + 1) * p;
		if(cnt > (m - badColumns) * (((n + 1) / 2) - 1) + badColumns * p){
			badColumns++;
			continue;
		}
		for(int j=1; j<=m; j++)
			for(int i=1; i<=n; i++){
				if(j <= badColumns)
					a[i][j] = '+';
				else
					a[i][j] = '-';
			}

		int j = badColumns + 1;	
		for(int i=1; i<=p; i++)
			for(int nr=1; nr<=m/2+1-badColumns; nr++){
				a[i][j] = '+';
				j++;
				if(j == m + 1)
					j = badColumns + 1;
			}

		cout << ans << '\n';
		for(int i=1; i<=n; i++){
			for(int j=1; j<=m; j++)
				cout << a[i][j];
			cout << '\n';
		}
		break;
	}
}

int main(){

	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int t;
	cin >> t;
	while(t--){
		solve();
	}

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 1368 KB Output is correct
2 Correct 19 ms 1932 KB Output is correct
3 Correct 25 ms 2100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 1328 KB Output is correct
2 Correct 18 ms 1748 KB Output is correct
3 Correct 16 ms 1588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 25 ms 1368 KB Output is correct
6 Correct 19 ms 1932 KB Output is correct
7 Correct 25 ms 2100 KB Output is correct
8 Correct 21 ms 1328 KB Output is correct
9 Correct 18 ms 1748 KB Output is correct
10 Correct 16 ms 1588 KB Output is correct
11 Correct 6 ms 588 KB Output is correct
12 Correct 16 ms 1808 KB Output is correct
13 Correct 21 ms 1956 KB Output is correct
14 Correct 15 ms 1640 KB Output is correct
15 Correct 28 ms 2392 KB Output is correct
16 Correct 16 ms 1736 KB Output is correct
17 Correct 10 ms 1248 KB Output is correct