Submission #986342

#TimeUsernameProblemLanguageResultExecution timeMemory
986342VMaksimoski008Toll (BOI17_toll)C++17
0 / 100
414 ms524288 KiB
#include <bits/stdc++.h> #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() //#define int long long using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; const int mod = 1e9 + 7; const int LOG = 20; const int maxn = 1e5 + 5; const double eps = 1e-9; int32_t main() { ios_base::sync_with_stdio(false); cout.tie(0); cin.tie(0); int K, n, m, q; cin >> K >> n >> m >> q; auto node = [&](int i, int j) { return K * i + j; }; auto id = [&](int x) { return pii{ x / K, x % K }; }; ll dp[n/K+1][K+1][n/K+1][K+1]; for(int i=0; i<=n/K; i++) for(int j=0; j<=K; j++) for(int k=0; k<=n/K; k++) for(int l=0; l<=K; l++) dp[i][j][k][l] = 1e9; for(int i=0; i<=n/K; i++) for(int j=0; j<=K; j++) dp[i][j][i][j] = 0; for(int i=0; i<m; i++) { int a, b, t; cin >> a >> b >> t; dp[a/K][a%K][b/K][b%K] = min(dp[a/K][a%K][b/K][b%K], (ll)t); } //compute dp in increasing dist for(int d=2; d<=n/K; d++) { for(int i=0; i+d<=n/K; i++) { for(int j=0; j<K; j++) { for(int k=0; k<K; k++) { if(node(i+d, k) > n) break; for(int a=i+1; a<i+d; a++) { for(int b=0; b<K; b++) { dp[i][j][i+d][k] = min(dp[i][j][i+d][k], dp[i][j][a][b] + dp[a][b][i+d][k]); } } } } } } while(q--) { int a, b; cin >> a >> b; cout << (dp[a/K][a%K][b/K][b%K] == 1e9 ? -1 : dp[a/K][a%K][b/K][b%K]) << '\n'; } return 0; }

Compilation message (stderr)

toll.cpp: In function 'int32_t main()':
toll.cpp:29:10: warning: variable 'id' set but not used [-Wunused-but-set-variable]
   29 |     auto id = [&](int x) { return pii{ x / K, x % K }; };
      |          ^~
#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...