#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <bitset>
#include <unordered_map>
#include <stack>
#include <random>
using namespace std;
const int N = 1003, M = 103;
const int mod = 1e9 + 7;
int n, m;
int calc(int a, int b, int np)
{
return a - (np * a + b - 1) / b;
}
bool check(int a, int b)
{
if (a * b == 0)
return true;
int np = max(0, m / 2 + 1 - (m - b));
int nm = max(0, n / 2 + 1 - (n - a));
//cout << a << ' ' << b << endl << np << ' ' << nm << ' ' << calc(a, b, np) << endl;
return nm <= calc(a, b, np);
}
bool ans[N][N];
void answ(int a, int b)
{
int np = max(0, m / 2 + 1 - (m - b));
int r = -1, l = 0;
for (int i = 0; i < a * np; i++)
{
r += i % np == 0;
ans[r][l] = true;
l++;
l %= b;
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
if (i >= a)
cout << '-';
else if (j >= b)
cout << '+';
else
cout << (ans[i][j] ? '+' : '-');
}
cout << endl;
}
for (int i = 0; i < a; i++)
{
for (int j = 0; j < b; j++)
ans[i][j] = false;
}
}
void solve()
{
cin >> n >> m;
int a = 0, b = 0;
for (int i = n; i >= 0; i--)
{
for (int j = m; j >= 0; j--)
{
if (!check(i, j))
continue;
if (i + j > a + b)
{
a = i;
b = j;
}
}
}
cout << a + b << endl;
answ(a, b);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cout.precision(9);
cout << fixed;
int q = 1;
cin >> q;
while (q--)
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
6 ms |
388 KB |
Output is correct |
4 |
Correct |
11 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
1432 KB |
Output is correct |
2 |
Correct |
29 ms |
1888 KB |
Output is correct |
3 |
Correct |
38 ms |
1984 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
1400 KB |
Output is correct |
2 |
Correct |
27 ms |
1744 KB |
Output is correct |
3 |
Correct |
25 ms |
1516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
6 ms |
388 KB |
Output is correct |
4 |
Correct |
11 ms |
332 KB |
Output is correct |
5 |
Correct |
54 ms |
1432 KB |
Output is correct |
6 |
Correct |
29 ms |
1888 KB |
Output is correct |
7 |
Correct |
38 ms |
1984 KB |
Output is correct |
8 |
Correct |
47 ms |
1400 KB |
Output is correct |
9 |
Correct |
27 ms |
1744 KB |
Output is correct |
10 |
Correct |
25 ms |
1516 KB |
Output is correct |
11 |
Correct |
23 ms |
520 KB |
Output is correct |
12 |
Correct |
31 ms |
1788 KB |
Output is correct |
13 |
Correct |
29 ms |
1924 KB |
Output is correct |
14 |
Correct |
26 ms |
1672 KB |
Output is correct |
15 |
Correct |
35 ms |
2232 KB |
Output is correct |
16 |
Correct |
24 ms |
1724 KB |
Output is correct |
17 |
Correct |
11 ms |
1228 KB |
Output is correct |