#include <bits/stdc++.h>
using namespace std;
#define int long long
#define MOD 998244353
#define INF 1000000000000000000
#define EPS 1e-10
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t;
cin >> t;
while(t--) {
int n, m, ans = 0;
bool swp = false;
cin >> n >> m;
if(n > m) {
swap(n, m);
swp = true;
}
int a[n][m], idx = 0, cnt = 0, num = (n-ceil((n+1)/2.0))*m;
memset(a, 0, sizeof(a));
for(int i = 0; i < n;) {
for(int j = 0; j < m/2+1; j++) {
if(cnt == num) goto nxt;
a[i][idx] = 1; // red
idx = (idx+1)%m;
cnt++;
if(j == m/2) i++;
}
}
nxt:;
for(int i = 0; i < n; i++) {
cnt = 0;
for(int j = 0; j < m; j++) {
if(a[i][j] == 1) cnt++;
}
if(cnt > m-cnt) ans++;
}
for(int j = 0; j < m; j++) {
cnt = 0;
for(int i = 0; i < n; i++) {
if(a[i][j] == 0) cnt++;
}
if(cnt > n-cnt) ans++;
}
cout << ans << '\n';
if(swp) {
for(int j = 0; j < m; j++) {
for(int i = 0; i < n; i++) {
if(a[i][j] == 1) cout << '-';
else cout << '+';
}
cout << '\n';
}
} else {
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
if(a[i][j] == 1) cout << '+';
else cout << '-';
}
cout << '\n';
}
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
1320 KB |
Output is correct |
2 |
Correct |
36 ms |
6308 KB |
Output is correct |
3 |
Correct |
25 ms |
6740 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
1440 KB |
Output is correct |
2 |
Correct |
22 ms |
5068 KB |
Output is correct |
3 |
Correct |
21 ms |
3520 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
35 ms |
1320 KB |
Output is correct |
6 |
Correct |
36 ms |
6308 KB |
Output is correct |
7 |
Correct |
25 ms |
6740 KB |
Output is correct |
8 |
Correct |
30 ms |
1440 KB |
Output is correct |
9 |
Correct |
22 ms |
5068 KB |
Output is correct |
10 |
Correct |
21 ms |
3520 KB |
Output is correct |
11 |
Correct |
7 ms |
456 KB |
Output is correct |
12 |
Correct |
30 ms |
4384 KB |
Output is correct |
13 |
Correct |
28 ms |
3520 KB |
Output is correct |
14 |
Correct |
18 ms |
2424 KB |
Output is correct |
15 |
Correct |
35 ms |
9036 KB |
Output is correct |
16 |
Correct |
22 ms |
6760 KB |
Output is correct |
17 |
Correct |
11 ms |
3148 KB |
Output is correct |