# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1098059 | VinhLuu | Trains (BOI24_trains) | C++17 | 196 ms | 127088 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 int long long
#define ll long long
#define fi first
#define se second
#define all(vin) vin.begin(), vin.end()
using namespace std;
typedef pair<int,int> pii;
typedef pair<pii,int> tp;
const int N = 1e5 + 2;
//const int oo = -1e16;
const int mod = 1e9 + 7;
int n, d[N], x[N], block, g[318][N], f[N];
void get(int &x,int y){
x = (x + y) % mod;
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define task "v"
if(fopen(task ".inp","r")){
freopen(task ".inp","r",stdin);
freopen(task ".out","w",stdout);
}
cin >> n;
block = sqrt(n);
vector<int> vr;
for(int i = 1; i <= n; i ++){
cin >> d[i] >> x[i];
if(d[i] <= block) vr.push_back(d[i]);
}
sort(all(vr)); vr.resize(unique(all(vr)) - vr.begin());
for(int i = 1; i <= n; i ++) f[i] = 1;
for(int i = n; i >= 1; i --){
if(d[i] > block){
for(int j = 1; j <= x[i] && i + 1ll * j * d[i] <= n; j ++)
get(f[i], f[i + 1ll * j * d[i]]);
}else{
int val = 0;
if(x[i] && i + 1ll * (x[i] + 1) * d[i] <= n) val = (mod - g[d[i]][i + 1ll * (x[i] + 1) * d[i]]) % mod;
if(x[i]) get(f[i], (g[d[i]][i + d[i]] + val) % mod);
}
for(auto j : vr){
get(g[j][i], f[i] + (i + j <= n ? g[j][i + j] : 0));
}
}
cout << f[1];
}
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... |