Submission #1062997

#TimeUsernameProblemLanguageResultExecution timeMemory
1062997quanmcvnTrains (BOI24_trains)C++17
71 / 100
2087 ms946120 KiB
#include<bits/stdc++.h> using namespace std; using ll = int64_t; constexpr size_t nmax = 100000 + 15; constexpr size_t sqrt_n = 317 + 15; constexpr ll mod = 1'000'000'000 + 7; void add(ll& lhs, ll rhs) { lhs += rhs; lhs %= mod; } void sub(ll& lhs, ll rhs) { lhs -= rhs; lhs %= mod; lhs += mod; lhs %= mod; } ll n; set<ll> from[nmax]; ll dp[nmax]; ll sum[sqrt_n][sqrt_n]; struct Event { ll type, i; Event() {} Event(ll t_, ll i_) : type(t_), i(i_) {} }; vector<Event> events[sqrt_n][nmax]; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr); cin >> n; ll sqrt_n_real = sqrt(n); for (ll i = 1; i <= n; ++ i) { ll d, x; cin >> d >> x; if (d == 0 || x == 0) continue; if (d > sqrt_n_real) { for (ll j = 1; j <= x; ++ j) { ll new_i = i + d * j; if (new_i > n) break; from[new_i].insert(i); } } else { ll l = i + d; ll r = i + d * (x + 1); events[d][l].emplace_back(0, i); if (r <= n) { events[d][r].emplace_back(1, i); } } } dp[1] = 1; for (ll i = 2; i <= n; ++ i) { for (const auto& j : from[i]) { add(dp[i], dp[j]); } for (ll d = 1; d <= sqrt_n_real; ++ d) { for (const auto& [type, j] : events[d][i]) { if (type == 0) { add(sum[d][j % d], dp[j]); } else { sub(sum[d][j % d], dp[j]); } } } for (ll d = 1; d <= sqrt_n_real; ++ d) { add(dp[i], sum[d][i % d]); } } ll res = 0; for (ll i = 1; i <= n; ++ i) { add(res, dp[i]); } cout << res; }
#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...