# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1091322 |
2024-09-20T14:22:01 Z |
kasdo |
Bouquet (EGOI24_bouquet) |
C++14 |
|
23 ms |
12068 KB |
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define endl '\n'
#define speed cin.tie (0) -> sync_with_stdio (0);ios_base::sync_with_stdio(false);cin.tie(0);
const int maxn = 200005;
int n;
int l[maxn], r[maxn];
int dp[maxn];
int rec(int i, int p)
{
if (i <= 0) return 0;
if (dp[i] != -1) return dp[i];
int ret = max(rec(i - 1, i), rec(i - l[i] - 1, i) + 1);
return dp[i] = ret;
}
int rec2(int i)
{
if (i <= 0) return 0;
if (dp[i] != -1) return dp[i];
int ret = 1;
for(int j=1; j<i; j++)
{
if (j + r[j] < i && i - l[i] > j) ret = max(ret, rec2(j) + 1);
}
return dp[i] = ret;
}
void s1()
{
for(int i=1; i<=maxn-5; i++) dp[i] = -1;
cout<<rec(n, 0)<<endl;
}
void s2()
{
cout<<(n - 1) / (l[1] + 1) + 1<<endl;
}
void s3()
{
for(int i=1; i<=maxn-5; i++) dp[i] = -1;
rec2(n);
int ans = 0;
for(int i=1; i<=n; i++) ans = max(ans, dp[i]);
cout<<ans<<endl;
}
void solve()
{
cin>>n;
bool ok = 1;
for(int i=1; i<=n; i++)
{
cin>>l[i]>>r[i];
ok &= (l[i] == r[i]); ok &= (l[i] == l[1]);
}
if (n <= 1000) s3();
else if (ok) s2();
else s1();
}
signed main ()
{
speed
// freopen("feast.in", "r", stdin);
// freopen("feast.out", "w", stdout);
int _ = 1;
// cin>>_;
while(_--) solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1884 KB |
Output is correct |
2 |
Correct |
14 ms |
4188 KB |
Output is correct |
3 |
Correct |
16 ms |
4700 KB |
Output is correct |
4 |
Correct |
15 ms |
4188 KB |
Output is correct |
5 |
Correct |
16 ms |
4632 KB |
Output is correct |
6 |
Correct |
18 ms |
4972 KB |
Output is correct |
7 |
Correct |
19 ms |
5432 KB |
Output is correct |
8 |
Correct |
20 ms |
5820 KB |
Output is correct |
9 |
Correct |
23 ms |
5716 KB |
Output is correct |
10 |
Correct |
2 ms |
1884 KB |
Output is correct |
11 |
Correct |
2 ms |
1884 KB |
Output is correct |
12 |
Correct |
2 ms |
1884 KB |
Output is correct |
13 |
Correct |
2 ms |
1884 KB |
Output is correct |
14 |
Correct |
1 ms |
2004 KB |
Output is correct |
15 |
Correct |
1 ms |
1884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
4184 KB |
Output is correct |
2 |
Correct |
2 ms |
1880 KB |
Output is correct |
3 |
Correct |
1 ms |
1884 KB |
Output is correct |
4 |
Correct |
20 ms |
12004 KB |
Output is correct |
5 |
Correct |
19 ms |
10584 KB |
Output is correct |
6 |
Correct |
18 ms |
9564 KB |
Output is correct |
7 |
Correct |
17 ms |
9052 KB |
Output is correct |
8 |
Correct |
17 ms |
8608 KB |
Output is correct |
9 |
Correct |
17 ms |
7516 KB |
Output is correct |
10 |
Correct |
16 ms |
7308 KB |
Output is correct |
11 |
Correct |
17 ms |
6744 KB |
Output is correct |
12 |
Correct |
17 ms |
6492 KB |
Output is correct |
13 |
Correct |
17 ms |
6236 KB |
Output is correct |
14 |
Correct |
17 ms |
6384 KB |
Output is correct |
15 |
Correct |
16 ms |
6236 KB |
Output is correct |
16 |
Correct |
18 ms |
6260 KB |
Output is correct |
17 |
Correct |
17 ms |
6268 KB |
Output is correct |
18 |
Correct |
16 ms |
6236 KB |
Output is correct |
19 |
Correct |
17 ms |
6308 KB |
Output is correct |
20 |
Correct |
18 ms |
6480 KB |
Output is correct |
21 |
Correct |
18 ms |
6436 KB |
Output is correct |
22 |
Correct |
19 ms |
6748 KB |
Output is correct |
23 |
Correct |
20 ms |
6748 KB |
Output is correct |
24 |
Correct |
2 ms |
1884 KB |
Output is correct |
25 |
Correct |
2 ms |
1884 KB |
Output is correct |
26 |
Correct |
2 ms |
1884 KB |
Output is correct |
27 |
Correct |
2 ms |
1884 KB |
Output is correct |
28 |
Incorrect |
3 ms |
2064 KB |
Output isn't correct |
29 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1880 KB |
Output is correct |
2 |
Correct |
2 ms |
1880 KB |
Output is correct |
3 |
Correct |
2 ms |
1884 KB |
Output is correct |
4 |
Correct |
2 ms |
1884 KB |
Output is correct |
5 |
Correct |
1 ms |
1884 KB |
Output is correct |
6 |
Correct |
2 ms |
1884 KB |
Output is correct |
7 |
Correct |
2 ms |
1884 KB |
Output is correct |
8 |
Correct |
2 ms |
1884 KB |
Output is correct |
9 |
Correct |
2 ms |
1884 KB |
Output is correct |
10 |
Incorrect |
2 ms |
1884 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
4188 KB |
Output is correct |
2 |
Correct |
2 ms |
1884 KB |
Output is correct |
3 |
Correct |
20 ms |
12068 KB |
Output is correct |
4 |
Correct |
19 ms |
10632 KB |
Output is correct |
5 |
Correct |
19 ms |
10580 KB |
Output is correct |
6 |
Correct |
20 ms |
11980 KB |
Output is correct |
7 |
Incorrect |
21 ms |
10584 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1884 KB |
Output is correct |
2 |
Correct |
14 ms |
4188 KB |
Output is correct |
3 |
Correct |
16 ms |
4700 KB |
Output is correct |
4 |
Correct |
15 ms |
4188 KB |
Output is correct |
5 |
Correct |
16 ms |
4632 KB |
Output is correct |
6 |
Correct |
18 ms |
4972 KB |
Output is correct |
7 |
Correct |
19 ms |
5432 KB |
Output is correct |
8 |
Correct |
20 ms |
5820 KB |
Output is correct |
9 |
Correct |
23 ms |
5716 KB |
Output is correct |
10 |
Correct |
2 ms |
1884 KB |
Output is correct |
11 |
Correct |
2 ms |
1884 KB |
Output is correct |
12 |
Correct |
2 ms |
1884 KB |
Output is correct |
13 |
Correct |
2 ms |
1884 KB |
Output is correct |
14 |
Correct |
1 ms |
2004 KB |
Output is correct |
15 |
Correct |
1 ms |
1884 KB |
Output is correct |
16 |
Correct |
21 ms |
4184 KB |
Output is correct |
17 |
Correct |
2 ms |
1880 KB |
Output is correct |
18 |
Correct |
1 ms |
1884 KB |
Output is correct |
19 |
Correct |
20 ms |
12004 KB |
Output is correct |
20 |
Correct |
19 ms |
10584 KB |
Output is correct |
21 |
Correct |
18 ms |
9564 KB |
Output is correct |
22 |
Correct |
17 ms |
9052 KB |
Output is correct |
23 |
Correct |
17 ms |
8608 KB |
Output is correct |
24 |
Correct |
17 ms |
7516 KB |
Output is correct |
25 |
Correct |
16 ms |
7308 KB |
Output is correct |
26 |
Correct |
17 ms |
6744 KB |
Output is correct |
27 |
Correct |
17 ms |
6492 KB |
Output is correct |
28 |
Correct |
17 ms |
6236 KB |
Output is correct |
29 |
Correct |
17 ms |
6384 KB |
Output is correct |
30 |
Correct |
16 ms |
6236 KB |
Output is correct |
31 |
Correct |
18 ms |
6260 KB |
Output is correct |
32 |
Correct |
17 ms |
6268 KB |
Output is correct |
33 |
Correct |
16 ms |
6236 KB |
Output is correct |
34 |
Correct |
17 ms |
6308 KB |
Output is correct |
35 |
Correct |
18 ms |
6480 KB |
Output is correct |
36 |
Correct |
18 ms |
6436 KB |
Output is correct |
37 |
Correct |
19 ms |
6748 KB |
Output is correct |
38 |
Correct |
20 ms |
6748 KB |
Output is correct |
39 |
Correct |
2 ms |
1884 KB |
Output is correct |
40 |
Correct |
2 ms |
1884 KB |
Output is correct |
41 |
Correct |
2 ms |
1884 KB |
Output is correct |
42 |
Correct |
2 ms |
1884 KB |
Output is correct |
43 |
Incorrect |
3 ms |
2064 KB |
Output isn't correct |
44 |
Halted |
0 ms |
0 KB |
- |