Submission #466979

# Submission time Handle Problem Language Result Execution time Memory
466979 2021-08-21T06:55:14 Z hhhhaura Red-blue table (IZhO19_stones) C++14
100 / 100
97 ms 5172 KB
#define wiwihorz
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma loop-opt(on)

#define rep(i, a, b) for(int i = a; i <= b; i ++)
#define rrep(i, a, b) for(int i = b; i >= a; i--)
#define all(x) x.begin(), x.end()
#define ceil(a, b) ((a + b - 1) / (b))

using namespace std;
#define pii pair<int, int>

namespace solver {
	int n, m, inv;
	priority_queue<pii,vector<pii>, greater<pii>> pq;
	vector<vector<int>> a;
	void init_(int _n, int _m) {
		n = _n, m = _m, inv = 0 ;
		if(n > m) swap(n, m), inv = 1;
		while(pq.size()) pq.pop();
		a.assign(n + 1, vector<int>(m + 1, 0));
	}
	void solve() {
		int mxn = n - n / 2 - 1, mxm = m / 2 + 1;
		int ans = m;
		rep(i, 1, m) pq.push({0, i});
		rep(i, 1, n) {
			bool done = 0;
			rep(j, 1, mxm) {
				pii p = pq.top(); pq.pop();
				if(p.first == mxn) {
					done = 1;
					break;
				}
				p.first ++; 
				a[i][p.second] = 1;
				pq.push(p);
			}
			if(done) break;
			else ans ++;
		}
		cout << ans << "\n";
		if(inv) rep(i, 1, m) rep(j, 1, n) 
			cout << (a[j][i] ? "-" : "+") << (j == n ? "\n" : "");			
		else rep(i, 1, n) rep(j, 1, m) 
			cout << (a[i][j] ? "+" : "-") << (j == m ? "\n" : "");	
	}

};
using namespace solver;
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	int t; cin >> t;
	while(t--) {
		int n, m;
		cin >> n >> m;
		init_(n, m);
		solve();
	}
	return 0;
}  

Compilation message

stones.cpp:4: warning: ignoring '#pragma loop ' [-Wunknown-pragmas]
    4 | #pragma loop-opt(on)
      |
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 5 ms 360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 97 ms 1404 KB Output is correct
2 Correct 83 ms 3828 KB Output is correct
3 Correct 78 ms 4164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 87 ms 1468 KB Output is correct
2 Correct 78 ms 3320 KB Output is correct
3 Correct 82 ms 3268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 5 ms 360 KB Output is correct
5 Correct 97 ms 1404 KB Output is correct
6 Correct 83 ms 3828 KB Output is correct
7 Correct 78 ms 4164 KB Output is correct
8 Correct 87 ms 1468 KB Output is correct
9 Correct 78 ms 3320 KB Output is correct
10 Correct 82 ms 3268 KB Output is correct
11 Correct 19 ms 460 KB Output is correct
12 Correct 72 ms 2876 KB Output is correct
13 Correct 80 ms 2908 KB Output is correct
14 Correct 57 ms 2024 KB Output is correct
15 Correct 96 ms 5172 KB Output is correct
16 Correct 68 ms 3880 KB Output is correct
17 Correct 30 ms 1860 KB Output is correct