#include <bits/stdc++.h>
using namespace std;
int main()
{
int q;
cin >> q;
while(q--){
int n , m , ans , z;
cin >> n >> m;
char a[n][m];
if(n <= m){
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
a[i][j] = '-';
}
}
ans = m;
vector<pair<int,int>> v(m);
for(int i = 0; i < m; i++){
v[i].second = i;
}
int k[m];
for(int i = 0; i < m + 1; i++){
k[i] = n;
}
for(int line = 0; line < n; line++){
sort(v.begin(), v.end());
for(int l = 0; l < m / 2 + 1; l++){
if(k[v[l].second] - 1 > n / 2){
v[l].first++;
k[v[l].second]--;
a[line][v[l].second] = '+';
}
}
}
for(int i = 0; i < n; i++){
z = 0;
for(int j = 0; j < m; j++){
if(a[i][j] == '+') z++;
}
if(z > m / 2) ans++;
}
cout << ans << endl;
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
cout << a[i][j];
}
cout << endl;
}
} else {
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
a[i][j] = '+';
}
}
ans = n;
vector<pair<int,int>> v(n);
for(int i = 0; i < n; i++){
v[i].second = i;
}
int k[n];
for(int i = 0; i < n + 1; i++){
k[i] = m;
}
for(int line = 0; line < m; line++){
sort(v.begin(), v.end());
for(int l = 0; l < n / 2 + 1; l++){
if(k[v[l].second] - 1 > m / 2){
v[l].first++;
k[v[l].second]--;
a[v[l].second][line] = '-';
}
}
}
for(int i = 0; i < m; i++){
z = 0;
for(int j = 0; j < n; j++){
if(a[j][i] == '-') z++;
}
if(z > n / 2) ans++;
}
cout << ans << endl;
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 |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
15 ms |
376 KB |
Output is correct |
4 |
Correct |
25 ms |
632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
114 ms |
1400 KB |
Output is correct |
2 |
Correct |
60 ms |
1912 KB |
Output is correct |
3 |
Correct |
60 ms |
1912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
85 ms |
1400 KB |
Output is correct |
2 |
Correct |
56 ms |
1760 KB |
Output is correct |
3 |
Correct |
51 ms |
1400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
15 ms |
376 KB |
Output is correct |
4 |
Correct |
25 ms |
632 KB |
Output is correct |
5 |
Correct |
114 ms |
1400 KB |
Output is correct |
6 |
Correct |
60 ms |
1912 KB |
Output is correct |
7 |
Correct |
60 ms |
1912 KB |
Output is correct |
8 |
Correct |
85 ms |
1400 KB |
Output is correct |
9 |
Correct |
56 ms |
1760 KB |
Output is correct |
10 |
Correct |
51 ms |
1400 KB |
Output is correct |
11 |
Correct |
54 ms |
504 KB |
Output is correct |
12 |
Correct |
57 ms |
1528 KB |
Output is correct |
13 |
Correct |
61 ms |
1500 KB |
Output is correct |
14 |
Correct |
46 ms |
1124 KB |
Output is correct |
15 |
Correct |
64 ms |
2396 KB |
Output is correct |
16 |
Correct |
48 ms |
1784 KB |
Output is correct |
17 |
Correct |
25 ms |
1016 KB |
Output is correct |