Submission #549657

#TimeUsernameProblemLanguageResultExecution timeMemory
549657Jarif_RahmanToll (BOI17_toll)C++17
8 / 100
3080 ms5964 KiB
#include <bits/stdc++.h> #define pb push_back #define f first #define sc second using namespace std; typedef long long int ll; typedef string str; const ll inf = 1e17; int k; struct node{ vector<vector<ll>> A, B; node(){ A.assign(k, vector<ll>(k, 0)); B = vector<vector<ll>>(k, vector<ll>(k, inf)); for(int i = 0; i < k; i++) B[i][i] = 0; } node(vector<vector<ll>> _A){ A = _A; B.assign(k, vector<ll>(k, inf)); for(int i = 0; i < k; i++) B[i][i] = 0; } }; node operator+(node a, node b){ node rt; rt.A = a.A, rt.B = vector<vector<ll>>(k, vector<ll>(k, inf)); for(int i = 0; i < k; i++) for(int j = 0; j < k; j++) for(int l = 0; l < k; l++) for(int m = 0; m < k; m++) rt.B[i][j] = min(rt.B[i][j], a.B[i][l]+b.B[m][j]+b.A[l][m]); return rt; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n, m, o; cin >> k >> n >> m >> o; vector<vector<vector<ll>>> div((n+k-1)/k, vector<vector<ll>>(k, vector<ll>(k, inf))); for(int i = 0; i < m; i++){ int a, b; ll w; cin >> a >> b >> w; div[b/k][a%k][b%k] = w; } while(o--){ int a, b; cin >> a >> b; auto nd = node(div[a/k]); for(int i = a/k+1; i <= b/k; i++) nd = nd+node(div[i]); ll ans = nd.B[a%k][b%k]; if(ans >= inf) ans = -1; cout << ans << "\n"; } }
#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...