답안 #286884

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
286884 2020-08-31T06:16:50 Z dvdg6566 Red-blue table (IZhO19_stones) C++14
100 / 100
39 ms 9208 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector<ll> vi;
typedef vector<pi> vpi;
#define pb emplace_back
#define mp make_pair
#define f first
#define s second
#define SZ(x) (int)x.size()
#define ALL(x) x.begin(),x.end()
#define lb lower_bound
const int MAXN=1001;
const ll MOD=998244353;

ll A[MAXN][MAXN];
ll R,C,T;

int eval(){
	int ans=0;
	for(int i=0;i<R;++i){
		int colp=0;
		for(int j=0;j<C;++j)if(A[i][j]==0)++colp;
		if(colp*2 > C)++ans;
	}
	for(int i=0;i<C;++i){
		int colc=0;
		for(int j=0;j<R;++j)if(A[j][i])++colc;
		if(colc*2>R)++ans;
	}
	return ans;
}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>T;
	while(T--){
		cin>>R>>C;
		
		for(int i=0;i<R;++i)for(int j=0;j<C;++j)A[i][j]=0;
		if(R==1){
			cout<<C<<'\n';
			for(int i=0;i<C;++i)cout<<'-';cout<<'\n';
			continue;
		}else if(C==1){
			cout<<R<<'\n';
			for(int i=0;i<R;++i){cout<<'+';cout<<'\n';}
			continue;
		}
		if(C <= R){
			int perow=(C+1)/2-1;
			int tar= R*((C+1)/2-1);

			tar /= (R/2+1);

			int cur=0;
			for(int i=0;i<R;++i){
				for(int ww=0;ww<perow;++ww){
					A[i][cur] = 1;
					++cur;
					cur%=tar;
				}
			}
		}else{
			int percol=(R+1)/2-1;
			int tar=C*((R+1)/2-1);
			tar /= (C/2+1);
			int cur=0;
			for(int i=0;i<R;++i)for(int j=0;j<C;++j)A[i][j]=1;
			for(int i=0;i<C;++i){
				for(int ww=0;ww<percol;++ww){
					A[cur][i]=0;
					++cur;
					cur%=tar;
				}
			}
		}
		// assert(eval()+4>=R+C);
		cout<<eval()<<'\n';
		// break;
		for(int i=0;i<R;++i){
			for(int j=0;j<C;++j){
				if(A[i][j])cout<<'-';
				else cout<<'+';
			}
			cout<<'\n';
		}
		// return 0;
	}	
}

Compilation message

stones.cpp: In function 'int main()':
stones.cpp:44:4: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   44 |    for(int i=0;i<C;++i)cout<<'-';cout<<'\n';
      |    ^~~
stones.cpp:44:34: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   44 |    for(int i=0;i<C;++i)cout<<'-';cout<<'\n';
      |                                  ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 4 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 1792 KB Output is correct
2 Correct 36 ms 7160 KB Output is correct
3 Correct 36 ms 8696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 2040 KB Output is correct
2 Correct 33 ms 6776 KB Output is correct
3 Correct 29 ms 5624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 4 ms 640 KB Output is correct
5 Correct 37 ms 1792 KB Output is correct
6 Correct 36 ms 7160 KB Output is correct
7 Correct 36 ms 8696 KB Output is correct
8 Correct 36 ms 2040 KB Output is correct
9 Correct 33 ms 6776 KB Output is correct
10 Correct 29 ms 5624 KB Output is correct
11 Correct 9 ms 640 KB Output is correct
12 Correct 31 ms 7416 KB Output is correct
13 Correct 33 ms 7680 KB Output is correct
14 Correct 25 ms 6008 KB Output is correct
15 Correct 39 ms 9208 KB Output is correct
16 Correct 30 ms 7292 KB Output is correct
17 Correct 14 ms 5888 KB Output is correct