Submission #1062970

#TimeUsernameProblemLanguageResultExecution timeMemory
1062970quanmcvnTrains (BOI24_trains)C++14
0 / 100
2056 ms27632 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; } ll n; bool ok[nmax][sqrt_n]; ll cd[nmax]; vector<pair<ll, ll>> bus[sqrt_n]; set<ll> ok_sll[nmax]; ll dp[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 (x > sqrt_n_real) { for (ll j = 0; j < x; ++ j) { ll new_i = i + d * j; if (new_i > n) break; ok_sll[new_i].insert(d); } continue; } else { bus[d].emplace_back(i, x); } } for (ll d = 1; d <= sqrt_n_real; ++ d) { for (ll i = 1; i <= n; ++ i) cd[i] = 0; for (const auto& [i, x] : bus[d]) { ll l = i; ll r = i + d * x; ++ cd[l]; if (r <= n) -- cd[r]; } for (ll i = d; i <= n; ++ i) { cd[i] += cd[i - d]; if (cd[i] > 0) { ok[i][d] = true; } } } dp[1] = 1; for (ll i = 1; i < n; ++ i) { for (ll d = 1; d <= sqrt_n_real; ++ d) { if (ok[i][d] && i + d <= n) { add(dp[i + d], dp[i]); } } for (const auto& d : ok_sll[i]) { if (i + d <= n) { add(dp[i + d], dp[i]); } } } ll res = 0; for (ll i = 1; i <= n; ++ i) { add(res, dp[i]); } cout << res; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:42:20: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   42 |   for (const auto& [i, x] : bus[d]) {
      |                    ^
#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...