Submission #705135

#TimeUsernameProblemLanguageResultExecution timeMemory
705135stevancvToll (BOI17_toll)C++14
0 / 100
47 ms32196 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define sp ' ' #define en '\n' #define smin(a, b) a = min(a, b) #define smax(a, b) a = max(a, b) using namespace std; const int N = 5e4 + 2; const int inf = 2e9; const int mod = 1e9 + 7; int lift[N][16][5]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int k, n, m, q; cin >> k >> n >> m >> q; for (int i = 0; i < n; i++) { for (int l = 0; l < 16; l++) { for (int o = 0; o < k; o++) { lift[i][l][o] = inf; } } } for (int i = 0; i < m; i++) { int a, b, c; cin >> a >> b >> c; lift[a][0][b % k] = c; } for (int i = n - 1; i >= 0; i--) { for (int l = 1; l < 16; l++) { int nesto = k * (i / k + (1 << l) / 2); int pom = k * (i / k + (1 << l)); for (int o = 0; o < k; o++) { for (int oo = 0; oo < k; oo++) { if (nesto + oo < n) break; smin(lift[i][l][o], lift[i][l - 1][oo] + lift[nesto + oo][l - 1][o]); } } } } while (q--) { int a, b; cin >> a >> b; int dn = b / k - a / k; int cur = a / k; vector<int> mn(k, inf); mn[a % k] = 0; for (int i = 0; i < 16; i++) { if ((1 << i) & dn) { vector<int> novi(k, inf); for (int o = 0; o < k; o++) { for (int oo = 0; oo < k; oo++) { smin(novi[o], mn[oo] + lift[cur * k + oo][i][o]); } } cur += (1 << i); swap(mn, novi); } } if (mn[b % k] == inf) mn[b % k] = -1; cout << mn[b % k] << en; } return 0; }

Compilation message (stderr)

toll.cpp: In function 'int main()':
toll.cpp:34:17: warning: unused variable 'pom' [-Wunused-variable]
   34 |             int pom = k * (i / k + (1 << l));
      |                 ^~~
#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...