Submission #613949

# Submission time Handle Problem Language Result Execution time Memory
613949 2022-07-30T14:20:09 Z Mohammed_Atalah Red-blue table (IZhO19_stones) C++17
100 / 100
31 ms 2308 KB
/// Template path: /home/mohammed/.config/sublime-text-3/Packages/User

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

// typedef
typedef long long ll;
typedef long double ld;
typedef vector<int> vecint;
typedef vector<char> vecchar;
typedef vector<string> vecstr;
typedef vector<long long> vecll;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

// Marcos
#define endl ("\n")
#define int long long
#define mod 1000000007
#define pi (3.141592653589)
#define REP(i,a,b) for (int i = a; i < b; i++)
#define RREP(i,a,b) for (int i = a; i > b; i--)
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)

// Functions
long long squared(long long x) {return (x * x) % mod;}
int factorial(int n) {long long res = 1; for (int i = 1; i <= n; i++) {res = ((res * i) % mod + mod) % mod ;} return res;}
long long power(long long x, long long p) {if (p == 0) {return 1;} if (p % 2 == 1) {return (power(x, p - 1) * x) % mod;} return squared(power(x, p / 2));}

// cout << fixed;
// cout << setprecision(4);


// ---------(^_^)--------- //




void main_solve() {


	int n, m; cin >> n >> m;
	string s = "";
	for (int i = 0; i < m; i ++) {
		s += ((n > m) ? '+' : '-');
	}


	vector<string> v(n, s);
	int result = max(n, m);
	if (n > m) {
		queue<vector<int>>q;
		int e = (m / 2) - ((m % 2 == 0) ? 1 : 0);
		for (int i = 0; i < n && e ; i++) {
			q.push({1, i});
		}

		for (int i = 0; i < m ; i++) {
			int w = (n / 2) + 1;
			int t = 0;
			while (w-- && !q.empty()) {
				vector<int> vv = q.front();
				q.pop();
				int a = vv[1];
				int b = vv[0];
				v[a][i] = '-';
				if (b < e) {
					q.push({b + 1, a});
				}
				t++;
			}

			if (t == (n / 2) + 1) {
				result++;
			}
		}
	} else {
		// cout << "hello" << endl;
		queue<vector<int>>q;
		int e = (n / 2) - ((n % 2 == 0) ? 1 : 0);
		for (int i = 0; i < m && e ; i++) {
			q.push({1, i});
		}
		// cout << e << endl;
		for (int i = 0; i < n && e ; i++) {
			int w = (m / 2) + 1;
			int t = 0;
			while (w-- && !q.empty()) {
				vector<int> vv = q.front();
				q.pop();
				int a = vv[1];
				int b = vv[0];
				v[i][a] = '+';
				if (b < e) {
					q.push({b + 1, a});
				}
				t++;
			}

			if (t == (m / 2) + 1) {
				result++;
			}
		}
	}

	cout << result << endl;

	for (auto &i : v) {
		cout << i << endl;
	}


}


int32_t main() {

	fast;

	// Just another problem (-_-)

	int t;
	cin >> t;
	// t = 1;

	while (t--) {
		main_solve();
	}


}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 1356 KB Output is correct
2 Correct 31 ms 1876 KB Output is correct
3 Correct 29 ms 1868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 1352 KB Output is correct
2 Correct 21 ms 1664 KB Output is correct
3 Correct 18 ms 1364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 28 ms 1356 KB Output is correct
6 Correct 31 ms 1876 KB Output is correct
7 Correct 29 ms 1868 KB Output is correct
8 Correct 27 ms 1352 KB Output is correct
9 Correct 21 ms 1664 KB Output is correct
10 Correct 18 ms 1364 KB Output is correct
11 Correct 7 ms 468 KB Output is correct
12 Correct 24 ms 1560 KB Output is correct
13 Correct 24 ms 1424 KB Output is correct
14 Correct 21 ms 1096 KB Output is correct
15 Correct 28 ms 2308 KB Output is correct
16 Correct 21 ms 1780 KB Output is correct
17 Correct 9 ms 960 KB Output is correct