Submission #1091321

# Submission time Handle Problem Language Result Execution time Memory
1091321 2024-09-20T14:05:24 Z kasdo Bouquet (EGOI24_bouquet) C++14
24 / 100
22 ms 11356 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++)
    {
        int good = (j + r[j] < i && i - l[i] > j);
        
        ret = max(ret, rec2(j) + good);
    }
    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;
    
    cout<<rec2(n)<<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 1880 KB Output is correct
2 Correct 14 ms 3420 KB Output is correct
3 Correct 16 ms 3416 KB Output is correct
4 Correct 13 ms 3352 KB Output is correct
5 Correct 15 ms 3420 KB Output is correct
6 Correct 16 ms 3420 KB Output is correct
7 Correct 18 ms 3420 KB Output is correct
8 Correct 20 ms 3420 KB Output is correct
9 Correct 20 ms 3560 KB Output is correct
10 Correct 2 ms 1884 KB Output is correct
11 Correct 1 ms 1884 KB Output is correct
12 Correct 2 ms 1880 KB Output is correct
13 Correct 1 ms 1884 KB Output is correct
14 Correct 1 ms 1884 KB Output is correct
15 Correct 1 ms 1880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 3420 KB Output is correct
2 Correct 2 ms 1884 KB Output is correct
3 Correct 1 ms 1884 KB Output is correct
4 Correct 20 ms 11188 KB Output is correct
5 Correct 19 ms 9708 KB Output is correct
6 Correct 18 ms 8796 KB Output is correct
7 Correct 19 ms 8068 KB Output is correct
8 Correct 18 ms 7772 KB Output is correct
9 Correct 16 ms 6720 KB Output is correct
10 Correct 17 ms 6492 KB Output is correct
11 Correct 18 ms 5796 KB Output is correct
12 Correct 16 ms 5596 KB Output is correct
13 Correct 17 ms 5468 KB Output is correct
14 Correct 17 ms 5212 KB Output is correct
15 Correct 18 ms 5208 KB Output is correct
16 Correct 17 ms 5212 KB Output is correct
17 Correct 19 ms 4956 KB Output is correct
18 Correct 18 ms 4948 KB Output is correct
19 Correct 17 ms 5060 KB Output is correct
20 Correct 17 ms 4952 KB Output is correct
21 Correct 17 ms 5024 KB Output is correct
22 Correct 20 ms 5212 KB Output is correct
23 Correct 22 ms 5212 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 Correct 2 ms 1884 KB Output is correct
29 Correct 1 ms 1884 KB Output is correct
30 Correct 19 ms 9680 KB Output is correct
31 Correct 21 ms 11356 KB Output is correct
32 Correct 1 ms 1880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1880 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 2 ms 1884 KB Output is correct
4 Correct 2 ms 1884 KB Output is correct
5 Correct 2 ms 1880 KB Output is correct
6 Correct 1 ms 1884 KB Output is correct
7 Correct 1 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 Correct 2 ms 1884 KB Output is correct
11 Correct 1 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 2 ms 1884 KB Output is correct
15 Incorrect 2 ms 1884 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 3420 KB Output is correct
2 Correct 2 ms 1884 KB Output is correct
3 Correct 20 ms 11356 KB Output is correct
4 Correct 19 ms 9816 KB Output is correct
5 Correct 19 ms 9816 KB Output is correct
6 Correct 21 ms 11352 KB Output is correct
7 Incorrect 19 ms 9820 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1880 KB Output is correct
2 Correct 14 ms 3420 KB Output is correct
3 Correct 16 ms 3416 KB Output is correct
4 Correct 13 ms 3352 KB Output is correct
5 Correct 15 ms 3420 KB Output is correct
6 Correct 16 ms 3420 KB Output is correct
7 Correct 18 ms 3420 KB Output is correct
8 Correct 20 ms 3420 KB Output is correct
9 Correct 20 ms 3560 KB Output is correct
10 Correct 2 ms 1884 KB Output is correct
11 Correct 1 ms 1884 KB Output is correct
12 Correct 2 ms 1880 KB Output is correct
13 Correct 1 ms 1884 KB Output is correct
14 Correct 1 ms 1884 KB Output is correct
15 Correct 1 ms 1880 KB Output is correct
16 Correct 14 ms 3420 KB Output is correct
17 Correct 2 ms 1884 KB Output is correct
18 Correct 1 ms 1884 KB Output is correct
19 Correct 20 ms 11188 KB Output is correct
20 Correct 19 ms 9708 KB Output is correct
21 Correct 18 ms 8796 KB Output is correct
22 Correct 19 ms 8068 KB Output is correct
23 Correct 18 ms 7772 KB Output is correct
24 Correct 16 ms 6720 KB Output is correct
25 Correct 17 ms 6492 KB Output is correct
26 Correct 18 ms 5796 KB Output is correct
27 Correct 16 ms 5596 KB Output is correct
28 Correct 17 ms 5468 KB Output is correct
29 Correct 17 ms 5212 KB Output is correct
30 Correct 18 ms 5208 KB Output is correct
31 Correct 17 ms 5212 KB Output is correct
32 Correct 19 ms 4956 KB Output is correct
33 Correct 18 ms 4948 KB Output is correct
34 Correct 17 ms 5060 KB Output is correct
35 Correct 17 ms 4952 KB Output is correct
36 Correct 17 ms 5024 KB Output is correct
37 Correct 20 ms 5212 KB Output is correct
38 Correct 22 ms 5212 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 Correct 2 ms 1884 KB Output is correct
44 Correct 1 ms 1884 KB Output is correct
45 Correct 19 ms 9680 KB Output is correct
46 Correct 21 ms 11356 KB Output is correct
47 Correct 1 ms 1880 KB Output is correct
48 Correct 2 ms 1880 KB Output is correct
49 Correct 1 ms 1884 KB Output is correct
50 Correct 2 ms 1884 KB Output is correct
51 Correct 2 ms 1884 KB Output is correct
52 Correct 2 ms 1880 KB Output is correct
53 Correct 1 ms 1884 KB Output is correct
54 Correct 1 ms 1884 KB Output is correct
55 Correct 2 ms 1884 KB Output is correct
56 Correct 2 ms 1884 KB Output is correct
57 Correct 2 ms 1884 KB Output is correct
58 Correct 1 ms 1884 KB Output is correct
59 Correct 2 ms 1884 KB Output is correct
60 Correct 2 ms 1884 KB Output is correct
61 Correct 2 ms 1884 KB Output is correct
62 Incorrect 2 ms 1884 KB Output isn't correct
63 Halted 0 ms 0 KB -