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;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int t; cin >> t;
while (t--) {
int n, m; cin >> n >> m;
array<int, 2> res{m, 0};
vector<int> cnt(m), ord(m); iota(ord.begin(), ord.end(), 0);
int cur = m;
auto cmp = [&](int a, int b) -> bool {
if (cnt[a] >= n / 2 + 1 && cnt[b] >= n / 2 + 1) {
return a < b;
}
if (cnt[a] >= n / 2 + 1) {
return 1;
}
if (cnt[b] >= n / 2 + 1) {
return 0;
}
return cnt[a] < cnt[b];
};
for (int i = 0; i < n; ++i) {
sort(ord.begin(), ord.end(), cmp);
for (int j = 0, k = 0; j < m / 2 + 1; ++j) {
while (cnt[ord[k]] == n) {
++k;
}
cur -= ++cnt[ord[k++]] == n / 2 + 1;
}
res = max(res, {cur + i + 1, i + 1});
}
fill(cnt.begin(), cnt.end(), 0);
vector a(n, vector<char>(m, '-'));
for (int i = 0; i < res[1]; ++i) {
sort(ord.begin(), ord.end(), cmp);
for (int j = 0, k = 0; j < m / 2 + 1; ++j) {
while (cnt[ord[k]] == n) {
++k;
}
++cnt[ord[k]];
a[i][ord[k++]] = '+';
}
}
cout << res[0] << "\n";
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
cout << a[i][j];
}
cout << "\n";
}
}
return 0;
}
# | 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... |