# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1028077 | Abito | Trains (BOI24_trains) | C++17 | 606 ms | 259664 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>
#define F first
#define S second
#define pb push_back
#define ppb pop_back
#define ep insert
#define endl '\n'
#define elif else if
#define pow pwr
#define sqrt sqrtt
#define int long long
#define ll long long
#define y1 YONE
typedef unsigned long long ull;
using namespace std;
const int N=1e5+5,M=1e9+7,S=300;
int dp[N],d[N],x[N],n;
vector<int> s[S+5][S];
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
cin>>n;
for (int i=1;i<=n;i++) cin>>d[i]>>x[i];
for (int i=1;i<=S;i++){
int sz=n/i+50;
for (int j=0;j<i;j++) s[i][j].resize(sz,0);
}
for (int i=n;i;i--){
dp[i]=1;
if (d[i]>S){
for (int j=i+d[i];j<=n && j<=i+d[i]*x[i];j+=d[i]) dp[i]=(dp[i]+dp[j])%M;
}
elif (d[i] && x[i]){
int l=i/d[i]+1,r=l+x[i];
if (r>=s[d[i]][i%d[i]].size()){
dp[i]=(s[d[i]][i%d[i]][l]+1)%M;
}
//cout<<i<<' '<<l<<' '<<r<<endl;
else dp[i]=((s[d[i]][i%d[i]][l]-s[d[i]][i%d[i]][r]+M)%M+1)%M;
}
for (int j=1;j<=S;j++){
s[j][i%j][i/j]=(s[j][i%j][i/j+1]+dp[i])%M;
}
}
//for (int i=1;i<=n;i++) cout<<dp[i]<<' ';cout<<endl;
cout<<dp[1]<<endl;
return 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... |