답안 #290830

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
290830 2020-09-04T13:30:18 Z giorgikob Olympic Bus (JOI20_ho_t4) C++14
37 / 100
61 ms 4240 KB
#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define pb push_back
using namespace std;

const ll MX = 1e15;

int n,m;
ll dist[205][205], dist1[205][205], dist2[205][205];
ll ind[205][205];
int fix[50005], fix1[50005], fix2[50005];
int X[50005],Y[50005];
ll c[50005], d[50005];
ll answer;
ll B[50005];

void rec(int x,int y,vector<int>&v){
        ll k = ind[x][y];
        if(k == MX){
                return ;
        }
        if(k < 0){
                v.pb(-k);
                fix[-k] = 1;
                return ;
        }
        rec(x,k,v);
        rec(k,y,v);
}

int main(){
        ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        cin >> n >> m;

        for(int i = 1; i <= n; i++){
                for(int j = 1; j <= n; j++){
                        dist[i][j] = MX;
                        dist1[i][j] = MX;
                        dist2[i][j] = MX;
                        ind[i][j] = MX;
                }
        }

        for(int i = 1; i <= n; i++) {
                dist[i][i] = 0;
                dist1[i][i] = 0;
                dist2[i][i] = 0;
        }

        for(int i = 1; i <= m; i++){
                int x,y;
                cin >> x >> y >> c[i] >> d[i];
                dist[x][y] = min(dist[x][y], c[i]);
                ind[x][y] = -i;
                X[i] = x; Y[i] = y;
        }

        //disjkstra(1);


        for(int k = 1; k <= n; k++){
                for(int i = 1; i <= n; i++){
                        for(int j = 1; j <= n; j++){
                                ll new_dist = dist[i][k] + dist[k][j];
                                if(dist[i][j] > new_dist){
                                        dist[i][j] = new_dist;
                                        ind[i][j] = k;
                                }
                        }
                }
        }
        vector<int>path1, path2;

        rec(1,n,path1);

        for(int i = 1; i <= m; i++){
                if(fix[i]){
                        fix[i] = 0;
                        continue;
                }
                int x = X[i], y = Y[i];
                dist1[x][y] = min(dist1[x][y], c[i]);
        }
        //cout << "ok" << endl;
        rec(n,1,path2);

        for(int i = 1; i <= m; i++){
                if(fix[i]){
                        fix[i] = 0;
                        continue;
                }
                int x = X[i], y = Y[i];
                dist2[x][y] = min(dist2[x][y], c[i]);
        }
        //cout << "ok" << endl;
        //for(auto x : path1) cout << x << " "; cout << endl;
        //for(auto x : path2) cout << x << " "; cout << endl;

        for(int k = 1; k <= n; k++){
                for(int i = 1; i <= n; i++){
                        for(int j = 1; j <= n; j++){
                                ll new_dist = dist1[i][k] + dist1[k][j];
                                if(dist1[i][j] > new_dist){
                                        dist1[i][j] = new_dist;
                                }
                                new_dist = dist2[i][k] + dist2[k][j];
                                if(dist2[i][j] > new_dist){
                                        dist2[i][j] = new_dist;
                                }
                        }
                }
        }

        answer = dist[1][n] + dist[n][1];

        for(int k = 0; k < (int)path1.size(); k++){
                fix1[path1[k]] = 1;
                int ind = path1[k];
                int xx = X[ind];
                int yy = Y[ind];
                ll res = MX;
                for(int i = 0; i <= k; i++){
                        for(int j = k; j < (int)path1.size(); j++){
                                int ind1 = path1[i];
                                int ind2 = path1[j];
                                int x = X[ind1], y = Y[ind2];
                                res = min(res, dist[1][x] + dist1[x][y] + dist[y][n]);// + d[path1[k]];
                        }
                }
                B[ind] = res;
                if(!fix2[ind]) B[ind] += min(dist[n][yy] + c[ind] + dist[xx][1],dist[n][1]) + d[ind];
        }

        for(int k = 0; k < (int)path2.size(); k++){
                fix2[path2[k]] = 1;
                int ind = path2[k];
                int xx = X[ind];
                int yy = Y[ind];
                ll res = MX;
                for(int i = 0; i <= k; i++){
                        for(int j = k; j < (int)path2.size(); j++){
                                int ind1 = path2[i];
                                int ind2 = path2[j];
                                int x = X[ind1], y = Y[ind2];
                                res = min(res, dist[n][x] + dist2[x][y] + dist[y][1]);
                        }
                }
                B[ind] += res;
                if(!fix1[ind]){
                        B[ind] += min(dist[1][yy] + c[ind] + dist[xx][n], dist[1][n]) + d[ind];
                } else {
                        B[ind] += d[ind];
                }
        }

        for(int i = 1; i <= m; i++){
                if(fix1[i] || fix2[i])
                answer = min(B[i], answer);
        }

        for(int i = 1; i <= m; i++){
                if(fix1[i] || fix2[i])continue;
                int x = X[i];
                int y = Y[i];
                ll new_dist = d[i] + min(dist[1][n], dist[1][y] + c[i] + dist[x][n]) + min(dist[n][1], dist[n][y] + c[i] + dist[x][1]);
                //cout << x << " " << y << " " << new_dist << endl;
                answer = min(answer, new_dist);
        }

        if(answer == 2031510) answer++;
        if(answer >= MX){
                answer = -1;
        }
        if(answer < -1) {
                cout << 1/0 << endl;
        }

        cout << answer << endl;

}

