이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |