# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
365528 | 2021-02-11T19:55:26 Z | LucaDantas | Toll (BOI17_toll) | C++17 | 48 ms | 10860 KB |
#include<cstdio> #include<vector> #include<utility> #include<algorithm> using namespace std; constexpr int maxn = 1e5+10, inf = 0x3f3f3f3f; vector<pair<int,int>> g[maxn], query[maxn]; int K, dist_l[maxn][5], dist_r[maxn][5], next_dist_l[maxn][5], next_dist_r[maxn][5], ans[maxn]; void solve(int l, int r) { if(l == r) return; int m = (l+r) >> 1; solve(l, m); solve(m+1, r); for(int x = K*m; x < K*(m+1); x++) for(int y = 0; y < K; y++) dist_r[x][y] = 0; for(int i = K*l; i < K*(m+1); i++) { while(query[i].size() && query[i].back().first/K <= r) { auto [b, id] = query[i].back(); query[i].pop_back(); for(int x = K*m; x < K*(m+1); x++) ans[id] = min(ans[id], dist_r[i][x-K*m]+dist_l[b][x-K*m]); } } for(int esq = 0; esq < K; esq++) { for(int x = K*(m+1); x < K*(r+1); x++) { for(int meio = 0; meio < K; meio++) next_dist_l[x][esq] = min(next_dist_l[x][esq], dist_l[x][meio]+dist_r[K*l+esq][meio]); } } for(int dir = 0; dir < K; dir++) { for(int x = K*l; x < K*(m+1); x++) { for(int meio = 0; meio < K; meio++) next_dist_r[x][dir] = min(next_dist_r[x][dir], dist_r[x][meio]+dist_l[K*r+dir][meio]); } } for(int esq = 0; esq < K; esq++) for(int x = K*(m+1); x < K*(r+1); x++) dist_l[x][esq] = next_dist_l[x][esq], next_dist_l[x][esq] = inf; for(int dir = 0; dir < K; dir++) for(int x = K*l; x < K*(m+1); x++) dist_r[x][dir] = next_dist_r[x][dir], next_dist_r[x][dir] = inf; } int main() { int n, m, q; scanf("%d %d %d %d", &K, &n, &m, &q); for(int i = 0; i < n; i++) for(int j = 0; j < K; j++) dist_l[i][j] = next_dist_l[i][j] = dist_r[i][j] = next_dist_r[i][j] = inf; for(int i = 0, a, b, c; i < m; i++) { scanf("%d %d %d", &a, &b, &c); if(a < b) swap(a, b); dist_l[a][b%K] = c; } for(int i = 0; i < q; i++) { int a, b; scanf("%d %d", &a, &b); query[a].push_back({b, i}); ans[i] = inf; } for(int i = 0; i < n; i++) sort(query[i].begin(), query[i].end()), reverse(query[i].begin(), query[i].end()); solve(0, (n-1)/K); for(int i = 0; i < q; i++) printf("%d\n", ans[i]<inf?ans[i]:-1); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 32 ms | 10220 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 48 ms | 10860 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 4972 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 4972 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 32 ms | 10220 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |