Submission #216666

# Submission time Handle Problem Language Result Execution time Memory
216666 2020-03-27T19:08:02 Z eggag32 Red-blue table (IZhO19_stones) C++17
27 / 100
153 ms 1404 KB
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

bool cmp(pi a, pi b){
	return a.fi > b.fi;
}

void solve(){
	int n, m;
	cin >> n >> m;
	int ans = n; //do the rows
	char res[n + 1][m + 1];
	rep(i, n) rep(j, m) res[i][j] = '+';
	priority_queue<pi, vector<pi>, function<bool(pi, pi)>> pq(cmp);
	rep(i, n) if(((m - 1) / 2) > 0) pq.push(mp((m - 1) / 2, i));
	rep(j, m){
		int need = (n + 2) / 2; //how many need to be changed
		vector<pi> add;
		while(need && pq.size()){
			pi cur = pq.top();
			pq.pop();
			need--;
			res[cur.se][j] = '-';
			add.pb(mp(cur.fi - 1, cur.se));
		}
		if(need) break;
		else ans++;
		rep(i, add.size()) if(add[i].fi) pq.push(add[i]);
	}
	int ans1 = m;
	priority_queue<pi, vector<pi>, function<bool(pi, pi)>> pq1(cmp);
	rep(i, m) if(((n - 1) / 2) > 0) pq1.push(mp((n - 1) / 2, i));
	char res1[n + 1][m + 1];
	rep(i, n) rep(j, m) res1[i][j] = '-';
	rep(i, n){
		int need = (m + 2) / 2; //how many need to be changed
		vector<pi> add;
		while(need && pq1.size()){
			pi cur = pq1.top();
			pq1.pop();
			need--;
			res1[i][cur.se] = '+';
			add.pb(mp(cur.fi - 1, cur.se));
		}
		if(need) break;
		else ans1++;
		rep(i, add.size()) if(add[i].fi) pq1.push(add[i]);
	}
	if(ans > ans1){
		cout << ans << endl;
		rep(i, n){
			rep(j, m) cout << res[i][j];
			cout << endl;
		}
	}
	else{
		cout << ans1 << endl;
		rep(i, n){
			rep(j, m) cout << res1[i][j];
			cout << endl;
		}
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int t;
	cin >> t;
	while(t--) solve();
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 14 ms 384 KB Output is correct
4 Incorrect 23 ms 384 KB Wrong answer in test 5 29: 31 < 32
# Verdict Execution time Memory Grader output
1 Incorrect 153 ms 1404 KB Wrong answer in test 97 21: 107 < 116
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 129 ms 1400 KB Wrong answer in test 24 24: 35 < 44
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 14 ms 384 KB Output is correct
4 Incorrect 23 ms 384 KB Wrong answer in test 5 29: 31 < 32