#include <bits/stdc++.h>
using namespace std;
int main() {
int T = 1;
cin >> T;
while(T--) {
int n, m;
cin >> n >> m;
bool swapped = 0;
if(n < m) {
swap(n, m);
swapped = true;
}
bool ans[n + 1][m + 1];
memset(ans, 0, sizeof ans);
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[j][i] ? '-' : '+');
}
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();
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Incorrect |
5 ms |
384 KB |
Wrong answer in test 5 29: 31 < 32 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
97 ms |
1308 KB |
Wrong answer in test 97 21: 107 < 116 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
103 ms |
1328 KB |
Wrong answer in test 24 24: 35 < 44 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Incorrect |
5 ms |
384 KB |
Wrong answer in test 5 29: 31 < 32 |