# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1033578 | BuiDucManh123 | Trains (BOI24_trains) | C++14 | 2062 ms | 3208 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 fi first
#define se second
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define taskname ""
using namespace std;
const int mod=1e9+7;
ll n,i,a[100009],d[100009],x[100009],bit[100009],f[100009],j,ans;
bool check;
void update(int id,int val){
while(id<=n){
bit[id]+=val;
bit[id]%=mod;
id+=id&-id;
}
}
ll get(int id){
ll res=0;
while(id){
res+=bit[id];
res%=mod;
id-=id&-id;
}return res;
}
int main() {
if (fopen(taskname".inp","r")) {
freopen(taskname".inp","r",stdin);
freopen(taskname".out","w",stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;check=true;
for(i=1;i<=n;i++){
cin>>d[i]>>x[i];
if(d[i]!=1) check=false;
}
if(check==false){
f[1]=1;
for(i=1;i<=n;i++){
for(j=1;j<i;j++){
if(d[j]!=0&&(i-j)%d[j]==0&&i<=j+d[j]*x[j]){
f[i]+=f[j];
f[i]%=mod;
}
}
}ans=0;
for(i=1;i<=n;i++) ans+=f[i],ans%=mod;
cout<<ans;
}else{
update(1,1);
update(2,-1);
for(i=1;i<=n;i++){
j=get(i);
update(i+1,j);
update(i+x[i]+1,-j);
}
for(i=1;i<=n;i++){
ans+=get(i);
ans%=mod;
}cout<<ans;
}
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... |