# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
995465 |
2024-06-09T06:40:22 Z |
12345678 |
Trains (BOI24_trains) |
C++17 |
|
13 ms |
2584 KB |
#include <bits/stdc++.h>
using namespace std;
const int nx=1e5+5, mod=1e9+7;
int n, d[nx], x[nx], dp[nx], res, sm=1;
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n;
for (int i=1; i<=n; i++) cin>>d[i]>>x[i];
dp[1]=1;
pq.push({1+x[1]+1, dp[1]});
for (int i=2; i<=n; i++)
{
while (!pq.empty()&&pq.top().first<=i) sm=((sm-pq.top().second)%mod+mod)%mod, pq.pop();
dp[i]=sm;
//cout<<"dp "<<i<<' '<<dp[i]<<'\n';
sm=(sm+dp[i])%mod;
pq.push({i+x[i]+1, dp[i]});
}
for (int i=1; i<=n; i++) res=(res+dp[i])%mod;
cout<<res;
}
/*
5
1 3
1 2
1 1
1 4
1 5
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
2 ms |
600 KB |
Output is correct |
5 |
Correct |
8 ms |
1372 KB |
Output is correct |
6 |
Correct |
11 ms |
2524 KB |
Output is correct |
7 |
Correct |
12 ms |
2524 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
12 ms |
2564 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
2 ms |
780 KB |
Output is correct |
15 |
Correct |
13 ms |
2584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
1504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |