#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<int, int> pii;
typedef pair<ld, ld> pld;
int n, m, rev;
int cur[1009];
void solve(){
cin >> n >> m;
pii use = {-1, -1};
for(int i = 0; i <= n; ++i){
int curans = i;
int needother = max(0, (n+2)/2-(n-i));
int extra = m-(m+2)/2;
if(needother == 0)
curans += m;
else{
curans += min(m, i*extra/needother);
}
use = max(use, {curans, i});
//cout << i << ' ' << << '\n';
}
for(int j = 0; j < m; ++j)
cur[j] = 0;
cout << use.ff << '\n';
int left = use.ss;
int need = max(0, (n+2)/2-(n-left));
int col = m;
if(need)
col = min(m, left*(m-(m+2)/2)/need);
for(int i = 0; i < n; ++i){
if(left){
--left;
int extra = m-(m+2)/2;
set<pii> s;
for(int j = 0; j < col; ++j){
s.insert({cur[j], j});
}
set<int> use;
while(extra--){
if(s.size()){
use.insert(s.begin()->ss);
s.erase(s.begin());
}
}
for(int j = 0; j < m; ++j){
if(use.size() && j == *use.begin()){
++cur[j];
use.erase(use.begin());
cout << '-';
}
else
cout << '+';
}
}
else
for(int j = 0; j < m; ++j)
cout << '-';
cout << '\n';
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
int t;
cin >> t;
while(t--)
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
3 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
150 ms |
1272 KB |
Output is correct |
2 |
Correct |
173 ms |
1220 KB |
Output is correct |
3 |
Correct |
164 ms |
1188 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
160 ms |
1228 KB |
Output is correct |
2 |
Correct |
154 ms |
1220 KB |
Output is correct |
3 |
Correct |
170 ms |
964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
3 ms |
332 KB |
Output is correct |
5 |
Correct |
150 ms |
1272 KB |
Output is correct |
6 |
Correct |
173 ms |
1220 KB |
Output is correct |
7 |
Correct |
164 ms |
1188 KB |
Output is correct |
8 |
Correct |
160 ms |
1228 KB |
Output is correct |
9 |
Correct |
154 ms |
1220 KB |
Output is correct |
10 |
Correct |
170 ms |
964 KB |
Output is correct |
11 |
Correct |
26 ms |
460 KB |
Output is correct |
12 |
Correct |
137 ms |
1104 KB |
Output is correct |
13 |
Correct |
180 ms |
1072 KB |
Output is correct |
14 |
Correct |
115 ms |
964 KB |
Output is correct |
15 |
Correct |
202 ms |
1388 KB |
Output is correct |
16 |
Correct |
134 ms |
1068 KB |
Output is correct |
17 |
Correct |
59 ms |
568 KB |
Output is correct |