# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1120816 | ntdaccode | Trains (BOI24_trains) | C++17 | 387 ms | 162104 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 fori(i,a,b) for(int i=a;i<=b;i++)
#define int long long
#define pb push_back
using namespace std;
typedef pair<int,int> ii;
typedef tuple<int,int,int> tp;
const int M = 1e6 + 10;
const int N = 1e3 + 10;
const int mod = 1e9 + 7;
const int SIZE = 150;
int n, d[M], x[M], f[M];
vector<int> sum[SIZE + 10][SIZE + 10];
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if(fopen("1.inp","r")) {
freopen("1.inp","r",stdin);
freopen("1.ans","w",stdout);
}
#define task ""
if(fopen(task".inp","r")) {
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);
}
cin >> n;
for(int i = 1;i <= n; i++) {
cin >> d[i] >> x[i];
f[i] = 1;
}
for(int i = 1;i <= SIZE; i++) {
for(int j = 0;j <= i - 1; j++) {
sum[j][i].pb(0);
}
}
for(int i = n; i != 0; i--) {
if(d[i] != 0) {
if(d[i] > SIZE) {
int cnt = 1;
for(int j = i + d[i]; j <= n; j += d[i]) {
if(cnt > x[i]) break;
f[i] = (f[i] + f[j]) % mod;
cnt++;
}
//cout << i << " ";
}
else {
// cout << "A";
int du = i % d[i];
int sz = sum[du][d[i]].size();
int lim = sz - 1 - min(x[i],sz - 1);
f[i] = (f[i] + sum[du][d[i]].back() - sum[du][d[i]][lim] + mod) % mod;
}
}
for(int j = 1;j <= SIZE; j++) {
int du = i % j;
sum[du][j].pb( (sum[du][j].back() + f[i]) % mod);
}
}
cout << f[1] % mod;
//cerr << (float)clock()/CLOCKS_PER_SEC << "\n";
}
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... |