#include<bits/stdc++.h>
using namespace std;
#define int long long
#define f first
#define s second
#define endl '\n'
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int t; cin>>t;
while(t--){
int n,m;
cin>>n>>m;
int BOT = n/2;
int BOT1 = m/2;
int REM = n - BOT -1;
int REM1 = m-BOT1 - 1;
int a = n;
a+= n*REM1/(BOT+1);
int b = m ;
b+= m*REM/(BOT1+1);
if(a >= b){
// cerr<<"HERE!"<<endl;
int x = a-n;
vector<vector<int>> v(n, vector<int>(m,1)); // all red
vector<int> need(x,BOT+1);
for(int i = 0; i<n; i++){
int hv = REM1;
for(int j = 0; j<REM1; j++){
int mn = -INT_MAX; int idx = -1;
for(int k = 0; k<need.size(); k++){
if(need[k] > mn) mn = need[k], idx = k;
}
hv--;
need[idx]--;
// cerr<<i<<" "<<idx<<endl;
v[i][idx] = 0;
}
}
cout<<a<<endl;
for(auto x : v){
for(auto y : x){
if(y) cout<<"+";
else cout<<"-";
}
cout<<endl;
}
}
else{
// cerr<<"HERE1!"<<endl;
int x = b-m;
// He activat columnes, ara haig dactivar files.
vector<vector<int>> v(n, vector<int>(m,0)); // all red
vector<int> need(x,BOT1+1);
for(int i = 0; i<m; i++){
int hv = REM;
for(int j = 0; j<REM; j++){
int mn = -INT_MAX; int idx = -1;
for(int k = 0; k<need.size(); k++){
if(need[k] > mn) mn = need[k], idx = k;
}
hv--;
need[idx]--;
v[idx][i] = 1;
}
}
cout<<b<<endl;
for(auto x : v){
for(auto y : x){
if(y) cout<<"+";
else cout<<"-";
}
cout<<endl;
}
}
}
}
/*
1 3 7 9 10
10 + 24
9 + 11
7 + 4
1 + 3
*/
Compilation message
stones.cpp: In function 'int main()':
stones.cpp:34:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for(int k = 0; k<need.size(); k++){
| ~^~~~~~~~~~~~
stones.cpp:64:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | for(int k = 0; k<need.size(); k++){
| ~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
1616 KB |
Output is correct |
2 |
Correct |
209 ms |
6176 KB |
Output is correct |
3 |
Correct |
194 ms |
6944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
1740 KB |
Output is correct |
2 |
Correct |
186 ms |
5164 KB |
Output is correct |
3 |
Correct |
139 ms |
3576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
48 ms |
1616 KB |
Output is correct |
6 |
Correct |
209 ms |
6176 KB |
Output is correct |
7 |
Correct |
194 ms |
6944 KB |
Output is correct |
8 |
Correct |
65 ms |
1740 KB |
Output is correct |
9 |
Correct |
186 ms |
5164 KB |
Output is correct |
10 |
Correct |
139 ms |
3576 KB |
Output is correct |
11 |
Correct |
12 ms |
600 KB |
Output is correct |
12 |
Correct |
131 ms |
4396 KB |
Output is correct |
13 |
Correct |
99 ms |
3232 KB |
Output is correct |
14 |
Correct |
66 ms |
2136 KB |
Output is correct |
15 |
Correct |
357 ms |
9072 KB |
Output is correct |
16 |
Correct |
218 ms |
6744 KB |
Output is correct |
17 |
Correct |
56 ms |
3160 KB |
Output is correct |