This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define pii pair<int,int>
#define All(x) x.begin(), x.end()
using namespace std;
#define debug(args...) kout("[ " + string(#args) + " ]", args)
void kout() { cerr << endl; }
template <class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ',kout(b...); }
template <class T> void pary(T L, T R) { while (L != R) cerr << *L << " \n"[++L==R]; }
int t, n, m;
vector<vector<char>> A, B;
vector <pii> cnt;
int ansA, ansB;
void init() {
A.clear(), B.clear();
A.resize(n), B.resize(n);
for (int i = 0; i < n; i++)
A[i].resize(m), B[i].resize(m);
ansA = n, ansB = m;
}
void check() {
int tmp = ansA;
for (int i = 0; i < n; i++) {
int c = 0;
for (int j = 0; j < m; j++) {
if (A[i][j] == '+') c++;
}
if (c * 2 > m) tmp--;
}
for (int i = 0; i < m; i++) {
int c = 0;
for (int j = 0; j < n; j++) {
if (A[j][i] == '-') c++;
}
if (c * 2 > n) tmp--;
}
assert(!tmp);
tmp = ansB;
for (int i = 0; i < n; i++) {
int c = 0;
for (int j = 0; j < m; j++) {
if (B[i][j] == '+') c++;
}
if (c * 2 > m) tmp--;
}
for (int i = 0; i < m; i++) {
int c = 0;
for (int j = 0; j < n; j++) {
if (B[j][i] == '-') c++;
}
if (c * 2 > n) tmp--;
}
assert(!tmp);
}
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> t;
while (t--) {
cin >> n >> m;
init();
cnt.clear(), cnt.resize(n);
for (int i = 0; i < n; i++)
cnt[i] = pii(0, i);
for (int i = 0; i < m; i++) {
int c = (n+2)/2;
sort(All(cnt));
for (auto &[v, j] : cnt) {
if (c > 0 && v < (m-1)/2) {
A[j][i] = '-';
v++, c--;
} else {
A[j][i] = '+';
}
}
if (!c) ansA++;
}
cnt.clear(), cnt.resize(m);
for (int i = 0; i < m; i++)
cnt[i] = pii(0, i);
for (int i = 0; i < n; i++) {
int c = (m+2)/2;
sort(All(cnt));
for (auto &[v, j] : cnt) {
if (c > 0 && v < (n-1)/2) {
B[i][j] = '+';
v++, c--;
} else {
B[i][j] = '-';
}
}
if (!c) ansB++;
}
check();
if (ansA > ansB) {
cout << ansA << '\n';
for (auto v : A) {
for (char c : v) {
cout << c;
}
cout << '\n';
}
} else {
cout << ansB << '\n';
for (auto v : B) {
for (char c : v) {
cout << c;
}
cout << '\n';
}
}
}
}
Compilation message (stderr)
stones.cpp: In function 'int main()':
stones.cpp:70:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
70 | for (auto &[v, j] : cnt) {
| ^
stones.cpp:86:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
86 | for (auto &[v, j] : cnt) {
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |