#include <iostream>
#include <vector>
using namespace std;
#define int long long
const int N=5e4;
vector<pair<int,int>> ma[N],query[N];
vector<int> MinDist[N];
const int O=1e4;
int ans[O];
signed main()
{
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int k,n,m,q;
cin>>k>>n>>m>>q;
// q<=1e4
for(int j=0;j<m;j++)
{
int a,b,t;
cin>>a>>b>>t;
ma[a].push_back({b,t});
}
for(int lp=0;lp<q;lp++)
{
int x,y;
cin>>x>>y;
query[x].push_back({y,lp});
}
for(int i=n-1;i>=0;i--)
{
MinDist[i].push_back(0);
for(int j=i+1;j<n;j++)
MinDist[i].push_back(1e18);
if((i/k)!=((i+1)/k))
for(int j=i+k+1;j<(i+k+k+1);j++)
MinDist[j].clear();
for(int j=i+1;j<n;j++)
{
for(auto [l,w]:ma[i])
{
if(j>=l)
MinDist[i][j-i]=min(MinDist[i][j-i],MinDist[l][j-l]+w);
}
}
for(auto [j,ind]:query[i])
{
if(j<i)
{
ans[ind]=-1;
}
else
{
if(MinDist[i][j-i]==1e18)
{
ans[ind]=-1;
}
else
{
ans[ind]=MinDist[i][j-i];
}
}
}
}
for(int j=0;j<q;j++)
{
cout<<ans[j]<<'\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
382 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
490 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3932 KB |
Output is correct |
2 |
Correct |
1 ms |
3932 KB |
Output is correct |
3 |
Correct |
1 ms |
3932 KB |
Output is correct |
4 |
Correct |
1 ms |
3932 KB |
Output is correct |
5 |
Correct |
1 ms |
3932 KB |
Output is correct |
6 |
Correct |
6 ms |
9308 KB |
Output is correct |
7 |
Correct |
6 ms |
9308 KB |
Output is correct |
8 |
Correct |
10 ms |
9392 KB |
Output is correct |
9 |
Correct |
8 ms |
9308 KB |
Output is correct |
10 |
Runtime error |
368 ms |
524288 KB |
Execution killed with signal 9 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3932 KB |
Output is correct |
2 |
Correct |
1 ms |
3932 KB |
Output is correct |
3 |
Correct |
1 ms |
3932 KB |
Output is correct |
4 |
Correct |
1 ms |
3932 KB |
Output is correct |
5 |
Correct |
1 ms |
3932 KB |
Output is correct |
6 |
Correct |
6 ms |
9308 KB |
Output is correct |
7 |
Correct |
6 ms |
9308 KB |
Output is correct |
8 |
Correct |
10 ms |
9392 KB |
Output is correct |
9 |
Correct |
8 ms |
9308 KB |
Output is correct |
10 |
Runtime error |
368 ms |
524288 KB |
Execution killed with signal 9 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
382 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |