//Challenge: Accepted
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <stack>
#include <set>
#include <assert.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
void debug() {cout << endl;}
template <class T, class ...U> void debug(T a, U ... b) { cout << a << " "; debug(b...);}
template <class T> void pary(T l, T r) {
while (l != r) {cout << *l << " ";l++;}
cout << endl;
}
#define ll long long
#define maxn 1005
#define mod 1000000007
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
bool ans[maxn][maxn];
int main() {
io
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
pii best = {0, 0};
for (int a = 0;a <= n;a++) {
for (int b = 0;b <= m;b++) {
bool poss = 0;
if (a == 0 || b == 0) poss = 1;
else {
int x = m / 2 + 1 - (m - b), y = (a - (n / 2 + 1 - (n - a))); // >= x per row, <= y per col
if ((a * x + b - 1) / b <= y) {
//debug(a, b, x, y);
poss = 1;
}
}
if (poss) {
if (a + b > best.ff + best.ss) {
best = make_pair(a, b);
}
}
}
}
cout << best.ff + best.ss << "\n";
for (int i = 0;i < maxn;i++) {
for (int j = 0;j < maxn;j++) ans[i][j] = 0;
}
for (int i = 0;i < best.ff;i++) {
for (int j = best.ss;j < m;j++) ans[i][j] = 1;
}
int x = m / 2 + 1 - (m - best.ss);
for (int i = 0;i < best.ff * x;i++) {
ans[i / x][i % best.ss] = 1;
}
for (int i = 0;i < n;i++) {
for (int j = 0;j < m;j++) cout << (ans[i][j] ? '+' : '-');
cout << "\n";
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1228 KB |
Output is correct |
2 |
Correct |
2 ms |
1228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
1312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1228 KB |
Output is correct |
2 |
Correct |
2 ms |
1228 KB |
Output is correct |
3 |
Correct |
13 ms |
1312 KB |
Output is correct |
4 |
Correct |
20 ms |
1328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
2272 KB |
Output is correct |
2 |
Correct |
40 ms |
2148 KB |
Output is correct |
3 |
Correct |
39 ms |
2132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
2244 KB |
Output is correct |
2 |
Correct |
37 ms |
2112 KB |
Output is correct |
3 |
Correct |
35 ms |
1988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1228 KB |
Output is correct |
2 |
Correct |
2 ms |
1228 KB |
Output is correct |
3 |
Correct |
13 ms |
1312 KB |
Output is correct |
4 |
Correct |
20 ms |
1328 KB |
Output is correct |
5 |
Correct |
59 ms |
2272 KB |
Output is correct |
6 |
Correct |
40 ms |
2148 KB |
Output is correct |
7 |
Correct |
39 ms |
2132 KB |
Output is correct |
8 |
Correct |
49 ms |
2244 KB |
Output is correct |
9 |
Correct |
37 ms |
2112 KB |
Output is correct |
10 |
Correct |
35 ms |
1988 KB |
Output is correct |
11 |
Correct |
42 ms |
1508 KB |
Output is correct |
12 |
Correct |
36 ms |
2020 KB |
Output is correct |
13 |
Correct |
37 ms |
1984 KB |
Output is correct |
14 |
Correct |
28 ms |
1860 KB |
Output is correct |
15 |
Correct |
45 ms |
2192 KB |
Output is correct |
16 |
Correct |
33 ms |
1940 KB |
Output is correct |
17 |
Correct |
16 ms |
1580 KB |
Output is correct |