# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
900515 | marcid | Red-blue table (IZhO19_stones) | C++17 | 17 ms | 1372 KiB |
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>
using namespace std;
#define int long long
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define vb vector<bool>
#define pb push_back
#define eb emplace_back
const int maxn = 1e6+5;
const int sq = 23;
const int inf = 1e18;
void solve() {
int n, m; cin >> n >> m;
// n, m <= 1000 -> n*m=1e6
// + is red, - is blue
// A - number of rows with cnt(+)>cnt(-)
// B - number of cols with cnt(-)>cnt(+)
// hypo:
// if we have optimal field, if we rotate it by 90 degrees and replace '+'s & '-'s, it remains optimal
// that means, ans[n][m]<->ans[m][n]
// + in a row >=n/2+1 and - in a col >=m/2+1
if (n==1 or n==2) {
cout << m << '\n';
for (int i = 0; i < n; i++) {for (int j = 0; j < m; j++) cout << '-'; cout << '\n';}
return;
} if (m==1 or m==2) {
cout << n << '\n';
for (int i = 0; i < n; i++) {for (int j = 0; j < m; j++) cout << '+'; cout << '\n';}
return;
} int row = m/2+1, col = n/2+1;
if (n==m) {
cout << n+(n-1)/2 << '\n';
if (n&1) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cout << (j&1?'-':'+');
} cout << '\n';
}
} else {
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cout << (j<n-1?(j&1?'-':'+'):'+');
} cout << '\n';
}
}
return;
}
if (n==3) {
cout << m+1 << '\n';
for (int i = 0; i < 2; i++) {
for (int j = 0; j < m; j++) {
cout << '-';
} cout << '\n';
} for (int i = 0; i < m; i++) cout << '+';
cout << '\n';
return;
} if (m==3) {
cout << n+1 << '\n';
for (int i = 0; i < n; i++) {
cout << "++-\n";
}
return;
}
}
signed main() {
cin.tie()->sync_with_stdio(0);
int tc = 1;
cin >> tc;
while (tc--) {
solve();
}
}
Compilation message (stderr)
# | 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... |