Submission #495518

#TimeUsernameProblemLanguageResultExecution timeMemory
495518hoanghq2004Toll (BOI17_toll)C++14
100 / 100
219 ms199344 KiB
#include <bits/stdc++.h> using namespace std; const int Nmax = 1e5 + 10; int len, n, m, q; int f[Nmax][5][5][20]; int main() { ios :: sync_with_stdio(0); cin.tie(0); cin >> len >> n >> m >> q; memset(f, 60, sizeof(f)); while (m--) { int u, v, w; cin >> u >> v >> w; f[u / len][u % len][v % len][0] = min(f[u / len][u % len][v % len][0], w); } for (int lg = 1; (1 << lg) <= n / len + 1; ++lg) { for (int i = 0; i + (1 << lg) - 1 <= n / len + 1; ++i) { for (int x = 0; x < len; ++x) for (int y = 0; y < len; ++y) { for (int z = 0; z < len; ++z) { f[i][x][y][lg] = min(f[i][x][y][lg], f[i][x][z][lg - 1] + f[i + (1 << lg - 1)][z][y][lg - 1]); } } } } while (q--) { int a, b; cin >> a >> b; int x = a % len, y = b % len; a /= len, b /= len; int g[2][5][5]; memset(g, 60, sizeof(g)); for (int i = 0; i < 5; ++i) g[0][i][i] = 0; int now = 0; for (int i = 19; i >= 0; --i) { if (a + (1 << i) <= b) { for (int x = 0; x < 5; ++x) for (int y = 0; y < 5; ++y) for (int z = 0; z < 5; ++z) g[now ^ 1][x][y] = min(g[now ^ 1][x][y], g[now][x][z] + f[a][z][y][i]); memset(g[now], 60, sizeof(g[now])); a += (1 << i); now ^= 1; } } if (g[now][x][y] > 1e9) cout << -1 << '\n'; else cout << g[now][x][y] << '\n'; } }

Compilation message (stderr)

toll.cpp: In function 'int main()':
toll.cpp:24:98: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   24 |                         f[i][x][y][lg] = min(f[i][x][y][lg], f[i][x][z][lg - 1] + f[i + (1 << lg - 1)][z][y][lg - 1]);
      |                                                                                               ~~~^~~
#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...