#include <bits/stdc++.h>
using namespace std;
template<class T, class U>
void ckmin(T &a, U b)
{
if (a > b) a = b;
}
template<class T, class U>
void ckmax(T &a, U b)
{
if (a < b) a = b;
}
#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)
#define SZ(x) ((int) ((x).size()))
#define ALL(x) (x).begin(), (x).end()
#define MAXN 1013
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
int TC;
int N, M;
int A, B;
bitset<MAXN> ans[MAXN];
deque<pii> rem;
int32_t main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> TC;
while(TC--)
{
FOR(i, 0, N)
{
FOR(j, 0, M)
{
ans[i][j] = false;
}
}
rem.clear();
cin >> N >> M;
A = 0; B = 0;
FOR(i, 0, N + 1)
{
//say there are i rows that have more +s than -s.
//then there are i rows with (M / 2 + 1) +s, N - i rows with 0 +s
int lo = 0, hi = M;
while(hi > lo)
{
int mid = (hi + lo + 1) >> 1; //can we get mid columns with a majority of -s?
int tot = (M / 2 + 1) * i;
FOR(j, 0, M - mid)
{
tot -= i;
}
FOR(j, 0, mid)
{
tot -= ((N - 1) / 2);
}
if (tot <= 0) lo = mid;
else hi = mid - 1;
//try checking mid
}
if (lo + i > A + B)
{
A = i;
B = lo;
}
}
cout << A + B << '\n';
//now actually construct the grid!
FOR(i, 0, A)
{
FOR(j, B, M)
{
ans[i][j] = true;
}
rem.PB({i, (M / 2 + 1) - (M - B)});
}
//now you just need to do the remaining stuff!
FOR(i, 0, B)
{
FOR(j, 0, (N - 1) / 2)
{
if (rem.back().se <= 0) break;
pii p = rem.back(); rem.pop_back();
p.se--;
ans[p.fi][i] = true;
rem.push_front(p);
}
}
//for the remaining columns
FOR(i, 0, N)
{
FOR(j, 0, M)
{
cout << (ans[i][j] ? '+' : '-');
}
cout << '\n';
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
4 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
1460 KB |
Output is correct |
2 |
Correct |
32 ms |
1364 KB |
Output is correct |
3 |
Correct |
31 ms |
1364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
1524 KB |
Output is correct |
2 |
Correct |
30 ms |
1272 KB |
Output is correct |
3 |
Correct |
28 ms |
1180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
4 ms |
376 KB |
Output is correct |
5 |
Correct |
38 ms |
1460 KB |
Output is correct |
6 |
Correct |
32 ms |
1364 KB |
Output is correct |
7 |
Correct |
31 ms |
1364 KB |
Output is correct |
8 |
Correct |
41 ms |
1524 KB |
Output is correct |
9 |
Correct |
30 ms |
1272 KB |
Output is correct |
10 |
Correct |
28 ms |
1180 KB |
Output is correct |
11 |
Correct |
11 ms |
552 KB |
Output is correct |
12 |
Correct |
28 ms |
1144 KB |
Output is correct |
13 |
Correct |
30 ms |
1300 KB |
Output is correct |
14 |
Correct |
23 ms |
1048 KB |
Output is correct |
15 |
Correct |
34 ms |
1528 KB |
Output is correct |
16 |
Correct |
26 ms |
1144 KB |
Output is correct |
17 |
Correct |
14 ms |
760 KB |
Output is correct |