제출 #1000157

#제출 시각아이디문제언어결과실행 시간메모리
1000157OAleksaTrains (BOI24_trains)C++14
100 / 100
97 ms8424 KiB
#include <bits/stdc++.h> #define f first #define s second #define int long long using namespace std; const int N = 1e5 + 69; const int B = 320; const int mod = 1e9 + 7; int n, d[N], x[N], dp[N]; vector<int> cnt[B]; vector<tuple<int, int, int>> who[N]; int add(int x, int y) { x += y; if (x >= mod) x -= mod; return x; } int sub(int x, int y) { x -= y; x = (x + 1000ll * mod) % mod; return x; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int tt = 1; //cin >> tt; while (tt--) { cin >> n; for (int i = 1;i <= n;i++) { cin >> d[i] >> x[i]; x[i] = min(x[i], n); } for (int i = 1;i < B;i++) cnt[i].resize(i); dp[1] = 1; for (int i = 1;i <= n;i++) { for (int j = 1;j < B;j++) { int x = i % j; dp[i] = add(dp[i], cnt[j][x]); } if (d[i] >= B) { for (int j = i + d[i], j1 = 1;j <= n && j1 <= x[i];j += d[i], j1++) { dp[j] = add(dp[j], dp[i]); } } else { if (d[i] != 0) { int when = i + x[i] * d[i]; if (when <= n) who[when].push_back({d[i], i % d[i], dp[i]}); cnt[d[i]][i % d[i]] = add(cnt[d[i]][i % d[i]], dp[i]); } } for (auto j : who[i]) { int a, b, c; tie(a, b, c) = j; cnt[a][b] = sub(cnt[a][b], c); } } int ans = 0; for (int i = 1;i <= n;i++) ans = add(ans, dp[i]); cout << ans; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...