답안 #837956

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
837956 2023-08-25T21:31:04 Z MODDI Red-blue table (IZhO19_stones) C++14
38 / 100
43 ms 1824 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<long long, long long> pll;
typedef pair<int,int> pii;
typedef vector<long long> vl;
typedef vector<int> vi;
// 3 3
// -++
// +-+
// -++
// wlog N > M
// every row will have N/2+1 red stones
// then make rows
int main(){
	int t;
	cin>>t;
	while(t--){
		int n, m;
		cin>>n>>m;
		int ans = 0;
		char mat[n][m];
		if(n >= m){
			int minus[m];
			memset(minus, 0, sizeof minus);
			for(int i = 0; i < n; i++){
				int need = m/2 + 1;
				for(int j = 0; j < m; j++){
					if(minus[j] < n/2+1 && (m-j-1) >= need){
						minus[j]++;
						mat[i][j] = '-';
					}
					else{
						mat[i][j] = '+';
						need--;
					}
				}
				ans++;
			}
			for(int i = 0; i < m; i++){
				if(minus[i] >= n/2+1)	ans++;
			}
			int to_break = 0, bgain = 0;
			for(int b = 1; b <= n; b++){
				int gain = 0;
				for(int j = 0; j < m; j++){
					if(minus[j] >= n/2+1)	continue;
					if(minus[j] + b >= n/2+1)	gain++;
				}
				if(bgain < gain - b){
					bgain = gain-b;
					to_break = b;
				}
			}
			ans += bgain;
			for(int i = 0; i < to_break; i++){
				for(int j = 0; j < m; j++){
					mat[i][j]='-';
				}
			}
			cout<<ans<<"\n";
			for(int i = 0; i < n; i++){
				for(int j = 0; j < m; j++)
					cout<<mat[i][j];
				cout<<endl;
			}
		}
		else{
			int plus[n];
			memset(plus, 0, sizeof plus);
			for(int j = 0; j < m; j++){
				int need = n/2 + 1;
				for(int i = 0; i < n; i++){
					if(plus[i] < m/2+1 && (n - i - 1) >= need){
						mat[i][j] = '+';
						plus[i]++;
					}
					else{
						mat[i][j] = '-';
						need--;
					}
				}
				ans++;
			}
			for(int i = 0; i < n; i++)
				if(plus[i] >= m / 2 + 1)	ans++;
			
			int to_break = 0, bgain = 0;
			for(int b = 1; b <= m; b++){
				int gain = 0;
				for(int i = 0; i < n; i++){
					if(plus[i] >= m/2+1)	continue;
					else if(plus[i] + b >= m/2+1)	gain++;
				}
				if(bgain < gain-b){
					bgain = gain-b;
					to_break = b;
				}
			}
			ans += bgain;
			for(int j = 0; j < to_break; j++){
				for(int i = 0; i < n; i++)
					mat[i][j] = '+';
			}
			cout<<ans<<"\n";
			for(int i = 0; i < n; i++){
				for(int j = 0; j < m; j++)
					cout<<mat[i][j];
				cout<<endl;
			}
		}
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 5 ms 336 KB Output is correct
4 Incorrect 10 ms 340 KB Wrong answer in test 38 5: 40 < 41
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 1228 KB Output is correct
2 Correct 23 ms 1752 KB Output is correct
3 Correct 22 ms 1824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 33 ms 1236 KB Wrong answer in test 6 6: 8 < 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 5 ms 336 KB Output is correct
4 Incorrect 10 ms 340 KB Wrong answer in test 38 5: 40 < 41
5 Halted 0 ms 0 KB -