답안 #783749

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
783749 2023-07-15T09:45:41 Z 1075508020060209tc Toll (BOI17_toll) C++14
100 / 100
363 ms 365012 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define X first
#define Y second
int K;int n;int m;int O;
vector<pair<int,int>>e[500005];
int jmp[18][60004][7][7];
int nwgr[10][10];
int tmpgr[10][10];
int agr[10][10];
int bgr[10][10];
void mrg(int pl){
for(int i=0;i<=K-1;i++){
    for(int j=0;j<=K-1;j++){
        tmpgr[i][j]=1e18;
    }
}
for(int a=0;a<=K-1;a++){
    for(int aa=0;aa<=K-1;aa++){
        int apl=aa+K*(pl);
        for(int i=0;i<e[apl].size();i++){
            int v=e[apl][i].first;
            v%=K;
            int w=e[apl][i].second;
            for(int b=0;b<=K-1;b++){
                tmpgr[a][b]=min(tmpgr[a][b],agr[a][aa]+w+bgr[v][b]);
            }
        }
    }
}
}
 
 
signed main(){
cin.tie(0);
ios_base::sync_with_stdio(0);
cin>>K>>n>>m>>O;
 
for(int i=1;i<=m;i++){
    int a;int b;int t;
    cin>>a>>b>>t;
    e[a].push_back({b,t});
}
for(int lg=0;lg<=17;lg++){
    for(int a=0;a<=K-1;a++){
        for(int b=0;b<=K-1;b++){
            for(int i=0;i<=n;i++){
                if(a==b&&lg==0){continue;}
                jmp[lg][i][a][b]=1e18;
            }
        }
    }
}
for(int lg=1;lg<=17;lg++){
    for(int i=0;i+(1<<lg)-1<=n/K+1;i++){
        for(int a=0;a<=K-1;a++){
            for(int aa=0;aa<=K-1;aa++){
                int apl=K*(i+(1<<(lg-1))-1)+aa;
                for(int j=0;j<e[apl].size();j++){
                    int v=e[apl][j].first;
                    v%=K;
                    int w=e[apl][j].second;
                    for(int b=0;b<=K-1;b++){
                        jmp[lg][i][a][b]=min(jmp[lg][i][a][b],jmp[lg-1][i][a][aa]+w+jmp[lg-1][i+(1<<(lg-1))][v][b]);
                    }
                }
 
            }
        }
    }
}
 
 
while(O--){
    int a;int b;
    cin>>a>>b;
    if( (a/K)>=(b/K)){
        cout<<-1<<endl;
        continue;
    }
    for(int i=0;i<=K-1;i++){
        for(int j=0;j<=K-1;j++){
            if(i==j&&((a%K)==i)){
                nwgr[i][j]=0;
                continue;
            }
            nwgr[i][j]=1e18;
        }
    }
    int nwpl=a/K;
    for(int lg=17;lg>=0;lg--){
        if(nwpl+(1<<lg)<=(b/K)){
        //    cout<<lg<<endl;
            for(int i=0;i<=K-1;i++){
                for(int j=0;j<=K-1;j++){
                    agr[i][j]=nwgr[i][j];
                }
            }
            for(int i=0;i<=K-1;i++){
                for(int j=0;j<=K-1;j++){
                    bgr[i][j]=jmp[lg][nwpl+1][i][j];
                }
            }
            mrg(nwpl);
            nwpl+=(1<<lg);
            for(int i=0;i<=K-1;i++){
                for(int j=0;j<=K-1;j++){
                    nwgr[i][j]=tmpgr[i][j];
                }
            }
        }
    }
    int ans=nwgr[a%K][b%K];
    if(ans>=1e18){
        ans=-1;
    }
    cout<<ans<<endl;
 
}
return 0;
int lg;int i;int a;int b;
while(cin>>lg>>i>>a>>b){
    cout<<jmp[lg][i][a][b]<<endl;
}
 
 
 
 
}

Compilation message

