# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
255886 | karma | Red-blue table (IZhO19_stones) | C++14 | 96 ms | 3084 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>
#define pb emplace_back
#define ll long long
#define fi first
#define se second
#define mp make_pair
//#define int int64_t
using namespace std;
const int N = int(1e3) + 7;
const int inf = 1e9 + 1;
typedef pair<ll, ll> pii;
int cnt[N], n, m;
void solve() {
cin >> n >> m;
vector<vector<int>> ans(n, vector<int>(m, 0));
priority_queue<pii, vector<pii>, greater<pii>> pq;
/// column -, row +
fill(cnt, cnt + m, 0);
for(int i = 0; i < m; ++i) pq.emplace(0, i);
int res = m, num = 0;
for(int i = 1; i <= n; ++i) {
for(int j = 1; j * 2 <= m; ++j) {
auto top = pq.top(); pq.pop();
++cnt[top.se];
pq.emplace(top.fi + 1, top.se);
}
auto top = pq.top(); pq.pop();
++cnt[top.se];
pq.emplace(top.fi + 1, top.se);
int tmp = 0;
for(int j = 0; j < m; ++j)
if(cnt[j] * 2 < n) ++tmp;
if(tmp + i > res) res = tmp + i, num = i;
}
cout << res << '\n';
fill(cnt, cnt + m, 0);
for(int i = 0; i < m; ++i) pq.emplace(0, i);
for(int i = 0; i < num; ++i) {
for(int j = 1; j * 2 <= m; ++j) {
auto top = pq.top(); pq.pop();
++cnt[top.se];
ans[i][top.se] = 1;
pq.emplace(top.fi + 1, top.se);
}
auto top = pq.top(); pq.pop();
++cnt[top.se];
ans[i][top.se] = 1;
pq.emplace(top.fi + 1, top.se);
}
for(int i = 0; i < n; ++i) {
for(int j = 0; j < m; ++j) {
cout << (ans[i][j] == 0? '-': '+');
}
cout << '\n';
}
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
#define Task "test"
if(fopen(Task".inp", "r")) {
freopen(Task".inp", "r", stdin);
freopen(Task".out", "w", stdout);
}
int T; cin >> T;
while(T --) 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... |