#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
using namespace std;
void print(vector<vector<char> > &c) {
for(int i = 0; i < sz(c); ++i) {
for(int j = 0; j < sz(c[0]); ++j) {
cout << c[i][j];
}
cout << "\n";
}
}
vector<vector<char>> perfect(int n, int m, int x, int y) {
vector<vector<char> > c(n, vector<char>(m, '-'));
int k = 0;
for(int i = 0; i < n; ++i) {
for(int j = 0; j < y; ++j) {
c[i][k] = '+';
k = (k + 1) % m;
}
}
return c;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
for(int ti = 1; ti <= t; ++ti) {
int n, m;
cin >> n >> m;
int forsaken = 1e7;
int fn = 0, fm = 0;
int fx = 0, fy = 0;
for(int i = 0; i <= n; ++i) {
for(int j = 0; j <= m; ++j) {
int ns = n - i;
int ms = m - j;
int x = max(0, n / 2 + 1 - i);
int y = max(0, m / 2 + 1 - j);
if(x * ms + y * ns <= ns * ms) {
if(i + j < forsaken) {
forsaken = i + j;
fn = ns; fm = ms;
fx = x; fy = y;
}
}
}
}
vector<vector<char> > c = perfect(fn, fm, fx, fy);
for(int i = 0; i < fn; ++i) {
for(int j = fm; j < m; ++j) {
c[i].push_back('+');
}
}
for(int i = fn; i < n; ++i) {
c.push_back(vector<char>(m, '-'));
}
cout << n + m - forsaken << "\n";
print(c);
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
1348 KB |
Output is correct |
2 |
Correct |
24 ms |
2252 KB |
Output is correct |
3 |
Correct |
22 ms |
2616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
1260 KB |
Output is correct |
2 |
Correct |
23 ms |
1996 KB |
Output is correct |
3 |
Correct |
22 ms |
1552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Correct |
29 ms |
1348 KB |
Output is correct |
6 |
Correct |
24 ms |
2252 KB |
Output is correct |
7 |
Correct |
22 ms |
2616 KB |
Output is correct |
8 |
Correct |
38 ms |
1260 KB |
Output is correct |
9 |
Correct |
23 ms |
1996 KB |
Output is correct |
10 |
Correct |
22 ms |
1552 KB |
Output is correct |
11 |
Correct |
10 ms |
480 KB |
Output is correct |
12 |
Correct |
19 ms |
1948 KB |
Output is correct |
13 |
Correct |
21 ms |
1512 KB |
Output is correct |
14 |
Correct |
16 ms |
1232 KB |
Output is correct |
15 |
Correct |
27 ms |
3240 KB |
Output is correct |
16 |
Correct |
19 ms |
2508 KB |
Output is correct |
17 |
Correct |
8 ms |
1228 KB |
Output is correct |