답안 #1090093

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1090093 2024-09-17T17:37:33 Z PieArmy Red-blue table (IZhO19_stones) C++17
100 / 100
20 ms 5212 KB
typedef long long ll;
ll pie(ll army){return (1ll<<army);}
#include <bits/stdc++.h>
#define fr first
#define sc second
#define pb push_back
#define endl '\n'
#define mid ((left+right)>>1)
const ll inf=2000000000000000005;
const int sonsuz=2000000005;
using namespace std;
ll fpow(ll x,ll y,ll m=0){if(y<0){cout<<"powError";return -1;}if(m)x%=m;ll res=1;while(y>0){if(y&1)res*=x;x*=x;if(m){x%=m;res%=m;}y>>=1;}return res;}

void code(){
	bool b=false;
	int n,m;cin>>n>>m;
	if(n>m){
		b=true;
		swap(n,m);
	}
	int table[n][m];
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			table[i][j]=0;
		}
	}
	int bas=0;
	int k=(m/2)+1;
	for(int i=0;i<n;i++){
		for(int j=bas;j<bas+k;j++){
			table[i][j%m]=1;
		}
		bas+=k;
	}
	for(int j=0;j<m;j++){
		int say=0;
		for(int i=0;i<n;i++){
			say+=table[i][j];
			if(say>=(n+1)/2){
				table[i][j]=0;
			}
		}
	}
	int ans=m;
	for(int i=0;i<n;i++){
		int say=0;
		for(int j=0;j<m;j++){
			say+=table[i][j];
		}
		if(say>m/2){
			ans++;
		}
	}
	cout<<ans<<endl;
	if(b){
		swap(n,m);
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			int x;
			if(b){
				x=table[j][i];
			}
			else x=table[i][j];
			if(x!=b){
				cout<<'+';
			}
			else cout<<'-';
		}
		cout<<endl;
	}
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	bool usaco=0;if(usaco){freopen(".in","r",stdin);freopen(".out","w",stdout);}
	int t=0;
	if(!t)cin>>t;
	while(t--){code();}
	return 0;
}

Compilation message

stones.cpp: In function 'int main()':
stones.cpp:76:32: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |  bool usaco=0;if(usaco){freopen(".in","r",stdin);freopen(".out","w",stdout);}
      |                         ~~~~~~~^~~~~~~~~~~~~~~~~
stones.cpp:76:57: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |  bool usaco=0;if(usaco){freopen(".in","r",stdin);freopen(".out","w",stdout);}
      |                                                  ~~~~~~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 1416 KB Output is correct
2 Correct 19 ms 3920 KB Output is correct
3 Correct 18 ms 3928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 1368 KB Output is correct
2 Correct 17 ms 3164 KB Output is correct
3 Correct 15 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 19 ms 1416 KB Output is correct
6 Correct 19 ms 3920 KB Output is correct
7 Correct 18 ms 3928 KB Output is correct
8 Correct 20 ms 1368 KB Output is correct
9 Correct 17 ms 3164 KB Output is correct
10 Correct 15 ms 2392 KB Output is correct
11 Correct 5 ms 600 KB Output is correct
12 Correct 16 ms 2828 KB Output is correct
13 Correct 16 ms 2396 KB Output is correct
14 Correct 12 ms 1624 KB Output is correct
15 Correct 20 ms 5212 KB Output is correct
16 Correct 15 ms 3928 KB Output is correct
17 Correct 7 ms 1884 KB Output is correct