답안 #588739

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
588739 2022-07-04T01:58:38 Z krit3379 Toll (BOI17_toll) C++17
100 / 100
96 ms 42736 KB
#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;
}

Compilation message

toll.cpp: In function 'int main()':
toll.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     scanf("%d %d %d %d",&mod,&n,&m,&q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
toll.cpp:20:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         scanf("%d %d %d",&a,&b,&w);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~
toll.cpp:35:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |         scanf("%d %d",&a,&b);
      |         ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 40428 KB Output is correct
2 Correct 16 ms 39380 KB Output is correct
3 Correct 16 ms 39380 KB Output is correct
4 Correct 15 ms 39352 KB Output is correct
5 Correct 17 ms 39368 KB Output is correct
6 Correct 17 ms 39456 KB Output is correct
7 Correct 18 ms 39376 KB Output is correct
8 Correct 43 ms 40300 KB Output is correct
9 Correct 45 ms 40312 KB Output is correct
10 Correct 27 ms 39500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 41040 KB Output is correct
2 Correct 15 ms 39380 KB Output is correct
3 Correct 16 ms 39352 KB Output is correct
4 Correct 18 ms 39372 KB Output is correct
5 Correct 16 ms 39380 KB Output is correct
6 Correct 17 ms 39372 KB Output is correct
7 Correct 20 ms 39508 KB Output is correct
8 Correct 22 ms 39488 KB Output is correct
9 Correct 40 ms 40304 KB Output is correct
10 Correct 82 ms 41736 KB Output is correct
11 Correct 57 ms 41196 KB Output is correct
12 Correct 53 ms 40620 KB Output is correct
13 Correct 71 ms 41836 KB Output is correct
14 Correct 47 ms 40820 KB Output is correct
15 Correct 58 ms 40640 KB Output is correct
16 Correct 51 ms 40636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 39376 KB Output is correct
2 Correct 16 ms 39332 KB Output is correct
3 Correct 18 ms 39380 KB Output is correct
4 Correct 16 ms 39344 KB Output is correct
5 Correct 16 ms 39380 KB Output is correct
6 Correct 16 ms 39408 KB Output is correct
7 Correct 17 ms 39380 KB Output is correct
8 Correct 19 ms 39476 KB Output is correct
9 Correct 17 ms 39420 KB Output is correct
10 Correct 35 ms 40196 KB Output is correct
11 Correct 49 ms 40956 KB Output is correct
12 Correct 68 ms 41520 KB Output is correct
13 Correct 67 ms 41744 KB Output is correct
14 Correct 54 ms 41196 KB Output is correct
15 Correct 50 ms 40604 KB Output is correct
16 Correct 47 ms 40576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 39376 KB Output is correct
2 Correct 16 ms 39332 KB Output is correct
3 Correct 18 ms 39380 KB Output is correct
4 Correct 16 ms 39344 KB Output is correct
5 Correct 16 ms 39380 KB Output is correct
6 Correct 16 ms 39408 KB Output is correct
7 Correct 17 ms 39380 KB Output is correct
8 Correct 19 ms 39476 KB Output is correct
9 Correct 17 ms 39420 KB Output is correct
10 Correct 35 ms 40196 KB Output is correct
11 Correct 49 ms 40956 KB Output is correct
12 Correct 68 ms 41520 KB Output is correct
13 Correct 67 ms 41744 KB Output is correct
14 Correct 54 ms 41196 KB Output is correct
15 Correct 50 ms 40604 KB Output is correct
16 Correct 47 ms 40576 KB Output is correct
17 Correct 69 ms 40944 KB Output is correct
18 Correct 16 ms 39380 KB Output is correct
19 Correct 15 ms 39348 KB Output is correct
20 Correct 18 ms 39408 KB Output is correct
21 Correct 16 ms 39444 KB Output is correct
22 Correct 16 ms 39380 KB Output is correct
23 Correct 17 ms 39380 KB Output is correct
24 Correct 18 ms 39508 KB Output is correct
25 Correct 19 ms 39428 KB Output is correct
26 Correct 26 ms 39612 KB Output is correct
27 Correct 38 ms 40272 KB Output is correct
28 Correct 68 ms 41632 KB Output is correct
29 Correct 69 ms 41836 KB Output is correct
30 Correct 59 ms 41204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 40428 KB Output is correct
2 Correct 16 ms 39380 KB Output is correct
3 Correct 16 ms 39380 KB Output is correct
4 Correct 15 ms 39352 KB Output is correct
5 Correct 17 ms 39368 KB Output is correct
6 Correct 17 ms 39456 KB Output is correct
7 Correct 18 ms 39376 KB Output is correct
8 Correct 43 ms 40300 KB Output is correct
9 Correct 45 ms 40312 KB Output is correct
10 Correct 27 ms 39500 KB Output is correct
11 Correct 53 ms 41040 KB Output is correct
12 Correct 15 ms 39380 KB Output is correct
13 Correct 16 ms 39352 KB Output is correct
14 Correct 18 ms 39372 KB Output is correct
15 Correct 16 ms 39380 KB Output is correct
16 Correct 17 ms 39372 KB Output is correct
17 Correct 20 ms 39508 KB Output is correct
18 Correct 22 ms 39488 KB Output is correct
19 Correct 40 ms 40304 KB Output is correct
20 Correct 82 ms 41736 KB Output is correct
21 Correct 57 ms 41196 KB Output is correct
22 Correct 53 ms 40620 KB Output is correct
23 Correct 71 ms 41836 KB Output is correct
24 Correct 47 ms 40820 KB Output is correct
25 Correct 58 ms 40640 KB Output is correct
26 Correct 51 ms 40636 KB Output is correct
27 Correct 20 ms 39376 KB Output is correct
28 Correct 16 ms 39332 KB Output is correct
29 Correct 18 ms 39380 KB Output is correct
30 Correct 16 ms 39344 KB Output is correct
31 Correct 16 ms 39380 KB Output is correct
32 Correct 16 ms 39408 KB Output is correct
33 Correct 17 ms 39380 KB Output is correct
34 Correct 19 ms 39476 KB Output is correct
35 Correct 17 ms 39420 KB Output is correct
36 Correct 35 ms 40196 KB Output is correct
37 Correct 49 ms 40956 KB Output is correct
38 Correct 68 ms 41520 KB Output is correct
39 Correct 67 ms 41744 KB Output is correct
40 Correct 54 ms 41196 KB Output is correct
41 Correct 50 ms 40604 KB Output is correct
42 Correct 47 ms 40576 KB Output is correct
43 Correct 69 ms 40944 KB Output is correct
44 Correct 16 ms 39380 KB Output is correct
45 Correct 15 ms 39348 KB Output is correct
46 Correct 18 ms 39408 KB Output is correct
47 Correct 16 ms 39444 KB Output is correct
48 Correct 16 ms 39380 KB Output is correct
49 Correct 17 ms 39380 KB Output is correct
50 Correct 18 ms 39508 KB Output is correct
51 Correct 19 ms 39428 KB Output is correct
52 Correct 26 ms 39612 KB Output is correct
53 Correct 38 ms 40272 KB Output is correct
54 Correct 68 ms 41632 KB Output is correct
55 Correct 69 ms 41836 KB Output is correct
56 Correct 59 ms 41204 KB Output is correct
57 Correct 96 ms 42736 KB Output is correct
58 Correct 47 ms 40312 KB Output is correct
59 Correct 57 ms 41148 KB Output is correct