#include <bits/stdc++.h>
using namespace std;
vector <vector <char>> a;
int main(){
ios::sync_with_stdio(false); cin.tie(nullptr);
int T;
cin >> T;
while(T--){
int n, m;
cin >> n >> m;
if(n >= m){
a.assign(n, vector <char> (m,'+'));
vector <int> vis(n,0), v;
int x = 0;
for(int j = 0; j < m; j++){
int cnt = (n/2 + 1);
v.clear();
while(cnt--){
v.push_back(x);
// cout << x << " ";
x++;
x %= n;
}
// cout << '\n';
bool tr = 0;
// cout << (int)v.size() << ' ';
for(int i = 0; i < (int)v.size(); i++){
vis[v[i]]++;
// cout << i << " ";
if(vis[v[i]] > (m-(m/2 + 1))){
tr = 1;
break;
}
}
// cout << "\n";
if(tr == 1){
break;
}
for(int i = 0; i < (int)v.size(); i++){
a[v[i]][j] = '-';
}
}
}
else {
a.assign(n, vector <char> (m,'-'));
vector <int> vis(m,0), v;
int x = 0;
for(int j = 0; j < n; j++){
int cnt = (m/2 + 1);
v.clear();
while(cnt--){
v.push_back(x);
x++;
x %= m;
}
bool tr = 0;
for(auto i : v){
vis[i]++;
if(vis[i] > (n-(n/2 + 1))){
tr = 1;
break;
}
}
if(tr == 1) break;
for(auto i : v){
a[j][i] = '+';
}
}
}
int ans = 0;
for(int i = 0; i < n; i++){
int a1 = 0, b1 = 0;
for(int j = 0; j < m; j++){
if(a[i][j] == '+') a1++;
else b1++;
}
ans += (a1 > b1);
}
for(int j = 0; j < m; j++){
int a1 = 0, b1 = 0;
for(int i = 0; i < n; i++){
if(a[i][j] == '+') a1++;
else b1++;
}
ans += (b1 > a1);
}
cout << ans << '\n';
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
cout << a[i][j];
}
cout << '\n';
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
352 KB |
Output is correct |
2 |
Correct |
0 ms |
452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
352 KB |
Output is correct |
2 |
Correct |
0 ms |
452 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
1364 KB |
Output is correct |
2 |
Correct |
20 ms |
1884 KB |
Output is correct |
3 |
Correct |
19 ms |
1884 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
1348 KB |
Output is correct |
2 |
Correct |
18 ms |
1624 KB |
Output is correct |
3 |
Correct |
17 ms |
1628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
352 KB |
Output is correct |
2 |
Correct |
0 ms |
452 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
22 ms |
1364 KB |
Output is correct |
6 |
Correct |
20 ms |
1884 KB |
Output is correct |
7 |
Correct |
19 ms |
1884 KB |
Output is correct |
8 |
Correct |
22 ms |
1348 KB |
Output is correct |
9 |
Correct |
18 ms |
1624 KB |
Output is correct |
10 |
Correct |
17 ms |
1628 KB |
Output is correct |
11 |
Correct |
6 ms |
600 KB |
Output is correct |
12 |
Correct |
18 ms |
1788 KB |
Output is correct |
13 |
Correct |
19 ms |
1628 KB |
Output is correct |
14 |
Correct |
14 ms |
1184 KB |
Output is correct |
15 |
Correct |
22 ms |
2392 KB |
Output is correct |
16 |
Correct |
16 ms |
1884 KB |
Output is correct |
17 |
Correct |
7 ms |
1116 KB |
Output is correct |