#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);
int rows = n, columns = 0, need = m / 2 + 1, to = 0;
for(int i = 1; i <= m; ++i) {
int allPlus = min(need, m - i);
int rem = m - allPlus, can = n - n / 2 - 1;
if(allPlus + i * can / rows >= need) {
columns = i;
to = allPlus;
}
}
int prev = to + 1;
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= to; ++j) {
ans[i][j] = 1;
}
int rem = need - to;
auto next = [&](int index) {
return 1 + (index == m ? to : index);
};
for(int j = prev; rem--; j = next(j)) {
prev = next(j);
ans[i][j] = 1;
}
}
cout << rows + columns << '\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:19:17: warning: unused variable 'rem' [-Wunused-variable]
19 | int rem = m - allPlus, can = n - n / 2 - 1;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
60 ms |
1296 KB |
Output is correct |
2 |
Correct |
35 ms |
1912 KB |
Output is correct |
3 |
Correct |
39 ms |
1912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
1332 KB |
Output is correct |
2 |
Correct |
36 ms |
1660 KB |
Output is correct |
3 |
Correct |
30 ms |
1408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
60 ms |
1296 KB |
Output is correct |
6 |
Correct |
35 ms |
1912 KB |
Output is correct |
7 |
Correct |
39 ms |
1912 KB |
Output is correct |
8 |
Correct |
41 ms |
1332 KB |
Output is correct |
9 |
Correct |
36 ms |
1660 KB |
Output is correct |
10 |
Correct |
30 ms |
1408 KB |
Output is correct |
11 |
Correct |
12 ms |
544 KB |
Output is correct |
12 |
Correct |
31 ms |
1528 KB |
Output is correct |
13 |
Correct |
33 ms |
1400 KB |
Output is correct |
14 |
Correct |
25 ms |
1148 KB |
Output is correct |
15 |
Correct |
39 ms |
2304 KB |
Output is correct |
16 |
Correct |
32 ms |
1784 KB |
Output is correct |
17 |
Correct |
14 ms |
1024 KB |
Output is correct |