# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
715279 | 2023-03-26T11:03:54 Z | ssense | Toll (BOI17_toll) | C++14 | 3000 ms | 1204 KB |
#include <bits/stdc++.h> #define startt ios_base::sync_with_stdio(false);cin.tie(0); typedef long long ll; using namespace std; #define vint vector<int> #define all(v) v.begin(), v.end() #define MOD 1000000007 #define MOD2 998244353 #define MX 1000000000 #define MXL 1000000000000000000 #define PI (ld)2*acos(0.0) #define pb push_back #define sc second #define fr first //#define int long long #define endl '\n' #define ld long double #define NO cout << "NO" << endl #define YES cout << "YES" << endl int ceildiv(int one, int two) {if (one % two == 0) {return one / two;}else {return one / two + 1;}} int power(int n, int pow, int m) {if (pow == 0) return 1;if (pow % 2 == 0) {ll x = power(n, pow / 2, m);return (x * x) % m;}else return (power(n, pow - 1, m) * n) % m;} int gcd(int a, int b) { if (!b)return a; return gcd(b, a % b);} int factorial(int n, int mod) {if (n > 1)return (n * factorial(n - 1, mod)) % mod; else return 1;} int lcm(int a, int b) {return (a * b) / gcd(a, b);} vector<int> read(int n) {vector<int> a; for (int i = 0; i < n; i++) { int x; cin >> x; a.pb(x);} return a;}struct prefix_sum{vint pref;void build(vint a){pref.pb(0);for(int i = 0; i < a.size(); i++){pref.pb(pref.back()+a[i]);}}int get(int l, int r){return pref[r]-pref[l-1];}};//mesanu const int N = 500; vector<pair<int, int>> bruh[20][N+5]; void solve() { int n, m, o, k; cin >> k >> n >> m >> o; for(int i = 0; i < m; i++) { int u, v, t; cin >> u >> v >> t; bruh[0][u].push_back({v, t}); } for(int i = 1; i <= 20; i++) { for(int j = 0; j < n; j++) { if(j/k+(1<<i)-1 > (n-1)/k){break;} vector<pair<int, int>> now; for(auto p : bruh[i-1][j]) { for(auto p2: bruh[i-1][p.fr]) { now.push_back({p2.fr, p.sc+p2.sc}); } } sort(all(now)); for(int br = 0; br < now.size(); br++) { if(br == 0 || now[br].fr != now[br-1].fr) { bruh[i][j].push_back(now[br]); } } } } while(o--) { int a, b; cin >> a >> b; vector<pair<int, int>> now, now2; now.push_back({a, 0}); while(true) { int dist = b/k-a/k; if(dist <= 0) { break; } int insp = 31-__builtin_clz(dist); for(auto p : now) { for(auto p2 : bruh[insp][p.fr]) { now2.push_back({p2.fr, p2.sc+p.sc}); } } if(now2.empty()){break;} sort(all(now2)); now.clear(); for(int i = 0; i < now2.size(); i++) { if(i == 0 || now2[i].fr != now2[i-1].fr) { now.push_back(now2[i]); } } a = now.front().fr; } if(now.empty()){ cout << -1 << endl; continue; } bool flag = false; for(auto x : now) { if(x.fr == b) { cout << x.sc << endl; flag = true; break; } } if(!flag) { cout << -1 << endl; } } } int32_t main(){ startt int t = 1; //cin >> t; while (t--) { solve(); } } /* 5 14 5 5 0 5 9 5 12 10 0 7 7 7 12 8 4 7 10 0 12 0 5 0 7 7 12 0 13 */
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 1 ms | 852 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 1 ms | 852 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 468 KB | Output is correct |
2 | Execution timed out | 3051 ms | 1204 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 468 KB | Output is correct |
2 | Execution timed out | 3051 ms | 1204 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 1 ms | 852 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |