#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
const int N = 1e3 + 5;
priority_queue <pair <int, int>> q;
char jog[N][N], jog1[N][N];
int main() {
// freopen ("input.txt", "r", stdin);
int t;
cin >> t;
while ( t-- ) {
int n, m;
cin >> n >> m;
// cout << "test cases : " << n << " " << m << endl;
bool tr = 0;
if (n < m) {
swap (n, m);
tr = 1;
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
jog[i][j] = '+';
}
}
int a = n / 2 + 1;
int b = (m - 1) / 2;
int ans = n + ((n * b) / a);
for (int i = 1; i <= n; ++i) {
if (b) q.push({b, i});
}
for (int i = 1; i <= ans; ++i) {
for (int j = 1; j <= a; ++j) {
if (q.empty()) break;
pair <int, int> x = q.top();
q.pop();
jog[x.ss][i] = '-';
if (x.ff > 1) {
q.push ({x.ff - 1, x.ss});
}
}
if (q.empty()) break;
}
if (tr) {
for (int i = 1; i <= n; ++i) {
for (int j = m; j > 0; j--) {
if (jog[i][j] == '-') jog[i][j] = '+';
else jog[i][j] = '-';
}
}
int l1 = 1, r1 = m;
for (int i = 1; i <= m; ++i) {
for (int j = 1; j <= n; ++j) {
jog1[i][j] = jog[l1][r1];
l1++;
}
l1 = 1;
r1--;
cout << endl;
}
if (tr) swap (n, m);
}
else {
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
jog1[i][j] = jog[i][j];
}
}
}
//
// int row = 0, column = 0;
// for (int i = 1; i <= n; ++i) {
// int x = 0;
// for (int j = 1; j <= m; ++j) {
// if (jog1[i][j] == '+') x++;
// else x--;
// }
// if (x > 0) row++;
// }
// for (int i = 1; i <= m; i++) {
// int x = 0;
// for (int j = 1; j <= n; ++j) {
// if (jog1[j][i] == '-') x++;
// else x--;
// }
// if (x > 0) column++;
// }
// int tt = row + column;
//
cout << ans << endl;
// if (ans != tt) {
// cout << "men : " << row << " " << column << " " << tt << "\n";
// }
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
cout << jog1[i][j];
}
cout << endl;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
6 ms |
348 KB |
Output is correct |
4 |
Correct |
11 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
1616 KB |
Output is correct |
2 |
Correct |
51 ms |
2896 KB |
Output is correct |
3 |
Correct |
47 ms |
3116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
1880 KB |
Output is correct |
2 |
Correct |
46 ms |
2576 KB |
Output is correct |
3 |
Correct |
40 ms |
2128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
6 ms |
348 KB |
Output is correct |
4 |
Correct |
11 ms |
344 KB |
Output is correct |
5 |
Correct |
76 ms |
1616 KB |
Output is correct |
6 |
Correct |
51 ms |
2896 KB |
Output is correct |
7 |
Correct |
47 ms |
3116 KB |
Output is correct |
8 |
Correct |
59 ms |
1880 KB |
Output is correct |
9 |
Correct |
46 ms |
2576 KB |
Output is correct |
10 |
Correct |
40 ms |
2128 KB |
Output is correct |
11 |
Correct |
29 ms |
604 KB |
Output is correct |
12 |
Correct |
43 ms |
2612 KB |
Output is correct |
13 |
Correct |
47 ms |
2896 KB |
Output is correct |
14 |
Correct |
36 ms |
2396 KB |
Output is correct |
15 |
Correct |
53 ms |
3156 KB |
Output is correct |
16 |
Correct |
42 ms |
2788 KB |
Output is correct |
17 |
Correct |
18 ms |
1976 KB |
Output is correct |