# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1077435 | 2024-08-27T07:13:34 Z | vjudge1 | Toll (BOI17_toll) | C++17 | 93 ms | 63056 KB |
#include <bits/stdc++.h> #define endl '\n' using namespace std; void FastIO(string name = "") { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); if (name.empty() == 0) { freopen((name + ".in").c_str(), "r", stdin); freopen((name + ".out").c_str(), "w", stdout); } } void solve() { int k, n, m, o; cin >> k >> n >> m >> o; vector<vector<pair<int, int>>> nei(n); for (int i = 1; i <= m; i++) { int a, b, t; cin >> a >> b >> t; nei[a].push_back({b, t}); } int lg = log2(n); const long long inf = 1e11; vector table(n, vector(lg + 1, vector(5, inf))); for (int i = 0; i < n; i++) { for (auto &[to, toll] : nei[i]) { table[i][0][to % k] = toll; } } for (int bit = 1; bit <= lg; bit++) { for (int i = 0; i < n; i++) { int jump = (1 << (bit - 1)); int ind = (i / k + jump ) * k ; for (int rem = 0; rem < k; rem++) { if (ind >= n) break; for (int j = 0; j < k; j++) table[i][bit][j] = min( table[i][bit-1][rem]+table[ind][bit - 1][j], table[i][bit][j]); ind++; } } } for (int q = 1; q <= o; q++) { int a, b; cin >> a >> b; if (a == b) { cout << 0; } else if (b/k <= a/k) { cout << -1; } else { int length = (b / k) - (a / k); vector<pair<int, long long>> node{{a, 0}}; for (int bit = 0; bit <= lg; bit++) if (length >> bit & 1) { map<int, long long> dis; for (auto &[at, d] : node) { int ind = (at / k + (1<<bit) ) * k ; for (int re = 0; re < k; re++) { if (dis.count(ind)) dis[ind] = min(dis[ind], d + table[at][bit][re]); else dis[ind] = d + table[at][bit][re]; ind++; } } node.clear(); for (auto &e : dis) node.push_back(e); } long long ans = 2e13; for (auto &[at, ds] : node) if (at == b) { ans = ds; } cout << (ans >= (int)1e9 ? -1 : ans) << endl; } } } int main() { FastIO(""); int t = 1; //cin >> t; for (int i = 0; i < t; i++) { solve(); } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 83 ms | 62288 KB | Output is correct |
2 | Correct | 1 ms | 856 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 2 ms | 1116 KB | Output is correct |
6 | Correct | 1 ms | 1116 KB | Output is correct |
7 | Correct | 2 ms | 1268 KB | Output is correct |
8 | Correct | 93 ms | 62288 KB | Output is correct |
9 | Correct | 85 ms | 62292 KB | Output is correct |
10 | Correct | 71 ms | 59984 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 87 ms | 63056 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Incorrect | 0 ms | 348 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Incorrect | 0 ms | 348 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Incorrect | 0 ms | 348 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 83 ms | 62288 KB | Output is correct |
2 | Correct | 1 ms | 856 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 2 ms | 1116 KB | Output is correct |
6 | Correct | 1 ms | 1116 KB | Output is correct |
7 | Correct | 2 ms | 1268 KB | Output is correct |
8 | Correct | 93 ms | 62288 KB | Output is correct |
9 | Correct | 85 ms | 62292 KB | Output is correct |
10 | Correct | 71 ms | 59984 KB | Output is correct |
11 | Correct | 87 ms | 63056 KB | Output is correct |
12 | Correct | 1 ms | 348 KB | Output is correct |
13 | Incorrect | 0 ms | 348 KB | Output isn't correct |
14 | Halted | 0 ms | 0 KB | - |