답안 #169138

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
169138 2019-12-18T15:07:28 Z Nodir_Bobiev Red-blue table (IZhO19_stones) C++14
100 / 100
83 ms 2296 KB
# include <bits/stdc++.h>
# define FILE
using namespace std;

int main(){

	# ifdef FILEs
		freopen( "input.txt", "r", stdin );
		freopen( "output.txt", "w", stdout );
	# endif
	ios_base::sync_with_stdio( false );
	int t;
	cin >> t;
	while( t -- ){
		int n, m;
		cin >> n >> m;
		char a[n][m];
		int ans = 0;
		if( n < m ){

			ans = m ;
			for( int i = 0; i < n; i ++ ){
				for( int j = 0; j < m; j ++ ){
					a[i][j] = '-';
				}
			}

			int cnt[m] = {}, mn = 0, cnt1 = m;

			for( int i = 0; i < n; i ++ ){
				int q1 = m/2+1;
				for( int j = 0; j < m; j ++ ){
					if( mn == (n-1)/2 ){
						mn = -1;
						break;
					}
					if( !q1 )break;
					if( cnt[j] == mn ){
						a[i][j] = '+';
						cnt[j] ++;
						cnt1--;
						q1--;
						if( !cnt1 ){
							cnt1 = m;
							mn++;
						}
					}
				}
				for( int j = 0; j < m; j ++ ){
					if( mn == (n-1)/2 ){
						mn = -1;
						break;
					}
					if( !q1 )break;
					if( cnt[j] == mn ){
						a[i][j] = '+';
						cnt[j] ++;
						cnt1--;
						q1--;
						if( !cnt1 ){
							cnt1 = m;
							mn++;	
						}
					}
				}
				if( q1 == 0 )
					ans ++;
				if( mn == -1 )
					break;
			}
		}
		else{

			ans = n ;
			for( int i = 0; i < n;  i++ ){
				for( int j = 0; j < m; j ++ ){
					a[i][j] = '+';
				}
			}

			int cnt[n] = {}, mn = 0, cnt1 = n;

			for( int j = 0; j < m; j ++ ){
				int q1 = n/2+1;
				for( int i = 0; i < n; i ++ ){
					if( mn == (m-1)/2 ){
						mn = -1;
						break;
					}
					if( !q1 )break;
					if( cnt[i] == mn ){
						a[i][j] = '-';
						cnt[i]++;
						cnt1--;
						q1--;
						if( !cnt1 ){
							cnt1 = n;
							mn++;
						}
					}
				}
				for( int i = 0; i < n; i ++ ){
					if( mn == (m-1)/2 ){
						mn = -1;
						break;
					}
					if( !q1 )break;
					if( cnt[i] == mn ){
						a[i][j] = '-';
						cnt[i]++;
						cnt1--;
						q1--;
						if( !cnt1 ){
							cnt1 = n;
							mn++;
						}
					}
				}
				if( q1 == 0 )
					ans ++;
				if( mn == -1 )
					break;
			}
		}

		cout << ans << endl;
		for( int i = 0; i < n; i ++ ){
			for( int j = 0; j < m; j ++ ){
				cout << a[i][j];
			}cout << endl;
		}

	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 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 14 ms 376 KB Output is correct
4 Correct 23 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 1372 KB Output is correct
2 Correct 32 ms 1884 KB Output is correct
3 Correct 34 ms 1912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 1400 KB Output is correct
2 Correct 31 ms 1656 KB Output is correct
3 Correct 30 ms 1400 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 14 ms 376 KB Output is correct
4 Correct 23 ms 376 KB Output is correct
5 Correct 83 ms 1372 KB Output is correct
6 Correct 32 ms 1884 KB Output is correct
7 Correct 34 ms 1912 KB Output is correct
8 Correct 57 ms 1400 KB Output is correct
9 Correct 31 ms 1656 KB Output is correct
10 Correct 30 ms 1400 KB Output is correct
11 Correct 48 ms 632 KB Output is correct
12 Correct 34 ms 1588 KB Output is correct
13 Correct 36 ms 1400 KB Output is correct
14 Correct 26 ms 1188 KB Output is correct
15 Correct 37 ms 2296 KB Output is correct
16 Correct 26 ms 1784 KB Output is correct
17 Correct 16 ms 1016 KB Output is correct