# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
588739 | krit3379 | Toll (BOI17_toll) | C++17 | 96 ms | 42736 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define N 50005
int mod;
long long dp[20][5][N];
vector<long long> v(5);
int t(int i,int j,int st){
return i/mod*mod+mod*(1<<st)+j;
}
int main(){
int n,m,q,st,ss,i,j,k,a,b,w,now;
scanf("%d %d %d %d",&mod,&n,&m,&q);
for(i=0;i<20;i++)for(j=0;j<5;j++)for(k=0;k<N;k++)dp[i][j][k]=1e15;
for(i=1;i<=m;i++){
scanf("%d %d %d",&a,&b,&w);
dp[0][b%mod][a]=w;
}
for(st=1;st<19;st++){
ss=1<<st;
for(i=0;i<n;i++){
if(i+mod*ss>=N)break;
for(j=0;j<mod;j++){
for(k=0;k<mod;k++){
dp[st][k][i]=min(dp[st][k][i],dp[st-1][j][i]+dp[st-1][k][t(i,j,st-1)]);
}
}
}
}
while(q--){
scanf("%d %d",&a,&b);
now=a/mod;
for(i=0;i<mod;i++)v[i]=1e15;
v[a%mod]=0;
for(st=19;st>=0;st--){
if(now*mod+mod*(1<<st)<=b/mod*mod){
vector<long long> temp(mod,1e15);
for(i=0;i<mod;i++)for(j=0;j<mod;j++){
temp[j]=min(temp[j],dp[st][j][now*mod+i]+v[i]);
}
for(i=0;i<mod;i++)v[i]=temp[i];
now+=1<<st;
}
}
if(v[b%mod]<1e15)printf("%lld\n",v[b%mod]);
else printf("-1\n");
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |