#include<bits/stdc++.h>
#define fi first
#define se second
#define len(x) (int)(x).size()
#define pb push_back
#define p2(x) (x)*(x)
#define all(x) (x).begin() , (x).end()
#define mkp make_pair
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("-O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long double ld;
typedef long long ll;
void solve(int n , int m){
/// red okay???
/// lulz
pair < int , int > best = {-1 , -1};
int ans = 0;
for(int A = 0; A <= n; ++A){
/// lulz
int ost = m - (m + 2)/2;
int need = max(0 , (n+2)/2 - (n-A));
int B;
if(need == 0){
B = m;
if(ans < A + B)
ans = A + B , best = {A , B};
}else{
B = (A * ost) / need;
B = min(B , m);
if(ans < A + B)
ans = A + B , best = {A , B};
}
}
/// lulz
cout << ans << '\n';
int A = best.fi , B = best.se;
int ost = m - (m + 2)/2;
int need = max(0 , (n+2)/2 - (n-A));
if(need == 0){
for(int i = 0 ; i < n; ++i){
if(A){
for(int j = 0 ; j < (m+2)/2;++j)
cout << '+';
for(int j = (m+2)/2; j < m; ++j)
cout << '-';
A--;
}else{
for(int j = 0 ; j < m; ++j)
cout << '-';
}
cout << '\n';
}
}else{
// system("pause");
// cout << " YO " << n << ' '<< m << '\n';
// cout << "YO\n";
// cout << A << ' ' << B << '\n';
// cout << ost << ' ' << need << '\n';
deque < int > bad;
for(int j = 0 ; j < B; ++j)
bad.pb(j);
vector < int > val(m);
for(int i = 0 ; i < n; ++i){
if(A){
/// poses
string cur = string(m , '+');
for(int j = 0; j < m - (m + 2) / 2; ++j){
/// lulz
int X = len(bad);
while(!bad.empty() && X){
--X;
int head = bad.front();bad.pop_front();
if(val[head] == need)
continue;
cur[head] = '-';
val[head]++;
bad.pb(head);
break;
}
}
cout << cur;
A--;
}else{
for(int j = 0 ; j < m; ++j)
cout << '-';
}
cout << '\n';
}
}
}
int main(){
ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
int t;
cin >> t;
// for(int i = 1; i<=10; ++i)
// for(int j = 1; j <= 10; ++j)
// solve(i , j);
while(t--){
int n ,m ;
cin >> n >> m;
solve( n , m);
}
}
/*
*/
Compilation message
stones.cpp: In function 'void solve(int, int)':
stones.cpp:46:9: warning: unused variable 'ost' [-Wunused-variable]
46 | int ost = m - (m + 2)/2;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
1388 KB |
Output is correct |
2 |
Correct |
7 ms |
1260 KB |
Output is correct |
3 |
Correct |
7 ms |
1260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
1388 KB |
Output is correct |
2 |
Correct |
7 ms |
1132 KB |
Output is correct |
3 |
Correct |
6 ms |
1132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
11 ms |
1388 KB |
Output is correct |
6 |
Correct |
7 ms |
1260 KB |
Output is correct |
7 |
Correct |
7 ms |
1260 KB |
Output is correct |
8 |
Correct |
11 ms |
1388 KB |
Output is correct |
9 |
Correct |
7 ms |
1132 KB |
Output is correct |
10 |
Correct |
6 ms |
1132 KB |
Output is correct |
11 |
Correct |
5 ms |
620 KB |
Output is correct |
12 |
Correct |
6 ms |
1132 KB |
Output is correct |
13 |
Correct |
7 ms |
1132 KB |
Output is correct |
14 |
Correct |
5 ms |
1004 KB |
Output is correct |
15 |
Correct |
8 ms |
1388 KB |
Output is correct |
16 |
Correct |
6 ms |
1132 KB |
Output is correct |
17 |
Correct |
3 ms |
620 KB |
Output is correct |