# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1033561 | vjudge1 | Trains (BOI24_trains) | C++14 | 154 ms | 9556 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.
#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define name "aaaaaa"
using ll = long long;
using pii = pair<ll, ll>;
using ld = long double;
void file(){
ios_base::sync_with_stdio(0); cin.tie(0);
if(fopen(name".inp", "r")) {
freopen(name".inp", "r", stdin);
freopen(name".out", "w", stdout);
}
}
const ll maxn = 1e5 + 5;
const ll maxs = 320;
const ll mod = 1e9 + 7;
ll d[maxn], x[maxn];
ll dp[maxn];
ll sus[maxs][maxs];
vector<pair<pii, ll>> v[maxn];
void solve (){
ll n; cin >> n;
for(ll i = 1; i <= n; i++){
cin >> d[i] >> x[i];
}
dp[1] = 1;
for(ll i = 1; i <= n; i++){
for(auto j : v[i]){
ll p1 = j.first.first, p2 = j.first.second, p3 = j.second;
sus[p1][p2] += p3;
if(sus[p1][p2] < 0){
sus[p1][p2] += mod;
}
}
for(ll j = 1; j < maxs; j++){
dp[i] += sus[j][i % j];
dp[i] %= mod;
}
if(d[i] >= maxs){
for(ll j = 1; j <= x[i]; j++){
if(i + d[i] * j > n) break;
dp[i + d[i] * j] += dp[i];
dp[i + d[i] * j] %= mod;
}
}else if(d[i] != 0){
sus[d[i]][i % d[i]] += dp[i];
sus[d[i]][i % d[i]] %= mod;
ll pos = i + (x[i] + 1) * d[i];
if(pos <= n){
v[pos].push_back({{d[i], i % d[i]}, -dp[i]});
}
}
}
ll ans = 0;
for(ll i = 1; i <= n; i++){
ans += dp[i];
}
cout << ans % mod;
}
int main(){
file();
ll t = 1;
//cin >> t;
while(t--){
solve();
}
}
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... |