Submission #336020

# Submission time Handle Problem Language Result Execution time Memory
336020 2020-12-14T13:40:09 Z amunduzbaev Red-blue table (IZhO19_stones) C++14
100 / 100
82 ms 3308 KB
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define int long long
#define ll long long 
#define ld long double 
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(),x.rend()
#define prc(n) fixed << setprecision(n)
#define fastios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pi acos(-1);
const int inf = 1e9+7;
const int N = 1e3+5;
int n, m, q;
char a[N][N], ans[N][N];
void solve(){
	cin>>n>>m;
	bool sw = 0;
	if(n > m){
		swap(n, m);
		sw = 1;
	}
	if(n == 1 || n == 2){
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				a[i][j] = '-';
			}
		}
		cout<<m<<endl;
	}
	else if(n == 3 || n == 4){
		for(int i=0;i<n-1;i++){
			for(int j=0;j<m;j++){
				a[i][j] = '-';
			}
		}for(int i=0;i<m;i++){
			a[n-1][i] = '+';
		}cout<<1 + m<<endl;
	}else{
		vector<int>cnt(m, 0);
		int j = 0, i = 0, need = m/2 +1, done = 0, cur = 0;
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++) a[i][j] = '-';
		}
		
		while(cnt[j] < (n-1)/2){
			a[i][j] = '+';
			cnt[j]++;
			j++;
			j%=m;
			done++;
			if(done == need) done = 0, i++, cur++;
		}
		
		cout<<cur + m<<endl;
	}
	
	if(sw){
		for(int i=0;i<m;i++){
			for(int j=0;j<n;j++){
				ans[i][j] = a[j][i];
				if(ans[i][j] == '-') ans[i][j] = '+';
				else ans[i][j] = '-';
			}
		}
		swap(n, m);
	}else{
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				ans[i][j] = a[i][j];
			}
		}
	}
	
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cout<<ans[i][j];
		}cout<<endl;
	}
	return;
}

signed main(){
	fastios
	int t = 1;
	cin>>t;
	while(t--) solve();
	return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 12 ms 364 KB Output is correct
4 Correct 18 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 82 ms 1644 KB Output is correct
2 Correct 38 ms 2668 KB Output is correct
3 Correct 36 ms 2924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 63 ms 1644 KB Output is correct
2 Correct 35 ms 2540 KB Output is correct
3 Correct 32 ms 2284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 12 ms 364 KB Output is correct
4 Correct 18 ms 492 KB Output is correct
5 Correct 82 ms 1644 KB Output is correct
6 Correct 38 ms 2668 KB Output is correct
7 Correct 36 ms 2924 KB Output is correct
8 Correct 63 ms 1644 KB Output is correct
9 Correct 35 ms 2540 KB Output is correct
10 Correct 32 ms 2284 KB Output is correct
11 Correct 40 ms 620 KB Output is correct
12 Correct 36 ms 2540 KB Output is correct
13 Correct 38 ms 2540 KB Output is correct
14 Correct 29 ms 2156 KB Output is correct
15 Correct 42 ms 3308 KB Output is correct
16 Correct 30 ms 2668 KB Output is correct
17 Correct 15 ms 1772 KB Output is correct