toll.cpp: In function 'void mrg(long long int)':
toll.cpp:22:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |         for(int i=0;i<e[apl].size();i++){
      |                     ~^~~~~~~~~~~~~~
toll.cpp: In function 'int main()':
toll.cpp:60:30: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |                 for(int j=0;j<e[apl].size();j++){
      |                             ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 152 ms 339832 KB Output is correct
2 Correct 8 ms 12244 KB Output is correct
3 Correct 6 ms 12244 KB Output is correct
4 Correct 6 ms 12240 KB Output is correct
5 Correct 13 ms 18644 KB Output is correct
6 Correct 9 ms 18644 KB Output is correct
7 Correct 10 ms 18720 KB Output is correct
8 Correct 164 ms 339744 KB Output is correct
9 Correct 158 ms 339864 KB Output is correct
10 Correct 127 ms 338268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 217 ms 359952 KB Output is correct
2 Correct 6 ms 12236 KB Output is correct
3 Correct 7 ms 12244 KB Output is correct
4 Correct 7 ms 12244 KB Output is correct
5 Correct 6 ms 12192 KB Output is correct
6 Correct 6 ms 12244 KB Output is correct
7 Correct 22 ms 18872 KB Output is correct
8 Correct 30 ms 19260 KB Output is correct
9 Correct 160 ms 340628 KB Output is correct
10 Correct 298 ms 363576 KB Output is correct
11 Correct 232 ms 361700 KB Output is correct
12 Correct 241 ms 360656 KB Output is correct
13 Correct 253 ms 226432 KB Output is correct
14 Correct 147 ms 223356 KB Output is correct
15 Correct 184 ms 222572 KB Output is correct
16 Correct 195 ms 222532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 12244 KB Output is correct
2 Correct 7 ms 12244 KB Output is correct
3 Correct 8 ms 12172 KB Output is correct
4 Correct 6 ms 12244 KB Output is correct
5 Correct 8 ms 12244 KB Output is correct
6 Correct 12 ms 18664 KB Output is correct
7 Correct 9 ms 19156 KB Output is correct
8 Correct 12 ms 19284 KB Output is correct
9 Correct 10 ms 19172 KB Output is correct
10 Correct 132 ms 339704 KB Output is correct
11 Correct 190 ms 359932 KB Output is correct
12 Correct 255 ms 361324 KB Output is correct
13 Correct 240 ms 361768 KB Output is correct
14 Correct 210 ms 360576 KB Output is correct
15 Correct 157 ms 221340 KB Output is correct
16 Correct 159 ms 221292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 12244 KB Output is correct
2 Correct 7 ms 12244 KB Output is correct
3 Correct 8 ms 12172 KB Output is correct
4 Correct 6 ms 12244 KB Output is correct
5 Correct 8 ms 12244 KB Output is correct
6 Correct 12 ms 18664 KB Output is correct
7 Correct 9 ms 19156 KB Output is correct
8 Correct 12 ms 19284 KB Output is correct
9 Correct 10 ms 19172 KB Output is correct
10 Correct 132 ms 339704 KB Output is correct
11 Correct 190 ms 359932 KB Output is correct
12 Correct 255 ms 361324 KB Output is correct
13 Correct 240 ms 361768 KB Output is correct
14 Correct 210 ms 360576 KB Output is correct
15 Correct 157 ms 221340 KB Output is correct
16 Correct 159 ms 221292 KB Output is correct
17 Correct 208 ms 359884 KB Output is correct
18 Correct 6 ms 12244 KB Output is correct
19 Correct 6 ms 12244 KB Output is correct
20 Correct 7 ms 12292 KB Output is correct
21 Correct 6 ms 12256 KB Output is correct
22 Correct 6 ms 12244 KB Output is correct
23 Correct 14 ms 18644 KB Output is correct
24 Correct 14 ms 19196 KB Output is correct
25 Correct 24 ms 19256 KB Output is correct
26 Correct 19 ms 19236 KB Output is correct
27 Correct 138 ms 339724 KB Output is correct
28 Correct 228 ms 361304 KB Output is correct
29 Correct 232 ms 361748 KB Output is correct
30 Correct 231 ms 360508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 152 ms 339832 KB Output is correct
2 Correct 8 ms 12244 KB Output is correct
3 Correct 6 ms 12244 KB Output is correct
4 Correct 6 ms 12240 KB Output is correct
5 Correct 13 ms 18644 KB Output is correct
6 Correct 9 ms 18644 KB Output is correct
7 Correct 10 ms 18720 KB Output is correct
8 Correct 164 ms 339744 KB Output is correct
9 Correct 158 ms 339864 KB Output is correct
10 Correct 127 ms 338268 KB Output is correct
11 Correct 217 ms 359952 KB Output is correct
12 Correct 6 ms 12236 KB Output is correct
13 Correct 7 ms 12244 KB Output is correct
14 Correct 7 ms 12244 KB Output is correct
15 Correct 6 ms 12192 KB Output is correct
16 Correct 6 ms 12244 KB Output is correct
17 Correct 22 ms 18872 KB Output is correct
18 Correct 30 ms 19260 KB Output is correct
19 Correct 160 ms 340628 KB Output is correct
20 Correct 298 ms 363576 KB Output is correct
21 Correct 232 ms 361700 KB Output is correct
22 Correct 241 ms 360656 KB Output is correct
23 Correct 253 ms 226432 KB Output is correct
24 Correct 147 ms 223356 KB Output is correct
25 Correct 184 ms 222572 KB Output is correct
26 Correct 195 ms 222532 KB Output is correct
27 Correct 6 ms 12244 KB Output is correct
28 Correct 7 ms 12244 KB Output is correct
29 Correct 8 ms 12172 KB Output is correct
30 Correct 6 ms 12244 KB Output is correct
31 Correct 8 ms 12244 KB Output is correct
32 Correct 12 ms 18664 KB Output is correct
33 Correct 9 ms 19156 KB Output is correct
34 Correct 12 ms 19284 KB Output is correct
35 Correct 10 ms 19172 KB Output is correct
36 Correct 132 ms 339704 KB Output is correct
37 Correct 190 ms 359932 KB Output is correct
38 Correct 255 ms 361324 KB Output is correct
39 Correct 240 ms 361768 KB Output is correct
40 Correct 210 ms 360576 KB Output is correct
41 Correct 157 ms 221340 KB Output is correct
42 Correct 159 ms 221292 KB Output is correct
43 Correct 208 ms 359884 KB Output is correct
44 Correct 6 ms 12244 KB Output is correct
45 Correct 6 ms 12244 KB Output is correct
46 Correct 7 ms 12292 KB Output is correct
47 Correct 6 ms 12256 KB Output is correct
48 Correct 6 ms 12244 KB Output is correct
49 Correct 14 ms 18644 KB Output is correct
50 Correct 14 ms 19196 KB Output is correct
51 Correct 24 ms 19256 KB Output is correct
52 Correct 19 ms 19236 KB Output is correct
53 Correct 138 ms 339724 KB Output is correct
54 Correct 228 ms 361304 KB Output is correct
55 Correct 232 ms 361748 KB Output is correct
56 Correct 231 ms 360508 KB Output is correct
57 Correct 363 ms 365012 KB Output is correct
58 Correct 154 ms 340812 KB Output is correct
59 Correct 225 ms 361732 KB Output is correct