# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1058792 | Tonyl | Trains (BOI24_trains) | C++17 | 447 ms | 191224 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;
using ll = long long;
using vi = vector<int>;
using pi = pair<int,int>;
#define REP(i,n) for (int i = 0; i < n; i++)
#define trav(a,x) for (auto& a : x)
#define D(x) cerr << #x << ": " << x << endl;
#define all(x) (x).begin(), (x).end()
const int MOD = 1e9+7;
const int MAX_N = 1e5+1;
const int SQRT = 320;
struct Prefix {
vi pr = {0};
int q(int x) {
if (x <= 0) return 0;
int r = pr.back();
int l = pr.size()>x ? pr[pr.size()-1-x] : 0;
return (MOD+r-l)%MOD;
}
void add(int a) {
pr.push_back((pr.back()+a)%MOD);
}
};
struct Station {
int d, x;
};
Station stations[MAX_N];
Prefix prsq[SQRT][SQRT];
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
int n; cin >> n;
REP(i,n) {
cin >> stations[i].d >> stations[i].x;
}
for (int i = n-1; i >= 0; i--) {
Station& st = stations[i];
int tot = st.d == 0 ? 1 : prsq[st.d-1][i%st.d].q(st.x)+1;
for (int s = 0; s < SQRT; s++) {
int sq = s+1;
int md = i%sq;
prsq[s][md].add(tot);
}
}
cout << prsq[0][0].q(1) << endl;
}
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... |