# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
836268 | 2023-08-24T09:27:46 Z | nonono | Toll (BOI17_toll) | C++14 | 64 ms | 99068 KB |
#include <bits/stdc++.h> using namespace std; const int INF = 5e8; const int LOG = 20; const int mxN = 50005; int K, N, M, O; int up[mxN][5][5][LOG]; signed main() { #define taskname "" if (fopen(taskname".inp", "r")) { freopen(taskname".inp", "r", stdin); freopen(taskname".ans", "w", stdout); } cin.tie(0)->sync_with_stdio(0); cin >> K >> N >> M >> O; for(int i = 1; i <= M; i ++) { int a, b, t; cin >> a >> b >> t; if(a / K + 1 == b / K) { up[a / K][a % K][b % K][0] = t; //cout << a / K << " " << a % K << " " << b % K << " " << t << "\n"; } } for(int k = 1; (1 << k) <= (N - 1) / K; k ++) { for(int i = 0; i + (1 << k) <= (N - 1) / K; i ++) { for(int j1 = 0; j1 < K; j1 ++) { for(int j2 = 0; j2 < K; j2 ++) { for(int j3 = 0; j3 < K; j3 ++) { if(!up[i + (1 << k - 1)][j2][j3][k - 1]) continue ; up[i][j1][j3][k] = up[i][j1][j2][k - 1] + up[i + (1 << k - 1)][j2][j3][k - 1]; /*cout << k << " " << i << " " << j1 << " " << j2 << " " << j3 << " " << up[i][j1][j2][k - 1] << " " << up[i + (1 << k - 1)][j2][j3][k - 1] << " " << up[i][j1][j3][k] << "\n";*/ } } } } } while(O --) { int a, b; cin >> a >> b; int typeA = a % K; int typeB = b % K; a /= K; b /= K; vector<int> ar(K); for(int i = 0; i < K; i ++) ar[i] = INF; ar[typeA] = 0; int depth = b - a; for(int k = 0; k <= 18; k ++) { if(depth >> k & 1) { vector<int> _ar(K); for(int i = 0; i < K; i ++) { _ar[i] = ar[i]; ar[i] = INF; } for(int i = 0; i < K; i ++) { for(int j = 0; j < K; j ++) { if(!up[a][j][i][k]) continue ; ar[i] = min(ar[i], _ar[j] + up[a][j][i][k]); } } a += (1 << k); } } if(ar[typeB] >= INF) cout << -1 << "\n"; else cout << ar[typeB] << "\n"; } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 60 ms | 99068 KB | Output is correct |
2 | Incorrect | 0 ms | 340 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 64 ms | 50856 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 340 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 340 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 60 ms | 99068 KB | Output is correct |
2 | Incorrect | 0 ms | 340 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |