#include <bits/stdc++.h>
using namespace std;
int score(const vector<vector<int>> &a, int plus) {
int tr = a[0].size()/2 + 1, tc = a.size()/2 + 1;
int ret = 0;
for (int i=0; i<(int)a.size(); i++) {
int cnt = 0;
for (int c : a[i]) cnt += (c == plus);
ret += (cnt >= tr);
}
for (int j=0; j<(int)a[0].size(); j++) {
int cnt = 0;
for (int i=0; i<(int)a.size(); i++) {
cnt += (a[i][j] != plus);
}
ret += (cnt >= tc);
}
return ret;
}
vector<vector<int>> transpose(const vector<vector<int>> &a) {
int n = a.size(), m = a[0].size();
vector<vector<int>> ret(m, vector<int>(n));
for (int i=0; i<n; i++) {
for (int j=0; j<m; j++) {
ret[j][i] = a[i][j];
}
}
return ret;
}
vector<vector<int>> build(int n, int m, int plus) {
int tr = m - (m/2 + 1), tc = n/2 + 1;
vector<vector<int>> ret(n, vector<int>(m, plus));
for (int i=0, j=0, c=0; j<m && c<tr*n; j++) {
for (int k=0; k<tc && c<tr*n; k++, i=(i+1 == n ? 0 : i+1), c++) {
ret[i][j] = plus^1;
}
}
return ret;
}
void solve() {
int n, m;
cin >> n >> m;
auto ans1 = build(n, m, 0), ans2 = build(m, n, 1);
int score1 = score(ans1, 0), score2 = score(ans2, 1);
if (score2 > score1) {
swap(score2, score1);
ans1 = transpose(ans2);
}
cout << score1 << '\n';
for (int i=0; i<n; i++) {
for (int j=0; j<m; j++) {
cout << (ans1[i][j] ? '-' : '+');
}
cout << '\n';
}
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int tcs;
cin >> tcs;
while (tcs--) {
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 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 |
324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
1456 KB |
Output is correct |
2 |
Correct |
25 ms |
8844 KB |
Output is correct |
3 |
Correct |
23 ms |
6864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
1588 KB |
Output is correct |
2 |
Correct |
22 ms |
4984 KB |
Output is correct |
3 |
Correct |
19 ms |
3484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
324 KB |
Output is correct |
5 |
Correct |
26 ms |
1456 KB |
Output is correct |
6 |
Correct |
25 ms |
8844 KB |
Output is correct |
7 |
Correct |
23 ms |
6864 KB |
Output is correct |
8 |
Correct |
22 ms |
1588 KB |
Output is correct |
9 |
Correct |
22 ms |
4984 KB |
Output is correct |
10 |
Correct |
19 ms |
3484 KB |
Output is correct |
11 |
Correct |
7 ms |
584 KB |
Output is correct |
12 |
Correct |
24 ms |
4476 KB |
Output is correct |
13 |
Correct |
20 ms |
3336 KB |
Output is correct |
14 |
Correct |
16 ms |
2536 KB |
Output is correct |
15 |
Correct |
24 ms |
9120 KB |
Output is correct |
16 |
Correct |
20 ms |
9688 KB |
Output is correct |
17 |
Correct |
8 ms |
3156 KB |
Output is correct |