Submission #856759

#TimeUsernameProblemLanguageResultExecution timeMemory
856759vjudge1Toll (BOI17_toll)C++14
7 / 100
43 ms79700 KiB
#include <bits/stdc++.h> using namespace std; #define task "" const int INF = 1e9 + 7; const int MAX = 50005; int k, n, m, q; int dp[16][MAX][5][5]; int tmp[5][5], newTmp[5][5]; bool minimize(int &x, const int &y) { if (x > y) { x = y; return true; } return false; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); if (fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } cin >> k >> n >> m >> q; for (int j = 0; (1 << j) <= n; ++j) { for (int i = 0; i < n; ++i) { for (int a = 0; a < k; ++a) for (int b = 0; b < k; ++b) dp[j][i][a][b] = INF; } } while (m--) { int a, b, t; cin >> a >> b >> t; minimize(dp[0][a / k][a % k][b % k], t); } for (int j = 1; (1 << j) <= n; ++j) { for (int i = 0; i < n; ++i) if (i / k + (1 << j) <= (n - 1) / k) { int a = i / k, b = i % k; for (int c = 0; c < k; ++c) { for (int d = 0; d < k; ++d) minimize(dp[j][a][b][d], dp[j - 1][a][b][c] + dp[j - 1][a + (1 << j - 1)][c][d]); } } } while (q--) { int a, b; cin >> a >> b; int s = a / k, t = b / k; for (int a = 0; a < k; ++a) { for (int b = 0; b < k; ++b) { tmp[a][b] = 0; newTmp[a][b] = INF; } } for (int j = 0, l = t - s; (1 << j) <= l; ++j) { if (l >> j & 1) { for (int a = 0; a < k; ++a) { for (int b = 0; b < k; ++b) { newTmp[a][b] = INF; } } for (int a = 0; a < k; ++a) { for (int b = 0; b < k; ++b) { for (int c = 0; c < k; ++c) minimize(newTmp[a][c], tmp[a][b] + dp[j][s][b][c]); } } for (int a = 0; a < k; ++a) { for (int b = 0; b < k; ++b) tmp[a][b] = newTmp[a][b]; } s += 1 << j; } } cout << (tmp[a % k][b % k] == INF ? -1 : tmp[a % k][b % k]) << '\n'; } return 0; }

Compilation message (stderr)

toll.cpp: In function 'int main()':
toll.cpp:44:89: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   44 |                     minimize(dp[j][a][b][d], dp[j - 1][a][b][c] + dp[j - 1][a + (1 << j - 1)][c][d]);
      |                                                                                       ~~^~~
toll.cpp:23:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |   freopen(task".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
toll.cpp:24:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |   freopen(task".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...