#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
using namespace std;
const int mod = 1e9 + 7;
const int inf = 1e12*2;
const int N = 2e5 + 5;
int32_t main(){
cin.tie(0); cout.tie(0);
ios_base::sync_with_stdio(false);
int t;
cin>>t;
while(t--){
int n, m;
cin>>n>>m;
int type1 = n + ((m - (m/2 + 1)) * n) / (n/2 + 1);
int type2 = m + ((n - (n/2 + 1)) * m) / (m/2 + 1);
cout<<max(type1, type2)<<endl;
if(type1 >= type2){
vector<vector<char> > a(n, vector<char>(m, '+'));
int cnt = n/2 + 1;
int limit = m - (m/2 + 1);
priority_queue<pair<int, int> > pq;
for(int i = 0; i < n; i++){
if(limit == 0) break;
pq.push(mp(0LL, i));
}
for(int j = 0; j < m; j++){
for(int i = 0; i < cnt; i++){
if(!pq.size()) break;
int xc = pq.top().first * (-1), pos = pq.top().second;
a[pos][j] = '-';
xc++;
pq.pop();
if(xc < limit) pq.push(mp(xc * (-1), pos));
}
}
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
cout<<a[i][j];
}
cout<<endl;
}
}
else{
vector<vector<char> > a(n, vector<char>(m, '-'));
int cnt = m/2 + 1;
int limit = n - (n/2 + 1);
priority_queue<pair<int, int> > pq;
for(int i = 0; i < m; i++){
if(limit == 0) break;
pq.push(mp(0LL, i));
}
for(int j = 0; j < n; j++){
for(int i = 0; i < cnt; i++){
if(!pq.size()) break;
int xc = pq.top().first * (-1), pos = pq.top().second;
a[j][pos] = '+';
xc++;
pq.pop();
if(xc < limit) pq.push(mp(xc * (-1), pos));
}
}
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
cout<<a[i][j];
}
cout<<endl;
}
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
6 ms |
348 KB |
Output is correct |
4 |
Correct |
10 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
67 ms |
1364 KB |
Output is correct |
2 |
Correct |
45 ms |
1876 KB |
Output is correct |
3 |
Correct |
42 ms |
1992 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
1360 KB |
Output is correct |
2 |
Correct |
41 ms |
1616 KB |
Output is correct |
3 |
Correct |
37 ms |
1368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
6 ms |
348 KB |
Output is correct |
4 |
Correct |
10 ms |
344 KB |
Output is correct |
5 |
Correct |
67 ms |
1364 KB |
Output is correct |
6 |
Correct |
45 ms |
1876 KB |
Output is correct |
7 |
Correct |
42 ms |
1992 KB |
Output is correct |
8 |
Correct |
54 ms |
1360 KB |
Output is correct |
9 |
Correct |
41 ms |
1616 KB |
Output is correct |
10 |
Correct |
37 ms |
1368 KB |
Output is correct |
11 |
Correct |
25 ms |
704 KB |
Output is correct |
12 |
Correct |
47 ms |
1468 KB |
Output is correct |
13 |
Correct |
43 ms |
1356 KB |
Output is correct |
14 |
Correct |
31 ms |
1212 KB |
Output is correct |
15 |
Correct |
48 ms |
2240 KB |
Output is correct |
16 |
Correct |
38 ms |
1880 KB |
Output is correct |
17 |
Correct |
17 ms |
1116 KB |
Output is correct |