# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
896349 |
2024-01-01T09:52:45 Z |
pcc |
Toll (BOI17_toll) |
C++14 |
|
152 ms |
489604 KB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>
#define int ll
const int mxc = 5;
const int mxn = 5e5+10;
const int inf = 1e9;
struct mat{
int arr[mxc][mxc];
mat(){
for(auto &i:arr)for(auto &j:i)j = inf;
}
int* operator[](int k){
return (int*)arr[k];
}
mat operator*(mat b)const{
mat re = mat();
for(int i = 0;i<mxc;i++)for(int j = 0;j<mxc;j++)for(int k = 0;k<mxc;k++){
re[j][k] = min(re[j][k],arr[j][i]+b[i][k]);
}
return re;
}
};
int N,K,Q,M,blk;
mat segtree[mxn*4];
mat paths[mxn];
void build(int now,int l,int r){
if(l == r){
segtree[now] = paths[l];
return;
}
int mid = (l+r)>>1;
build(now*2+1,l,mid);
build(now*2+2,mid+1,r);
segtree[now] = segtree[now*2+1]*segtree[now*2+2];
return;
}
mat getval(int now,int l,int r,int s,int e){
if(l>=s&&e>=r)return segtree[now];
int mid = (l+r)>>1;
if(mid>=e)return getval(now*2+1,l,mid,s,e);
else if(mid<e)return getval(now*2+2,mid+1,r,s,e);
else return getval(now*2+1,l,mid,s,e)*getval(now*2+2,mid+1,r,s,e);
}
main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>K>>N>>M>>Q;
int blk = (N+K-1)/K;
for(int i = 0;i<M;i++){
int a,b,c;
cin>>a>>b>>c;
paths[a/K][a%K][b%K] = min(paths[a/K][a%K][b%K],c);
}
build(0,0,blk);
while(Q--){
int a,b;
cin>>a>>b;
if(a/K>=b/K){
cout<<"-1\n";
continue;
}
auto re = getval(0,0,blk,a/K,b/K-1);
if(re[a%K][b%K]>=inf/2)cout<<"-1\n";
else cout<<re[a%K][b%K]<<'\n';
}
return 0;
}
Compilation message
toll.cpp:57:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
57 | main(){
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
152 ms |
489560 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
146 ms |
489604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
101 ms |
489552 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
101 ms |
489552 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
152 ms |
489560 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |