#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back // kak push_back 5
#define endl '\n'
#define FOR(i,start,end) for(int i = start;i < end;i ++)
const ll mxn = 1e6;
ll n,m,a[mxn];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
ll tt = 1;
cin >> tt;
while(tt --){
ll n,m;
cin >> n >> m;
if(n > m && m == 8){
cout << n + 5 << endl;
for(int i = 0;i < n;i ++){
cout << "+++";
if(i % 5 == 0) cout << "++---" << endl;
else if(i % 5 == 1) cout << "--++-" << endl;
else if(i % 5 == 2) cout << "+---+" << endl;
else if(i % 5 == 3) cout << "-++--" << endl;
else if(i % 5 == 4) cout << "---++" << endl;
}
continue;
}
else if(n == 8 && m > n){
char a[n][m];
for(int j = 0;j < m;j ++){
if(j % 5 == 0) a[3][j] = a[4][j] = '-',a[5][j] = a[6][j] = a[7][j] = '+';
else if(j % 5 == 1) a[5][j] = a[6][j] = '-',a[3][j]=a[4][j]=a[7][j]='+';
else if(j % 5 == 2) a[7][j]=a[3][j] = '-',a[4][j]=a[5][j]=a[6][j]='+';
else if(j % 5 == 3) a[4][j]=a[5][j] = '-',a[3][j]=a[6][j]=a[7][j]='+';
else a[6][j]=a[7][j]='-',a[3][j]=a[4][j]=a[5][j]='+';
}
cout << m + 5 << endl;
for(int i = 0;i < n;i ++){
if(i < 3){
for(int j = 0;j < m;j ++){
cout << '-';
}
cout << endl;
continue;
}
for(int j = 0;j < m;j ++) cout << a[i][j];
cout << endl;
}
continue;
}
if(n == 6 && m == 6){
cout << n + m / 2 << endl;
for(int i = 0;i < n;i ++){
for(int j = 0;j < m;j ++){
if(i < m / 2) cout << '-';
else{
if(j == (i - m / 2) * 2 || j == (i - m / 2) * 2 + 1) cout << '-';
else cout << '+';
}
}
cout << endl;
}
continue;
}
if(n >= m){
if(n == 1){
cout << 1 << endl << '+' << endl;
continue;
}
if(m == 1){
cout << n << endl;
for(int i = 0;i < n;i ++) cout << '+' << endl;
continue;
}
if(m % 2 == 0 && n % 2 == 1 && (n + (m - 2) / 2 + (m - 2) % 2) >= (n - 1) + (m - 2) || m % 2 == 1 && n % 2 == 1 && (n + (m - 2) / 2 + (m - 2) % 2) >= (n - 1) + (m - 1) || m % 2 == 0 && n % 2 == 0 && (n + (m - 2) / 2 + (m - 2) % 2) >= (m - 2) + (n - 2) || m % 2 == 1 && n % 2 == 0 && (n + (m - 2) / 2 + (m - 2) % 2) >= m - 1 + n - 2){
if(m == 5) {
cout << n + 3 << endl;
for(int i = 0;i < n;i ++){
cout << "++";
if(i % 3 == 0) cout << "+--";
else if(i % 3 == 1) cout << "-+-";
else cout << "--+";
cout << endl;
}
continue;
}
else cout << n + (m - 2) / 2 + (m - 2) % 2 << endl;
for(int i = 0;i < n;i ++){
cout<<'+';
for(int j = 1;j < m - 1;j ++){
if(j % 2 == 1) cout << '-';
else cout << '+';
}
cout << '+' << endl;
}
}
else{
if(n % 2 == 1){
if(m % 2 == 1){
cout << (n - 1) + (m - 1) << endl;
for(int i = 0;i < n;i ++){
if(i == n - 1){
for(int j = 0;j < m;j ++){
cout << '-';
}
cout << endl;
continue;
}
cout << '+';
for(int j = 1;j < m;j ++){
if(i % 2 == 0){
if(j % 2 == 1) cout << '-';
else cout << '+';
}
else{
if(j % 2 == 1) cout << '+';
else cout << '-';
}
}
cout << endl;
}
}
else{
cout << (n - 1) + (m - 2) << endl;
for(int i = 0;i < n;i ++){
if(i == n - 1){
for(int j = 0;j < m;j ++){
cout << '-';
}
cout << endl;
continue;
}
cout << '+';
for(int j = 1;j < m - 1;j ++){
if(i % 2 == 0){
if(j % 2 == 1) cout << '-';
else cout << '+';
}
else{
if(j % 2 == 1) cout << '+';
else cout << '-';
}
}
cout << '+' << endl;
}
}
}
else{
if(m % 2 == 1){
cout << n - 2 + m - 1 << endl;
for(int i = 0;i < n;i ++){
if(i == n - 1 || i == 0){
for(int j = 0;j < m;j ++){
cout << '-';
}
cout << endl;
continue;
}
cout << '+';
for(int j = 1;j < m;j ++){
if(i % 2 == 0){
if(j % 2 == 1) cout << '-';
else cout << '+';
}
else{
if(j % 2 == 1) cout << '+';
else cout << '-';
}
}
cout << endl;
}
}
else{
cout << n - 2 + m - 2 << endl;
for(int i = 0;i < n;i ++){
if(i == 0 || i == n - 1){
for(int j = 0;j < m;j ++) cout << '-';
cout << endl;
continue;
}
cout << '+';
for(int j = 1;j < m - 1;j ++){
if(i % 2 == 0){
if(j % 2 == 1) cout << '-';
else cout << '+';
}
else{
if(j % 2 == 1) cout << '+';
else cout << '-';
}
}
cout << '+' << endl;
}
}
}
}
}
else{
if(m == 1){
cout << 1 << endl << '-' << endl;
continue;
}
if(n == 1){
cout << m << endl;
for(int i = 0;i < m;i ++) cout << '-';
cout << endl;
continue;
}
if(n % 2 == 0 && m % 2 == 1 && (m + (n - 2) / 2 + (n - 2) % 2) >= (m - 1) + (n - 2) || n % 2 == 1 && m % 2 == 1 && (m + (n - 2) / 2 + (n - 2) % 2) >= (m - 1) + (n - 1) || n % 2 == 0 && m % 2 == 0 && (m + (n - 2) / 2 + (n - 2) % 2) >= (n - 2) + (m - 2) || n % 2 == 1 && m % 2 == 0 && (m + (n - 2) / 2 + (n - 2) % 2) >= n - 1 + m - 2){
if(n == 5){
cout << m + 3 << endl;
for(int i = 0;i < n;i ++){
if(i == 0 || i == 1){
for(int j = 0;j < m;j ++){
cout << '-';
}
cout << endl;
continue;
}
if(i == 3) { cout << '+'; m--;}
else if(i == 4) { cout << "++";m --;}
for(int j = 0;j < m;j ++){
if(j % 3 == 0) cout << '-';
else cout << '+';
}
cout << endl;
}
continue;
}
cout << m + (n - 2) / 2 + (n - 2) % 2 << endl;
for(int i = 0;i < n;i ++){
for(int j = 0;j < m;j ++){
if(i == 0 || i == n - 1){
cout << '-';
}
else if(i % 2 == 1) cout << '+';
else cout << '-';
}
cout << endl;
}
}
else{
if(m % 2 == 1){
if(n % 2 == 1){
cout << m - 1 + n - 1 << endl;
for(int i = 0;i < n;i ++){
if(i == 0){
for(int j = 0;j < m - 1;j ++) cout << '-';
cout << '+' << endl;
continue;
}
for(int j = 0;j < m - 1;j ++){
if(i % 2 == 1){
if(j % 2 == 0) cout << '+';
else cout << '-';
}
else{
if(j % 2 == 0) cout << '-';
else cout << '+';
}
}
cout << '+' << endl;
}
}
else{
cout << m - 1 + n - 2 << endl;
for(int i = 0;i < n;i ++){
if(i == 0 || i == n - 1){
for(int j = 0;j < m - 1;j ++) cout << '-';
cout << '+' << endl;
continue;
}
for(int j = 0;j < m - 1;j ++){
if(i % 2 == 1){
if(j % 2 == 0) cout << '+';
else cout << '-';
}
else{
if(j % 2 == 0) cout << '-';
else cout << '+';
}
}
cout << '+' << endl;
}
}
}
else{
if(n % 2 == 1){
cout << m - 2 + n - 1 << endl;
for(int i = 0;i < n;i ++){
if(i == 0){
cout << '+';
for(int j = 1;j < m - 1;j ++) cout << '-';
cout << '+' << endl;
continue;
}
cout << '+';
for(int j = 1;j < m - 1;j ++){
if(i % 2 == 1){
if(j % 2 == 0) cout << '+';
else cout << '-';
}
else{
if(j % 2 == 0) cout << '-';
else cout << '+';
}
}
cout << '+' << endl;
}
}
else{
cout << m - 2 + n - 2 << endl;
for(int i = 0;i < n;i ++){
if(i == 0 || i == n - 1){
cout << '+';
for(int j = 1;j < m - 1;j ++) cout << '-';
cout << '+' << endl;
continue;
}
cout << '+';
for(int j = 1;j < m - 1;j ++){
if(i % 2 == 1){
if(j % 2 == 0) cout << '+';
else cout << '-';
}
else{
if(j % 2 == 0) cout << '-';
else cout << '+';
}
}
cout << '+' << endl;
}
}
}
}
}
}
}
Compilation message
stones.cpp: In function 'int main()':
stones.cpp:77:41: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
77 | if(m % 2 == 0 && n % 2 == 1 && (n + (m - 2) / 2 + (m - 2) % 2) >= (n - 1) + (m - 2) || m % 2 == 1 && n % 2 == 1 && (n + (m - 2) / 2 + (m - 2) % 2) >= (n - 1) + (m - 1) || m % 2 == 0 && n % 2 == 0 && (n + (m - 2) / 2 + (m - 2) % 2) >= (m - 2) + (n - 2) || m % 2 == 1 && n % 2 == 0 && (n + (m - 2) / 2 + (m - 2) % 2) >= m - 1 + n - 2){
| ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
stones.cpp:77:209: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
77 | if(m % 2 == 0 && n % 2 == 1 && (n + (m - 2) / 2 + (m - 2) % 2) >= (n - 1) + (m - 2) || m % 2 == 1 && n % 2 == 1 && (n + (m - 2) / 2 + (m - 2) % 2) >= (n - 1) + (m - 1) || m % 2 == 0 && n % 2 == 0 && (n + (m - 2) / 2 + (m - 2) % 2) >= (m - 2) + (n - 2) || m % 2 == 1 && n % 2 == 0 && (n + (m - 2) / 2 + (m - 2) % 2) >= m - 1 + n - 2){
| ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
stones.cpp:77:293: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
77 | if(m % 2 == 0 && n % 2 == 1 && (n + (m - 2) / 2 + (m - 2) % 2) >= (n - 1) + (m - 2) || m % 2 == 1 && n % 2 == 1 && (n + (m - 2) / 2 + (m - 2) % 2) >= (n - 1) + (m - 1) || m % 2 == 0 && n % 2 == 0 && (n + (m - 2) / 2 + (m - 2) % 2) >= (m - 2) + (n - 2) || m % 2 == 1 && n % 2 == 0 && (n + (m - 2) / 2 + (m - 2) % 2) >= m - 1 + n - 2){
| ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
stones.cpp:211:41: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
211 | if(n % 2 == 0 && m % 2 == 1 && (m + (n - 2) / 2 + (n - 2) % 2) >= (m - 1) + (n - 2) || n % 2 == 1 && m % 2 == 1 && (m + (n - 2) / 2 + (n - 2) % 2) >= (m - 1) + (n - 1) || n % 2 == 0 && m % 2 == 0 && (m + (n - 2) / 2 + (n - 2) % 2) >= (n - 2) + (m - 2) || n % 2 == 1 && m % 2 == 0 && (m + (n - 2) / 2 + (n - 2) % 2) >= n - 1 + m - 2){
| ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
stones.cpp:211:209: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
211 | if(n % 2 == 0 && m % 2 == 1 && (m + (n - 2) / 2 + (n - 2) % 2) >= (m - 1) + (n - 2) || n % 2 == 1 && m % 2 == 1 && (m + (n - 2) / 2 + (n - 2) % 2) >= (m - 1) + (n - 1) || n % 2 == 0 && m % 2 == 0 && (m + (n - 2) / 2 + (n - 2) % 2) >= (n - 2) + (m - 2) || n % 2 == 1 && m % 2 == 0 && (m + (n - 2) / 2 + (n - 2) % 2) >= n - 1 + m - 2){
| ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
stones.cpp:211:293: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
211 | if(n % 2 == 0 && m % 2 == 1 && (m + (n - 2) / 2 + (n - 2) % 2) >= (m - 1) + (n - 2) || n % 2 == 1 && m % 2 == 1 && (m + (n - 2) / 2 + (n - 2) % 2) >= (m - 1) + (n - 1) || n % 2 == 0 && m % 2 == 0 && (m + (n - 2) / 2 + (n - 2) % 2) >= (n - 2) + (m - 2) || n % 2 == 1 && m % 2 == 0 && (m + (n - 2) / 2 + (n - 2) % 2) >= n - 1 + m - 2){
| ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
1304 KB |
Output is correct |
2 |
Correct |
23 ms |
1108 KB |
Output is correct |
3 |
Correct |
27 ms |
1108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
1268 KB |
Output is correct |
2 |
Correct |
19 ms |
1100 KB |
Output is correct |
3 |
Correct |
16 ms |
1032 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
25 ms |
1304 KB |
Output is correct |
6 |
Correct |
23 ms |
1108 KB |
Output is correct |
7 |
Correct |
27 ms |
1108 KB |
Output is correct |
8 |
Correct |
23 ms |
1268 KB |
Output is correct |
9 |
Correct |
19 ms |
1100 KB |
Output is correct |
10 |
Correct |
16 ms |
1032 KB |
Output is correct |
11 |
Incorrect |
6 ms |
468 KB |
Wrong answer in test 9 18: 24 < 25 |
12 |
Halted |
0 ms |
0 KB |
- |