# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
994584 | PenguinsAreCute | Trains (BOI24_trains) | C++17 | 297 ms | 247768 KiB |
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
const int SQ = 313;
const int MOD = 1e9 + 7;
main() {
int n; cin >> n;
int d[n], x[n]; for(int i=0;i<n;i++) cin>>d[i]>>x[i];
int dp[n], pre[n][SQ];
for(int i=n;i--;) {
dp[i]=1;
if(d[i]>=SQ) for(int j=1;j<=x[i]&&i+j*d[i]<n;j++) {dp[i]+=dp[i+j*d[i]]; if(dp[i]>=MOD) dp[i]-=MOD;}
else if(d[i]) {
if(i+d[i]<n) dp[i]+=pre[i+d[i]][d[i]];
if(i+d[i]*(x[i]+1)<n) dp[i]-=pre[i+d[i]*(x[i]+1)][d[i]];
if(dp[i]>=MOD) dp[i]-=MOD;
if(dp[i]<0) dp[i]+=MOD;
}
for(int j=1;j<SQ;j++) {pre[i][j]=dp[i]+(i+j<n?pre[i+j][j]:0); if(pre[i][j]>=MOD) pre[i][j]-=MOD;}
}
cout << dp[0];
}
Compilation message (stderr)
# | 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... |