| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1303474 | red_souls | Trains (BOI24_trains) | C++20 | 81 ms | 7456 KiB |
#include <bits/stdc++.h>
#define ll long long
#define task "TRAINS"
using namespace std;
const int N = 1e5 + 16;
const ll mod = 1e9 + 7;
int n;
ll d[N], x[N];
ll add(ll a, ll b) {
a += b;
if (a >= mod) {
a -= mod;
}
return a;
}
ll sub(ll a, ll b) {
a -= b;
if (a < 0) {
a += mod;
}
return a;
}
namespace sub5 {
ll result, dp[N], s[320][320];
vector <int> events[N];
int BLOCKSIZE;
void solve() {
BLOCKSIZE = sqrt(n);
dp[1] = 1;
for (int i = 1; i <= n; i++) {
for (auto x : events[i]) {
s[d[x]][x % d[x]] = sub(s[d[x]][x % d[x]], dp[x]);
}
for (int j = 1; j < BLOCKSIZE; j++) {
dp[i] = add(dp[i], s[j][i % j]);
}
if (d[i] == 0) {
continue;
}
if (d[i] >= BLOCKSIZE) {
for (int j = 1; j <= x[i] && i + j * d[i] <= n; j++) {
dp[i + j * d[i]] = add(dp[i + j * d[i]], dp[i]);
}
}
else {
s[d[i]][i % d[i]] = add(s[d[i]][i % d[i]], dp[i]);
events[min(1LL * n, d[i] * x[i] + i) + 1].push_back(i);
}
}
for (int i = 1; i <= n; i++) {
result = add(result, dp[i]);
}
cout << result;
}
}
int main() {
ios_base :: sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
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];
}
sub5 :: solve();
return 0;
}
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... | ||||
