Submission #1093925

# Submission time Handle Problem Language Result Execution time Memory
1093925 2024-09-28T05:39:02 Z stdfloat Red-blue table (IZhO19_stones) C++17
100 / 100
46 ms 2388 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#define ff  first
#define ss  second
#define pii pair<int, int>

#define all(v) (v).begin(), (v).end()

void solve() {
	int n, m;
	cin >> n >> m;


	int ans = max(n, m);
	vector<vector<char>> a;

	if (n < m) {
		a.assign(n, vector<char>(m, '-'));

		vector<int> vis(m);
		for (int i = 0; i < n; i++) {
			vector<pii> v;
			for (int j = 0; j < m; j++)
				v.push_back({vis[j], j});

			sort(v.begin(), v.end());

			bool tr = true;			
			for (int j = 0; j < (m >> 1) + 1; j++) {
				if (v[j].ff == (n - 1 >> 1)) {
					tr = false; break;
				}

				vis[v[j].ss]++;
				a[i][v[j].ss] = '+';
			}

			if (!tr) break;

			ans++;
		}
	}
	else {
		a.assign(n, vector<char>(m, '+'));

		vector<int> vis(n);
		for (int i = 0; i < m; i++) {
			vector<pii> v;
			for (int j = 0; j < n; j++)
				v.push_back({vis[j], j});

			sort(v.begin(), v.end());

			bool tr = true;			
			for (int j = 0; j < (n >> 1) + 1; j++) {
				if (v[j].ff == (m - 1 >> 1)) {
					tr = false; break;
				}

				vis[v[j].ss]++;
				a[v[j].ss][i] = '-';
			}

			if (!tr) break;

			ans++;
		}
	}

	cout << ans << '\n';
	for (auto i : a) {
		for (auto j : i)
			cout << j;
		cout << '\n';
	}
	cout << '\n';
}

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);

	int T;
	cin >> T;
	while (T--) solve();
}

Compilation message

stones.cpp: In function 'void solve()':
stones.cpp:33:23: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
   33 |     if (v[j].ff == (n - 1 >> 1)) {
      |                     ~~^~~
stones.cpp:59:23: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
   59 |     if (v[j].ff == (m - 1 >> 1)) {
      |                     ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 2 ms 520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 1360 KB Output is correct
2 Correct 39 ms 2008 KB Output is correct
3 Correct 37 ms 1876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 1348 KB Output is correct
2 Correct 35 ms 1612 KB Output is correct
3 Correct 34 ms 1368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 2 ms 520 KB Output is correct
5 Correct 42 ms 1360 KB Output is correct
6 Correct 39 ms 2008 KB Output is correct
7 Correct 37 ms 1876 KB Output is correct
8 Correct 36 ms 1348 KB Output is correct
9 Correct 35 ms 1612 KB Output is correct
10 Correct 34 ms 1368 KB Output is correct
11 Correct 8 ms 520 KB Output is correct
12 Correct 32 ms 1640 KB Output is correct
13 Correct 35 ms 1372 KB Output is correct
14 Correct 26 ms 1108 KB Output is correct
15 Correct 46 ms 2388 KB Output is correct
16 Correct 32 ms 1884 KB Output is correct
17 Correct 14 ms 1116 KB Output is correct