답안 #335189

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
335189 2020-12-11T11:57:29 Z Gurban Red-blue table (IZhO19_stones) C++17
27 / 100
37 ms 1900 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

const int maxn=1e3+5;
int tt,ans,ps,need;
int n,m,tr,a[maxn][maxn];
int cnt[maxn],num[maxn];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> tt;
	while(tt--){
		cin >> n >> m;
		tr = 0;
		if(n % 2 == 0) swap(n,m),tr=1;
		for(int i = 1;i <= n;i++) for(int j = 1;j <= m;j++) a[i][j]=1;
		if(min(n,m) <= 2){
			ans = max(n,m);
			for(int i = 1;i <= n;i++) for(int j = 1;j <= m;j++){
				if(n > m) a[i][j]=1;
				else a[i][j]=0;
			}
		}
		else{
			ans = n - 2,ps = m/2+1,need = n/2+1;
			for(int i = n - 1;i <= n;i++) for(int j = 1;j <= m;j++) a[i][j]=0;
			for(int i = 1;i <= m;i++) cnt[i] = 2;
			for(int i = 1;i <= n-2;i++) num[i] = m;
			for(int i = 1;i <= m;i++){
				for(int j = 1;j <= n-2;j++){
					if(cnt[i]==need) break;
					if(num[j] > ps){
						a[j][i] = 0;
						num[j]--,cnt[i]++;
					}
				}
				if(cnt[i]==need) ans++;
			}
		}
		if(ans < n+(m-1)/2){
			tr = 0,ans=n+(m-1)/2;
			for(int i = 1;i <= n;i++){
				for(int j = 1;j <= m/2+1;j++) a[i][j]=1;  
				for(int j = m/2+2;j <= m;j++) a[i][j]=0;
			}
		}
		if(ans < m+(n-1)/2){
			tr = 0,ans=m+(n-1)/2;
			for(int i = 1;i <= m;i++){
				for(int j = 1;j <= n/2+1;j++) a[j][i]=0;
				for(int j = n/2+2;j <= n;j++) a[j][i]=1;
			}
		}
		cout<<ans<<'\n';
		if(tr) swap(n,m);
		for(int i = 1;i <= n;i++){
			for(int j = 1;j <= m;j++){
				char nw = '+';
				if((tr and a[j][i]==1) or (tr==0 and a[i][j]==0)) nw = '-';
				cout<<nw;
			}
			cout<<'\n';
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 620 KB Output is correct
4 Incorrect 3 ms 620 KB Wrong answer
# 결과 실행 시간 메모리 Grader output
1 Incorrect 37 ms 1792 KB Wrong answer in test 97 21: 115 < 116
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 36 ms 1900 KB Wrong answer in test 19 19: 35 < 36
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 620 KB Output is correct
4 Incorrect 3 ms 620 KB Wrong answer