# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
308782 | nikatamliani | Red-blue table (IZhO19_stones) | C++14 | 60 ms | 2304 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;
int main() {
int T = 1;
cin >> T;
while(T--) {
int n, m;
cin >> n >> m;
bool swapped = 0;
if(n < m) {
swap(n, m);
swapped = true;
}
bool ans[n + 1][m + 1];
memset(ans, 0, sizeof ans);
int rows = n, columns = 0, need = m / 2 + 1, to = 0;
for(int i = 1; i <= m; ++i) {
int allPlus = min(need, m - i);
int rem = m - allPlus, can = n - n / 2 - 1;
if(allPlus + i * can / rows >= need) {
columns = i;
to = allPlus;
}
}
int prev = to + 1;
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= to; ++j) {
ans[i][j] = 1;
}
int rem = need - to;
auto next = [&](int index) {
return 1 + (index == m ? to : index);
};
for(int j = prev; rem--; j = next(j)) {
prev = next(j);
ans[i][j] = 1;
}
}
cout << rows + columns << '\n';
if(!swapped) {
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= m; ++j) {
cout << (ans[i][j] ? '+' : '-');
}
cout << '\n';
}
} else {
for(int i = 1; i <= m; ++i) {
for(int j = 1; j <= n; ++j) {
cout << (ans[j][i] ? '-' : '+');
}
cout << '\n';
}
}
}
}
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... |