Submission #1091301

# Submission time Handle Problem Language Result Execution time Memory
1091301 2024-09-20T12:58:34 Z kasdo Bouquet (EGOI24_bouquet) C++14
0 / 100
556 ms 1048576 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)
{
    if (i <= 0) return 0;
    if (dp[i] != -1) return dp[i];
    
    return dp[i] = max(rec(i - 1), rec(i - l[i]) + 1);
}
void s1()
{
    memset(dp, -1, sizeof dp);
    cout<<rec(n)<<endl;
}
void s2()
{
    int ans = 0, last = -1e18;
    for(int i=1; i<=n; i++)
    {
        if (i >= last && i - l[i] >= last)
        {
            ans++;
            last = r[i];
        }
    }
    cout<<ans<<endl;
}
void solve()
{
    int mx = 0;
    cin>>n;
    for(int i=1; i<=n; i++) cin>>l[i];
    for(int i=1; i<=n; i++)
    {
        cin>>r[i];
        mx = max(mx, r[i]);
    }
    
    if (mx == 0) s1();
    else s2();
}
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 Runtime error 548 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 556 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 539 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 541 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 548 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -