Submission #938671

#TimeUsernameProblemLanguageResultExecution timeMemory
938671farukToll (BOI17_toll)C++17
0 / 100
116 ms55124 KiB
#include <bits/stdc++.h> #define mp make_pair #define all(a) a.begin(), a.end() using namespace std; typedef long long ll; typedef pair<ll, ll> pii; vector<vector<pii> > graph; int k; vector<ll> combine(vector<ll> beg, int bn, vector<ll> endd) { vector<ll> ans(k, 1e18); for (int i = 0; i < k; i++) for (auto &[to, w] : graph[bn * k + i]) ans[to] = min(ans[to], beg[i] + endd[to] + w); return ans; } const int lg = 18; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, m, q; cin >> k >> n >> m >> q; graph = vector<vector<pii> >(n + 2 * k); for (int i = 0; i < m; i++) { int f, t, p; cin >>f >> t >> p; graph[f].push_back(pii(t % k, p)); } vector<vector<vector<ll> > > lift(lg, vector<vector<ll> > (n / k + 1, vector<ll>(k, 1e18))); int num_lay = n / k + 1; for (int i = 0; i < num_lay; i++) lift[0][i] = vector<ll>(k, 0); for (int bit = 1; bit < lg; bit++) for (int i = num_lay - (1 << bit - 1) - 1; i >= 0; i--) lift[bit][i] = combine(lift[bit - 1][i], i, lift[bit - 1][i + (1 << (bit - 1))]); while (q--) { int f, t; cin >> f >> t; int SF = f / k, ST = t / k; vector<ll> ans(k, 1e18); ans[f % k] = 0; int diff = ST - SF; for (int i = 0; i < lg; i++) { if (((1 << i) & diff) != 0) { ans = combine(ans, SF, lift[i][SF + 1]); SF += (1 << i); } } if (ans[t % k] == 1e18) cout << "-1\n"; else cout << ans[t % k] << "\n"; } }

Compilation message (stderr)

toll.cpp: In function 'int main()':
toll.cpp:40:42: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   40 |         for (int i = num_lay - (1 << bit - 1) - 1; i >= 0; i--)
      |                                      ~~~~^~~
#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...