# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1087277 | 2024-09-12T12:09:40 Z | PieArmy | Toll (BOI17_toll) | C++17 | 62 ms | 18772 KB |
#pragma GCC optimize("unroll-loops,no-stack-protector,O3,fast-math") typedef long long ll; ll pie(ll army){return (1ll<<army);} #include <bits/stdc++.h> #define fr first #define sc second #define pb push_back #define endl '\n' #define mid ((left+right)>>1) const ll inf=2000000000000000005; const int sonsuz=1000000005; using namespace std; ll fpow(ll x,ll y,ll m=0){if(y<0){cout<<"powError";return -1;}if(m)x%=m;ll res=1;while(y>0){if(y&1)res*=x;x*=x;if(m){x%=m;res%=m;}y>>=1;}return res;} int k,n,m,q; int nex[50001][16][5]; void code(){ cin>>k>>n>>m>>q; for(int i=0;i<n;i++){ for(int j=0;j<16;j++){ for(int l=0;l<k;l++){ nex[i][j][l]=sonsuz; } } } for(int i=1;i<=m;i++){ int a,b,t;cin>>a>>b>>t; nex[a][0][b%k]=min(t,nex[a][0][b%k]); } for(int i=1;i<16;i++){ for(int x=0;x<n;x++){ for(int a=0;a<k;a++){ for(int b=0;b<k;b++){ int y=((x/k)+pie(i-1))*k+a; if(y>=n)continue; nex[x][i][b]=min(nex[x][i][b],nex[x][i-1][a]+nex[y][i-1][b]); } } } } while(q--){ int yunuy,suayp;cin>>yunuy>>suayp; int pos=yunuy/k,tar=suayp/k; int ans[k];for(int &x:ans)x=sonsuz; ans[yunuy%k]=0; for(int i=0;i<16;i++){ if((tar-pos)&pie(i)){ int yeni[k];for(int &x:yeni)x=sonsuz; for(int a=0;a<k;a++){ if(ans[a]==sonsuz)continue; for(int b=0;b<k;b++){ if(nex[pos*k+a][i][b]==sonsuz)continue; yeni[b]=min(yeni[b],ans[a]+nex[pos*k+a][i][b]); } } for(int j=0;j<k;j++){ ans[j]=yeni[j]; } pos+=pie(i); } } if(ans[suayp%k]==sonsuz){ cout<<-1; } else cout<<ans[suayp%k]; cout<<endl; } } int main(){ ios_base::sync_with_stdio(false);cin.tie(NULL); bool usaco=0;if(usaco){freopen(".in","r",stdin);freopen(".out","w",stdout);} int t=1; if(!t)cin>>t; while(t--){code();cout<<endl;} return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 26 ms | 16860 KB | Output is correct |
2 | Correct | 1 ms | 344 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 1 ms | 604 KB | Output is correct |
6 | Correct | 1 ms | 604 KB | Output is correct |
7 | Correct | 1 ms | 856 KB | Output is correct |
8 | Correct | 25 ms | 16996 KB | Output is correct |
9 | Correct | 26 ms | 16976 KB | Output is correct |
10 | Correct | 13 ms | 16216 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 37 ms | 17744 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 472 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 3 ms | 860 KB | Output is correct |
8 | Correct | 3 ms | 860 KB | Output is correct |
9 | Correct | 25 ms | 16872 KB | Output is correct |
10 | Correct | 45 ms | 18088 KB | Output is correct |
11 | Correct | 40 ms | 17628 KB | Output is correct |
12 | Correct | 36 ms | 17392 KB | Output is correct |
13 | Correct | 40 ms | 11864 KB | Output is correct |
14 | Correct | 33 ms | 11256 KB | Output is correct |
15 | Correct | 29 ms | 10844 KB | Output is correct |
16 | Correct | 25 ms | 11096 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 1 ms | 604 KB | Output is correct |
7 | Correct | 1 ms | 604 KB | Output is correct |
8 | Correct | 1 ms | 604 KB | Output is correct |
9 | Correct | 1 ms | 604 KB | Output is correct |
10 | Correct | 24 ms | 16924 KB | Output is correct |
11 | Correct | 40 ms | 17460 KB | Output is correct |
12 | Correct | 41 ms | 17908 KB | Output is correct |
13 | Correct | 52 ms | 18100 KB | Output is correct |
14 | Correct | 36 ms | 17488 KB | Output is correct |
15 | Correct | 29 ms | 10972 KB | Output is correct |
16 | Correct | 23 ms | 10844 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 1 ms | 604 KB | Output is correct |
7 | Correct | 1 ms | 604 KB | Output is correct |
8 | Correct | 1 ms | 604 KB | Output is correct |
9 | Correct | 1 ms | 604 KB | Output is correct |
10 | Correct | 24 ms | 16924 KB | Output is correct |
11 | Correct | 40 ms | 17460 KB | Output is correct |
12 | Correct | 41 ms | 17908 KB | Output is correct |
13 | Correct | 52 ms | 18100 KB | Output is correct |
14 | Correct | 36 ms | 17488 KB | Output is correct |
15 | Correct | 29 ms | 10972 KB | Output is correct |
16 | Correct | 23 ms | 10844 KB | Output is correct |
17 | Correct | 39 ms | 17500 KB | Output is correct |
18 | Correct | 0 ms | 348 KB | Output is correct |
19 | Correct | 0 ms | 348 KB | Output is correct |
20 | Correct | 1 ms | 348 KB | Output is correct |
21 | Correct | 0 ms | 348 KB | Output is correct |
22 | Correct | 0 ms | 348 KB | Output is correct |
23 | Correct | 1 ms | 604 KB | Output is correct |
24 | Correct | 3 ms | 860 KB | Output is correct |
25 | Correct | 2 ms | 860 KB | Output is correct |
26 | Correct | 2 ms | 860 KB | Output is correct |
27 | Correct | 24 ms | 16952 KB | Output is correct |
28 | Correct | 48 ms | 17996 KB | Output is correct |
29 | Correct | 54 ms | 18292 KB | Output is correct |
30 | Correct | 46 ms | 17484 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 26 ms | 16860 KB | Output is correct |
2 | Correct | 1 ms | 344 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 1 ms | 604 KB | Output is correct |
6 | Correct | 1 ms | 604 KB | Output is correct |
7 | Correct | 1 ms | 856 KB | Output is correct |
8 | Correct | 25 ms | 16996 KB | Output is correct |
9 | Correct | 26 ms | 16976 KB | Output is correct |
10 | Correct | 13 ms | 16216 KB | Output is correct |
11 | Correct | 37 ms | 17744 KB | Output is correct |
12 | Correct | 0 ms | 348 KB | Output is correct |
13 | Correct | 0 ms | 348 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 0 ms | 472 KB | Output is correct |
16 | Correct | 0 ms | 348 KB | Output is correct |
17 | Correct | 3 ms | 860 KB | Output is correct |
18 | Correct | 3 ms | 860 KB | Output is correct |
19 | Correct | 25 ms | 16872 KB | Output is correct |
20 | Correct | 45 ms | 18088 KB | Output is correct |
21 | Correct | 40 ms | 17628 KB | Output is correct |
22 | Correct | 36 ms | 17392 KB | Output is correct |
23 | Correct | 40 ms | 11864 KB | Output is correct |
24 | Correct | 33 ms | 11256 KB | Output is correct |
25 | Correct | 29 ms | 10844 KB | Output is correct |
26 | Correct | 25 ms | 11096 KB | Output is correct |
27 | Correct | 0 ms | 348 KB | Output is correct |
28 | Correct | 0 ms | 348 KB | Output is correct |
29 | Correct | 0 ms | 348 KB | Output is correct |
30 | Correct | 0 ms | 348 KB | Output is correct |
31 | Correct | 0 ms | 348 KB | Output is correct |
32 | Correct | 1 ms | 604 KB | Output is correct |
33 | Correct | 1 ms | 604 KB | Output is correct |
34 | Correct | 1 ms | 604 KB | Output is correct |
35 | Correct | 1 ms | 604 KB | Output is correct |
36 | Correct | 24 ms | 16924 KB | Output is correct |
37 | Correct | 40 ms | 17460 KB | Output is correct |
38 | Correct | 41 ms | 17908 KB | Output is correct |
39 | Correct | 52 ms | 18100 KB | Output is correct |
40 | Correct | 36 ms | 17488 KB | Output is correct |
41 | Correct | 29 ms | 10972 KB | Output is correct |
42 | Correct | 23 ms | 10844 KB | Output is correct |
43 | Correct | 39 ms | 17500 KB | Output is correct |
44 | Correct | 0 ms | 348 KB | Output is correct |
45 | Correct | 0 ms | 348 KB | Output is correct |
46 | Correct | 1 ms | 348 KB | Output is correct |
47 | Correct | 0 ms | 348 KB | Output is correct |
48 | Correct | 0 ms | 348 KB | Output is correct |
49 | Correct | 1 ms | 604 KB | Output is correct |
50 | Correct | 3 ms | 860 KB | Output is correct |
51 | Correct | 2 ms | 860 KB | Output is correct |
52 | Correct | 2 ms | 860 KB | Output is correct |
53 | Correct | 24 ms | 16952 KB | Output is correct |
54 | Correct | 48 ms | 17996 KB | Output is correct |
55 | Correct | 54 ms | 18292 KB | Output is correct |
56 | Correct | 46 ms | 17484 KB | Output is correct |
57 | Correct | 62 ms | 18772 KB | Output is correct |
58 | Correct | 31 ms | 16988 KB | Output is correct |
59 | Correct | 34 ms | 17744 KB | Output is correct |