# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
407439 |
2021-05-19T00:39:12 Z |
534351 |
Cigle (COI21_cigle) |
C++17 |
|
368 ms |
67472 KB |
#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()
const int MAXN = 5013;
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 N;
int arr[MAXN], pref[MAXN];
int dp[MAXN][MAXN];
int ans;
int fen[MAXN];
void update(int idx, int i)
{
for (int e = idx + 1; e <= i; e += e & (-e))
{
fen[e]++;
}
}
int query(int idx)
{
int res = 0;
for (int e = idx + 1; e; e -= e & (-e))
{
res += fen[e];
}
return res;
}
int32_t main()
{
ios_base::sync_with_stdio(false); cin.tie(0);
cout << fixed << setprecision(12);
cerr << fixed << setprecision(4);
cin >> N;
FOR(i, 0, N)
{
cin >> arr[i];
pref[i + 1] = pref[i] + arr[i];
}
// dp[0][0] = 0;
FOR(i, 2, N + 1)
{
fill(fen, fen + N + 2, 0);
set<int> cands;
int best = 0;
FOR(j, 1, i)
{
ckmax(dp[j][i - 1], dp[j - 1][i - 1]);
}
best = dp[i - 1][i - 1];
int iter = i - 1;
FOR(j, i, N + 1)
{
dp[i][j] = best;
int c = 2 * pref[i - 1] - pref[j];
while(iter != 0 && pref[iter] > c)
{
iter--;
}
if (pref[iter] == c)
{
update(i - iter, i);
ckmax(best, dp[iter][i - 1] + query(i - iter));
}
}
}
FOR(i, 1, N + 1)
{
ckmax(ans, dp[i][N]);
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
588 KB |
Output is correct |
11 |
Correct |
1 ms |
588 KB |
Output is correct |
12 |
Correct |
1 ms |
588 KB |
Output is correct |
13 |
Correct |
1 ms |
588 KB |
Output is correct |
14 |
Correct |
1 ms |
588 KB |
Output is correct |
15 |
Correct |
1 ms |
588 KB |
Output is correct |
16 |
Correct |
1 ms |
588 KB |
Output is correct |
17 |
Correct |
1 ms |
588 KB |
Output is correct |
18 |
Correct |
1 ms |
588 KB |
Output is correct |
19 |
Correct |
1 ms |
588 KB |
Output is correct |
20 |
Correct |
1 ms |
588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2764 KB |
Output is correct |
2 |
Correct |
3 ms |
2764 KB |
Output is correct |
3 |
Correct |
3 ms |
2764 KB |
Output is correct |
4 |
Correct |
3 ms |
2764 KB |
Output is correct |
5 |
Correct |
3 ms |
2764 KB |
Output is correct |
6 |
Correct |
4 ms |
2764 KB |
Output is correct |
7 |
Correct |
4 ms |
2764 KB |
Output is correct |
8 |
Correct |
4 ms |
2764 KB |
Output is correct |
9 |
Correct |
4 ms |
2704 KB |
Output is correct |
10 |
Correct |
3 ms |
2764 KB |
Output is correct |
11 |
Correct |
3 ms |
2764 KB |
Output is correct |
12 |
Correct |
3 ms |
2764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
588 KB |
Output is correct |
11 |
Correct |
1 ms |
588 KB |
Output is correct |
12 |
Correct |
1 ms |
588 KB |
Output is correct |
13 |
Correct |
1 ms |
588 KB |
Output is correct |
14 |
Correct |
1 ms |
588 KB |
Output is correct |
15 |
Correct |
1 ms |
588 KB |
Output is correct |
16 |
Correct |
1 ms |
588 KB |
Output is correct |
17 |
Correct |
1 ms |
588 KB |
Output is correct |
18 |
Correct |
1 ms |
588 KB |
Output is correct |
19 |
Correct |
1 ms |
588 KB |
Output is correct |
20 |
Correct |
1 ms |
588 KB |
Output is correct |
21 |
Correct |
3 ms |
2764 KB |
Output is correct |
22 |
Correct |
3 ms |
2764 KB |
Output is correct |
23 |
Correct |
3 ms |
2764 KB |
Output is correct |
24 |
Correct |
3 ms |
2764 KB |
Output is correct |
25 |
Correct |
3 ms |
2764 KB |
Output is correct |
26 |
Correct |
4 ms |
2764 KB |
Output is correct |
27 |
Correct |
4 ms |
2764 KB |
Output is correct |
28 |
Correct |
4 ms |
2764 KB |
Output is correct |
29 |
Correct |
4 ms |
2704 KB |
Output is correct |
30 |
Correct |
3 ms |
2764 KB |
Output is correct |
31 |
Correct |
3 ms |
2764 KB |
Output is correct |
32 |
Correct |
3 ms |
2764 KB |
Output is correct |
33 |
Correct |
3 ms |
2764 KB |
Output is correct |
34 |
Correct |
3 ms |
2892 KB |
Output is correct |
35 |
Correct |
3 ms |
2764 KB |
Output is correct |
36 |
Correct |
3 ms |
2800 KB |
Output is correct |
37 |
Correct |
4 ms |
2708 KB |
Output is correct |
38 |
Correct |
4 ms |
2816 KB |
Output is correct |
39 |
Correct |
3 ms |
2764 KB |
Output is correct |
40 |
Correct |
3 ms |
2764 KB |
Output is correct |
41 |
Correct |
3 ms |
2764 KB |
Output is correct |
42 |
Correct |
3 ms |
2764 KB |
Output is correct |
43 |
Correct |
3 ms |
2740 KB |
Output is correct |
44 |
Correct |
3 ms |
2764 KB |
Output is correct |
45 |
Correct |
3 ms |
2764 KB |
Output is correct |
46 |
Correct |
3 ms |
2764 KB |
Output is correct |
47 |
Correct |
3 ms |
2764 KB |
Output is correct |
48 |
Correct |
3 ms |
2764 KB |
Output is correct |
49 |
Correct |
3 ms |
2764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
588 KB |
Output is correct |
11 |
Correct |
1 ms |
588 KB |
Output is correct |
12 |
Correct |
1 ms |
588 KB |
Output is correct |
13 |
Correct |
1 ms |
588 KB |
Output is correct |
14 |
Correct |
1 ms |
588 KB |
Output is correct |
15 |
Correct |
1 ms |
588 KB |
Output is correct |
16 |
Correct |
1 ms |
588 KB |
Output is correct |
17 |
Correct |
1 ms |
588 KB |
Output is correct |
18 |
Correct |
1 ms |
588 KB |
Output is correct |
19 |
Correct |
1 ms |
588 KB |
Output is correct |
20 |
Correct |
1 ms |
588 KB |
Output is correct |
21 |
Correct |
3 ms |
2764 KB |
Output is correct |
22 |
Correct |
3 ms |
2764 KB |
Output is correct |
23 |
Correct |
3 ms |
2764 KB |
Output is correct |
24 |
Correct |
3 ms |
2764 KB |
Output is correct |
25 |
Correct |
3 ms |
2764 KB |
Output is correct |
26 |
Correct |
4 ms |
2764 KB |
Output is correct |
27 |
Correct |
4 ms |
2764 KB |
Output is correct |
28 |
Correct |
4 ms |
2764 KB |
Output is correct |
29 |
Correct |
4 ms |
2704 KB |
Output is correct |
30 |
Correct |
3 ms |
2764 KB |
Output is correct |
31 |
Correct |
3 ms |
2764 KB |
Output is correct |
32 |
Correct |
3 ms |
2764 KB |
Output is correct |
33 |
Correct |
3 ms |
2764 KB |
Output is correct |
34 |
Correct |
3 ms |
2892 KB |
Output is correct |
35 |
Correct |
3 ms |
2764 KB |
Output is correct |
36 |
Correct |
3 ms |
2800 KB |
Output is correct |
37 |
Correct |
4 ms |
2708 KB |
Output is correct |
38 |
Correct |
4 ms |
2816 KB |
Output is correct |
39 |
Correct |
3 ms |
2764 KB |
Output is correct |
40 |
Correct |
3 ms |
2764 KB |
Output is correct |
41 |
Correct |
3 ms |
2764 KB |
Output is correct |
42 |
Correct |
3 ms |
2764 KB |
Output is correct |
43 |
Correct |
3 ms |
2740 KB |
Output is correct |
44 |
Correct |
3 ms |
2764 KB |
Output is correct |
45 |
Correct |
3 ms |
2764 KB |
Output is correct |
46 |
Correct |
3 ms |
2764 KB |
Output is correct |
47 |
Correct |
3 ms |
2764 KB |
Output is correct |
48 |
Correct |
3 ms |
2764 KB |
Output is correct |
49 |
Correct |
3 ms |
2764 KB |
Output is correct |
50 |
Correct |
303 ms |
67292 KB |
Output is correct |
51 |
Correct |
299 ms |
67328 KB |
Output is correct |
52 |
Correct |
303 ms |
67340 KB |
Output is correct |
53 |
Correct |
321 ms |
67308 KB |
Output is correct |
54 |
Correct |
307 ms |
67268 KB |
Output is correct |
55 |
Correct |
305 ms |
67380 KB |
Output is correct |
56 |
Correct |
368 ms |
67340 KB |
Output is correct |
57 |
Correct |
347 ms |
67376 KB |
Output is correct |
58 |
Correct |
277 ms |
67344 KB |
Output is correct |
59 |
Correct |
254 ms |
67240 KB |
Output is correct |
60 |
Correct |
242 ms |
67372 KB |
Output is correct |
61 |
Correct |
230 ms |
67268 KB |
Output is correct |
62 |
Correct |
218 ms |
67472 KB |
Output is correct |
63 |
Correct |
210 ms |
67268 KB |
Output is correct |
64 |
Correct |
210 ms |
67352 KB |
Output is correct |
65 |
Correct |
213 ms |
67448 KB |
Output is correct |
66 |
Correct |
215 ms |
67244 KB |
Output is correct |
67 |
Correct |
202 ms |
67288 KB |
Output is correct |
68 |
Correct |
210 ms |
67412 KB |
Output is correct |
69 |
Correct |
206 ms |
67260 KB |
Output is correct |
70 |
Correct |
236 ms |
67288 KB |
Output is correct |
71 |
Correct |
242 ms |
67268 KB |
Output is correct |
72 |
Correct |
228 ms |
67268 KB |
Output is correct |