This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define endl '\n'
const int mod = 1e9 + 7;
const int maxn = 1e6 + 5;
int n, l[maxn], r[maxn];
int dp[maxn];
int rec(int i)
{
if (i < 0) return 0;
if (dp[i] != -1) return dp[i];
int ret = max(rec(i - 1), rec(i - l[i] - 1) + 1);
return dp[i] = ret;
}
void s1()
{
cout << (n - 1) / (l[0] + 1) + 1 << endl;
}
void s2()
{
memset(dp, -1, sizeof dp);
cout << rec(n - 1) << endl;
}
void solve()
{
cin >> n;
bool flag = 1, flag2 = 1;
for(int i = 0; i < n; i++)
{
cin >> l[i] >> r[i];
if((l[i] != r[i]) || (i & (l[i] != l[i - 1]))) flag = 0;
if(r[i] != 0) flag2 = 0;
}
if(flag) s1();
else if(flag2) s2();
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int tt = 1;
//cin >> tt;
while(tt--) solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |