# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
994965 | salmon | Trains (BOI24_trains) | C++14 | 199 ms | 249800 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;
vector<int> v;
map<int,long long int> mep[100100];
vector<int> rebove[100100];
int N;
long long int d,x;
vector<pair<int,int>> iv;
long long int num[100100];
long long int mod = 1'000'000'007;
const int B = 300;
long long int blom[100100][B + 5];
int main(){
scanf(" %d",&N);
for(int i = 0; i < N; i++){
scanf(" %lld",&d);
scanf(" %lld",&x);
iv.push_back({d,x});
num[i] = 0;
if(d <= B) rebove[min((long long int)N,i + d * x)].push_back(i);
}
num[0]= 1;
long long int sum = 0;
for(int i = 0; i < N; i++){
num[i] %= mod;
for(int j : rebove[i]){
blom[i][iv[j].first] -= num[j];
blom[i][iv[j].first] %= mod;
}
if(iv[i].first <= B){
blom[i][iv[i].first] += num[i];
blom[i][iv[i].first] %= mod;
}
else{
int d = iv[i].first;
int x = iv[i].second;
for(int j = 1; j <= x && i + j * d < N; j++){
num[i + j * d] += num[i];
}
}
for(int j = 1; j <= B; j++){
num[min(N,i + j)] += blom[i][j];
blom[min(N,i + j)][j] += blom[i][j];
blom[min(N,i + j)][j] %= mod;
}
sum = (sum + num[i]) % mod;
}
printf("%lld",(sum + mod) % mod);
}
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... |