#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
344 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
436 KB |
Output is correct |
6 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
436 KB |
Output is correct |
6 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
344 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |