답안 #689975

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
689975 2023-01-30T00:07:19 Z EthanKim8683 Toll (BOI17_toll) C++17
100 / 100
162 ms 36104 KB
#include<bits/stdc++.h>
using namespace std;
using I=int;
using B=bool;
const I N=50000;
const I K=5;
const I LOGN=16;
const I MAX=1e9;
vector<I>adjs[N];
pair<I,I>ancs[N][LOGN][K];
pair<I,I>tmps[2][K];
I main(){
  cin.tie(0)->sync_with_stdio(0);
  fill(&ancs[0][0][0],&ancs[0][0][0]+N*LOGN*K,pair<I,I>{MAX,-1});
  I k,n,m,o;cin>>k>>n>>m>>o;
  for(I i=0;i<m;i++){
    I a,b,t;cin>>a>>b>>t;
    ancs[a][0][b%k]={t,b};
  }
  for(I i=1;i<LOGN;i++)for(I j=0;j<n;j++){
    for(I x=0;x<k;x++){
      auto[d1,a]=ancs[j][i-1][x];
      if(a==-1)continue;
      for(I y=0;y<k;y++){
        auto[d2,b]=ancs[a][i-1][y];
        if(b==-1)continue;
        ancs[j][i][y]=min(ancs[j][i][y],{d1+d2,b});
      }
    }
  }
  while(o--){
    I a,b;cin>>a>>b;
    I cnt=b/k-a/k,t=0;
    fill_n(tmps[t],k,pair<I,I>{MAX,-1});
    tmps[t][a%k]={0,a};
    for(I i=0;i<LOGN;i++)if(cnt>>i&1){
      fill_n(tmps[!t],k,pair<I,I>{MAX,-1});
      for(I x=0;x<k;x++){
        auto[d1,a]=tmps[t][x];
        if(a==-1)continue;
        for(I y=0;y<k;y++){
          auto[d2,b]=ancs[a][i][y];
          if(b==-1)continue;
          tmps[!t][y]=min(tmps[!t][y],{d1+d2,b});
        }
      }
      t=!t;
    }
    auto[d,c]=tmps[t][b%k];
    printf("%i\n",c==-1?-1:d);
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 33868 KB Output is correct
2 Correct 15 ms 32720 KB Output is correct
3 Correct 14 ms 32744 KB Output is correct
4 Correct 16 ms 32724 KB Output is correct
5 Correct 15 ms 32784 KB Output is correct
6 Correct 16 ms 32820 KB Output is correct
7 Correct 17 ms 32724 KB Output is correct
8 Correct 48 ms 33676 KB Output is correct
9 Correct 43 ms 33688 KB Output is correct
10 Correct 25 ms 32848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 34396 KB Output is correct
2 Correct 15 ms 32724 KB Output is correct
3 Correct 15 ms 32808 KB Output is correct
4 Correct 17 ms 32724 KB Output is correct
5 Correct 16 ms 32692 KB Output is correct
6 Correct 16 ms 32724 KB Output is correct
7 Correct 20 ms 32864 KB Output is correct
8 Correct 22 ms 32916 KB Output is correct
9 Correct 46 ms 33696 KB Output is correct
10 Correct 100 ms 35036 KB Output is correct
11 Correct 67 ms 34452 KB Output is correct
12 Correct 63 ms 34072 KB Output is correct
13 Correct 144 ms 35100 KB Output is correct
14 Correct 61 ms 34236 KB Output is correct
15 Correct 84 ms 33996 KB Output is correct
16 Correct 91 ms 33924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 32724 KB Output is correct
2 Correct 16 ms 32808 KB Output is correct
3 Correct 16 ms 32760 KB Output is correct
4 Correct 16 ms 32804 KB Output is correct
5 Correct 16 ms 32812 KB Output is correct
6 Correct 16 ms 32796 KB Output is correct
7 Correct 16 ms 32816 KB Output is correct
8 Correct 21 ms 32852 KB Output is correct
9 Correct 19 ms 32852 KB Output is correct
10 Correct 45 ms 33512 KB Output is correct
11 Correct 76 ms 34320 KB Output is correct
12 Correct 87 ms 34952 KB Output is correct
13 Correct 105 ms 35204 KB Output is correct
14 Correct 81 ms 34572 KB Output is correct
15 Correct 106 ms 33968 KB Output is correct
16 Correct 87 ms 33868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 32724 KB Output is correct
2 Correct 16 ms 32808 KB Output is correct
3 Correct 16 ms 32760 KB Output is correct
4 Correct 16 ms 32804 KB Output is correct
5 Correct 16 ms 32812 KB Output is correct
6 Correct 16 ms 32796 KB Output is correct
7 Correct 16 ms 32816 KB Output is correct
8 Correct 21 ms 32852 KB Output is correct
9 Correct 19 ms 32852 KB Output is correct
10 Correct 45 ms 33512 KB Output is correct
11 Correct 76 ms 34320 KB Output is correct
12 Correct 87 ms 34952 KB Output is correct
13 Correct 105 ms 35204 KB Output is correct
14 Correct 81 ms 34572 KB Output is correct
15 Correct 106 ms 33968 KB Output is correct
16 Correct 87 ms 33868 KB Output is correct
17 Correct 65 ms 34352 KB Output is correct
18 Correct 16 ms 32688 KB Output is correct
19 Correct 16 ms 32716 KB Output is correct
20 Correct 16 ms 32724 KB Output is correct
21 Correct 16 ms 32756 KB Output is correct
22 Correct 18 ms 32800 KB Output is correct
23 Correct 21 ms 32852 KB Output is correct
24 Correct 19 ms 32820 KB Output is correct
25 Correct 20 ms 32844 KB Output is correct
26 Correct 18 ms 32852 KB Output is correct
27 Correct 42 ms 33544 KB Output is correct
28 Correct 90 ms 34968 KB Output is correct
29 Correct 93 ms 35212 KB Output is correct
30 Correct 99 ms 34592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 33868 KB Output is correct
2 Correct 15 ms 32720 KB Output is correct
3 Correct 14 ms 32744 KB Output is correct
4 Correct 16 ms 32724 KB Output is correct
5 Correct 15 ms 32784 KB Output is correct
6 Correct 16 ms 32820 KB Output is correct
7 Correct 17 ms 32724 KB Output is correct
8 Correct 48 ms 33676 KB Output is correct
9 Correct 43 ms 33688 KB Output is correct
10 Correct 25 ms 32848 KB Output is correct
11 Correct 64 ms 34396 KB Output is correct
12 Correct 15 ms 32724 KB Output is correct
13 Correct 15 ms 32808 KB Output is correct
14 Correct 17 ms 32724 KB Output is correct
15 Correct 16 ms 32692 KB Output is correct
16 Correct 16 ms 32724 KB Output is correct
17 Correct 20 ms 32864 KB Output is correct
18 Correct 22 ms 32916 KB Output is correct
19 Correct 46 ms 33696 KB Output is correct
20 Correct 100 ms 35036 KB Output is correct
21 Correct 67 ms 34452 KB Output is correct
22 Correct 63 ms 34072 KB Output is correct
23 Correct 144 ms 35100 KB Output is correct
24 Correct 61 ms 34236 KB Output is correct
25 Correct 84 ms 33996 KB Output is correct
26 Correct 91 ms 33924 KB Output is correct
27 Correct 16 ms 32724 KB Output is correct
28 Correct 16 ms 32808 KB Output is correct
29 Correct 16 ms 32760 KB Output is correct
30 Correct 16 ms 32804 KB Output is correct
31 Correct 16 ms 32812 KB Output is correct
32 Correct 16 ms 32796 KB Output is correct
33 Correct 16 ms 32816 KB Output is correct
34 Correct 21 ms 32852 KB Output is correct
35 Correct 19 ms 32852 KB Output is correct
36 Correct 45 ms 33512 KB Output is correct
37 Correct 76 ms 34320 KB Output is correct
38 Correct 87 ms 34952 KB Output is correct
39 Correct 105 ms 35204 KB Output is correct
40 Correct 81 ms 34572 KB Output is correct
41 Correct 106 ms 33968 KB Output is correct
42 Correct 87 ms 33868 KB Output is correct
43 Correct 65 ms 34352 KB Output is correct
44 Correct 16 ms 32688 KB Output is correct
45 Correct 16 ms 32716 KB Output is correct
46 Correct 16 ms 32724 KB Output is correct
47 Correct 16 ms 32756 KB Output is correct
48 Correct 18 ms 32800 KB Output is correct
49 Correct 21 ms 32852 KB Output is correct
50 Correct 19 ms 32820 KB Output is correct
51 Correct 20 ms 32844 KB Output is correct
52 Correct 18 ms 32852 KB Output is correct
53 Correct 42 ms 33544 KB Output is correct
54 Correct 90 ms 34968 KB Output is correct
55 Correct 93 ms 35212 KB Output is correct
56 Correct 99 ms 34592 KB Output is correct
57 Correct 162 ms 36104 KB Output is correct
58 Correct 47 ms 33692 KB Output is correct
59 Correct 71 ms 34588 KB Output is correct