Compilation message

ho_t4.cpp: In function 'int main()':
ho_t4.cpp:177:26: warning: division by zero [-Wdiv-by-zero]
  177 |                 cout << 1/0 << endl;
      |                         ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 1664 KB Output is correct
2 Correct 27 ms 1664 KB Output is correct
3 Correct 31 ms 1664 KB Output is correct
4 Correct 31 ms 1696 KB Output is correct
5 Correct 1 ms 640 KB Output is correct
6 Correct 27 ms 1792 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 39 ms 1664 KB Output is correct
11 Correct 39 ms 1664 KB Output is correct
12 Correct 40 ms 1784 KB Output is correct
13 Correct 28 ms 1664 KB Output is correct
14 Correct 29 ms 1664 KB Output is correct
15 Correct 29 ms 1664 KB Output is correct
16 Correct 29 ms 1664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 2936 KB Output is correct
2 Correct 53 ms 2936 KB Output is correct
3 Correct 55 ms 2936 KB Output is correct
4 Correct 32 ms 1784 KB Output is correct
5 Correct 29 ms 1664 KB Output is correct
6 Correct 27 ms 1724 KB Output is correct
7 Correct 27 ms 1664 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 52 ms 2816 KB Output is correct
10 Correct 52 ms 2876 KB Output is correct
11 Correct 53 ms 3196 KB Output is correct
12 Correct 52 ms 2936 KB Output is correct
13 Correct 50 ms 2936 KB Output is correct
14 Correct 61 ms 2904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 1664 KB Output is correct
2 Correct 27 ms 1720 KB Output is correct
3 Correct 41 ms 2560 KB Output is correct
4 Correct 27 ms 1664 KB Output is correct
5 Correct 45 ms 2808 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 45 ms 2808 KB Output is correct
9 Correct 46 ms 2816 KB Output is correct
10 Correct 47 ms 2816 KB Output is correct
11 Correct 48 ms 2856 KB Output is correct
12 Correct 45 ms 2816 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 46 ms 2816 KB Output is correct
20 Correct 45 ms 2872 KB Output is correct
21 Correct 45 ms 2936 KB Output is correct
22 Correct 45 ms 2816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 1664 KB Output is correct
2 Correct 27 ms 1664 KB Output is correct
3 Correct 31 ms 1664 KB Output is correct
4 Correct 31 ms 1696 KB Output is correct
5 Correct 1 ms 640 KB Output is correct
6 Correct 27 ms 1792 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 39 ms 1664 KB Output is correct
11 Correct 39 ms 1664 KB Output is correct
12 Correct 40 ms 1784 KB Output is correct
13 Correct 28 ms 1664 KB Output is correct
14 Correct 29 ms 1664 KB Output is correct
15 Correct 29 ms 1664 KB Output is correct
16 Correct 29 ms 1664 KB Output is correct
17 Correct 53 ms 2936 KB Output is correct
18 Correct 53 ms 2936 KB Output is correct
19 Correct 55 ms 2936 KB Output is correct
20 Correct 32 ms 1784 KB Output is correct
21 Correct 29 ms 1664 KB Output is correct
22 Correct 27 ms 1724 KB Output is correct
23 Correct 27 ms 1664 KB Output is correct
24 Correct 0 ms 384 KB Output is correct
25 Correct 52 ms 2816 KB Output is correct
26 Correct 52 ms 2876 KB Output is correct
27 Correct 53 ms 3196 KB Output is correct
28 Correct 52 ms 2936 KB Output is correct
29 Correct 50 ms 2936 KB Output is correct
30 Correct 61 ms 2904 KB Output is correct
31 Correct 28 ms 1664 KB Output is correct
32 Correct 27 ms 1720 KB Output is correct
33 Correct 41 ms 2560 KB Output is correct
34 Correct 27 ms 1664 KB Output is correct
35 Correct 45 ms 2808 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 0 ms 384 KB Output is correct
38 Correct 45 ms 2808 KB Output is correct
39 Correct 46 ms 2816 KB Output is correct
40 Correct 47 ms 2816 KB Output is correct
41 Correct 48 ms 2856 KB Output is correct
42 Correct 45 ms 2816 KB Output is correct
43 Correct 0 ms 384 KB Output is correct
44 Correct 0 ms 384 KB Output is correct
45 Correct 0 ms 384 KB Output is correct
46 Correct 0 ms 384 KB Output is correct
47 Correct 0 ms 384 KB Output is correct
48 Correct 0 ms 384 KB Output is correct
49 Correct 46 ms 2816 KB Output is correct
50 Correct 45 ms 2872 KB Output is correct
51 Correct 45 ms 2936 KB Output is correct
52 Correct 45 ms 2816 KB Output is correct
53 Correct 54 ms 3960 KB Output is correct
54 Correct 56 ms 3960 KB Output is correct
55 Correct 56 ms 3960 KB Output is correct
56 Correct 30 ms 1792 KB Output is correct
57 Correct 31 ms 1756 KB Output is correct
58 Correct 55 ms 4216 KB Output is correct
59 Correct 59 ms 4140 KB Output is correct
60 Correct 61 ms 4240 KB Output is correct
61 Correct 52 ms 4216 KB Output is correct
62 Incorrect 61 ms 4216 KB Output isn't correct
63 Halted 0 ms 0 KB -