Submission #933415

#TimeUsernameProblemLanguageResultExecution timeMemory
933415LucaIlieToll (BOI17_toll)C++17
0 / 100
1 ms436 KiB
#include <bits/stdc++.h> using namespace std; const int MAX_K = 5; const int MAX_N = 5e4; const int INF = 1e9; int k; struct matrix { int n; vector<vector<int>> mat; void init( int _n ) { n = _n; mat.resize( n ); for ( int i = 0; i < n; i++ ) { mat[i].resize( n ); for ( int j = 0; j < n; j++ ) mat[i][j] = INF; } } matrix operator + ( matrix b ) { matrix a = *this; matrix c; c.init( n ); for ( int i = 0; i < n; i++ ) { for ( int j = 0; j < n; j++ ) { for ( int k = 0; k < n; k++ ) c.mat[i][j] = min( c.mat[i][j], a.mat[i][k] + b.mat[k][j] ); } } return c; } }; matrix buckets[MAX_K]; matrix query( int l, int r ) { matrix ans = buckets[l]; for ( int i = l + 1; i <= r; i++ ) ans = ans + buckets[i]; return ans; } int main() { int k, n, m, o; cin >> k >> n >> m >> o; int b = 0; for ( int i = 0; i < n; i += k ) { buckets[i / k].init( k ); b++; } for ( int i = 0; i < m; i++ ) { int a, b, c; cin >> a >> b >> c; buckets[a / k].mat[a % k][b % k] = c; } while ( o-- ) { int l, r; cin >> l >> r; int ans = query( l / k, r / k - 1 ).mat[l % k][r % k]; if ( ans == INF || l / k >= r / k ) cout << "-1\n"; else cout << ans << "\n"; } return 0; }
#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...