#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 = 0;
for(int d=1; d<=i; d++)
{
int j = i - d;
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1880 KB |
Output is correct |
2 |
Correct |
15 ms |
4188 KB |
Output is correct |
3 |
Correct |
16 ms |
4696 KB |
Output is correct |
4 |
Correct |
18 ms |
4188 KB |
Output is correct |
5 |
Correct |
15 ms |
4700 KB |
Output is correct |
6 |
Correct |
20 ms |
4952 KB |
Output is correct |
7 |
Correct |
21 ms |
5468 KB |
Output is correct |
8 |
Correct |
22 ms |
5924 KB |
Output is correct |
9 |
Correct |
22 ms |
5720 KB |
Output is correct |
10 |
Correct |
2 ms |
1992 KB |
Output is correct |
11 |
Correct |
2 ms |
1884 KB |
Output is correct |
12 |
Incorrect |
3 ms |
1884 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
4188 KB |
Output is correct |
2 |
Correct |
2 ms |
1884 KB |
Output is correct |
3 |
Incorrect |
1 ms |
1884 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1880 KB |
Output is correct |
2 |
Correct |
2 ms |
1884 KB |
Output is correct |
3 |
Incorrect |
2 ms |
1884 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
4188 KB |
Output is correct |
2 |
Correct |
2 ms |
1880 KB |
Output is correct |
3 |
Correct |
23 ms |
12120 KB |
Output is correct |
4 |
Correct |
20 ms |
10504 KB |
Output is correct |
5 |
Correct |
22 ms |
10588 KB |
Output is correct |
6 |
Correct |
21 ms |
12056 KB |
Output is correct |
7 |
Incorrect |
20 ms |
10580 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1880 KB |
Output is correct |
2 |
Correct |
15 ms |
4188 KB |
Output is correct |
3 |
Correct |
16 ms |
4696 KB |
Output is correct |
4 |
Correct |
18 ms |
4188 KB |
Output is correct |
5 |
Correct |
15 ms |
4700 KB |
Output is correct |
6 |
Correct |
20 ms |
4952 KB |
Output is correct |
7 |
Correct |
21 ms |
5468 KB |
Output is correct |
8 |
Correct |
22 ms |
5924 KB |
Output is correct |
9 |
Correct |
22 ms |
5720 KB |
Output is correct |
10 |
Correct |
2 ms |
1992 KB |
Output is correct |
11 |
Correct |
2 ms |
1884 KB |
Output is correct |
12 |
Incorrect |
3 ms |
1884 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |