#include <bits/stdc++.h>
using namespace std;
int main() {
int T = 1;
cin >> T;
while(T--) {
int n, m;
cin >> n >> m;
bool ans[n + 1][m + 1];
bool swapped = 0;
memset(ans, 0, sizeof ans);
if(n < m) {
swap(n, m);
swapped = true;
}
set < pair < int, int > > counts;
vector < int > good;
for(int i = 1; i <= m; ++i) counts.insert({0, i});
for(int i = 1; i <= n; ++i) {
int cnt = m / 2 + 1;
for(int j : good) {
if(cnt == 0)break;
cnt--;
ans[i][j] = 1;
}
while(cnt > 0) {
auto [x, y] = *counts.begin();
counts.erase(counts.begin());
++x;
if(n - x <= x) {
good.push_back(y);
} else {
counts.insert({x, y});
}
ans[i][y] = 1;
cnt--;
}
}
vector < int > row(n + 1), col(m + 1);
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= m; ++j) {
if(ans[i][j]) {
++row[i], --col[j];
} else {
--row[i], ++col[j];
}
}
}
int best = 0;
for(int i = 1; i <= n; ++i) best += row[i] > 0;
for(int i = 1; i <= m; ++i) best += col[i] > 0;
cout << best << '\n';
if(!swapped) {
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= m; ++j) {
cout << (ans[i][j] ? '+' : '-');
}
cout << '\n';
}
} else {
for(int i = 1; i <= m; ++i) {
for(int j = 1; j <= n; ++j) {
cout << (ans[i][j] ? '-' : '+');
}
cout << '\n';
}
}
}
}
Compilation message
stones.cpp: In function 'int main()':
stones.cpp:27:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
27 | auto [x, y] = *counts.begin();
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
in the table A+B is not equal to 3 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
384 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
in the table A+B is not equal to 3 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
384 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
100 ms |
1380 KB |
Wrong answer in test 24 24: 35 < 44 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
in the table A+B is not equal to 3 |
2 |
Halted |
0 ms |
0 KB |
- |