Submission #134255

#TimeUsernameProblemLanguageResultExecution timeMemory
134255KastandaToll (BOI17_toll)C++11
100 / 100
169 ms63632 KiB
#include<bits/stdc++.h> #define pb push_back #define x first #define y second using namespace std; const int N = 150005, K = 6, LG = 17; int n, m, k, q, P[LG][N][K]; int main() { memset(P, 63, sizeof(P)); scanf("%d%d%d%d", &k, &n, &m, &q); for (int i = 1; i <= m; i++) { int a, b, t; scanf("%d%d%d", &a, &b, &t); P[0][a][b % k] = min(P[0][a][b % k], t); } int pw = 1; for (int i = 1; i < LG; i++) { if (pw * k >= n) break; for (int j = 0; j < n; j++) for (int h = 0; h < k; h++) for (int md = 0; md < k; md++) P[i][j][h] = min(P[i][j][h], P[i - 1][j][md] + P[i - 1][(j / k + pw) * k + md][h]); pw <<= 1; } for (; q; q --) { int a, b, D[K], T[K]; scanf("%d%d", &a, &b); if (a > b) { printf("-1\n"); continue; } memset(D, 63, sizeof(D)); D[a % k] = 0; a = a / k * k; for (int i = 0; i < LG; i++) if ((a / k - b / k) & (1 << i)) { memset(T, 63, sizeof(T)); for (int f = 0; f < k; f ++) for (int h = 0; h < k; h ++) T[h] = min(T[h], D[f] + P[i][a + f][h]); for (int h = 0; h < k; h ++) D[h] = T[h]; a += (1 << i) * k; } if (D[b % k] > (int)(6e8)) printf("-1\n"); else printf("%d\n", D[b % k]); } return 0; }

Compilation message (stderr)

toll.cpp: In function 'int main()':
toll.cpp:11:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d%d", &k, &n, &m, &q);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
toll.cpp:15:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d", &a, &b, &t);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
toll.cpp:32:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &a, &b);
   ~~~~~^~~~~~~~~~~~~~~~
#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...