# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
990480 | ToniB | Red-blue table (IZhO19_stones) | C++17 | 54 ms | 2228 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;
typedef pair<int, int> pii;
const int N = 1001;
int t, n, m;
bool ans[N][N];
int main(){
// ios_base::sync_with_stdio(false); cin.tie(0);
cin >> t;
while (t--) {
cin >> n >> m;
bool swp = 0;
if (n > m) {
swap(n, m);
swp = 1;
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) ans[i][j] = 0;
}
int sum = m, mx = (n - 1) / 2;
multiset<pii> ms;
queue<pii> tmp;
for (int i = 0; i < m; ++i) ms.insert({0, i});
for (int i = 0; i < n; ++i) {
vector<int> cols;
bool bad = 0;
while (cols.size() < m / 2 + 1) {
auto it = ms.begin();
int idx = (*it).second, cnt = (*it).first;
ms.erase(it);
if (cnt == mx) {
bad = 1; break;
}
cols.push_back(idx);
tmp.push({cnt + 1, idx});
}
if (bad) break;
for (int j : cols) ans[i][j] = 1;
while (!tmp.empty()) {
ms.insert(tmp.front());
tmp.pop();
}
++sum;
}
cout << sum << '\n';
if (swp) {
for (int i = 0; i < m; ++i) {
for (int j = 0; j < n; ++j) {
if (ans[j][i]) cout << '-';
else cout << '+';
} cout << '\n';
}
} else {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (ans[i][j]) cout << '+';
else cout << '-';
} cout << '\n';
}
}
}
return 0;
}
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... |