#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 |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
344 KB |
in the table A+B is not equal to 5 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
in the table A+B is not equal to 51 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
344 KB |
in the table A+B is not equal to 5 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
31 ms |
1364 KB |
Wrong answer in test 97 21: 112 < 116 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
32 ms |
1436 KB |
in the table A+B is not equal to 46 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
344 KB |
in the table A+B is not equal to 5 |
3 |
Halted |
0 ms |
0 KB |
- |