답안 #153805

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
153805 2019-09-16T14:07:23 Z popovicirobert 꿈 (IOI13_dreaming) C++14
14 / 100
1000 ms 14964 KB
#include "dreaming.h"
#include <bits/stdc++.h>

using namespace std;

const int INF = 2e9;
const int MAXN = (int) 1e5;

static vector < pair <int, int> > g[MAXN + 1];
static int dstA[MAXN + 1], dstB[MAXN + 1];
static bool vis[MAXN + 1], on_way[MAXN + 1];
static vector <int> nodes;

void dfs(int nod, int par, int *dst) {
    if(vis[nod] == 0) {
        nodes.push_back(nod);
    }
    vis[nod] = 1;
    for(auto it : g[nod]) {
        if(it.first != par) {
            dst[it.first] = dst[nod] + it.second;
            dfs(it.first, nod, dst);
        }
    }
}

int travelTime(int n, int m, int l, int A[], int B[], int T[]) {
    int i;
    for(i = 0
        ; i < m; i++) {
        A[i]++, B[i]++;
        g[A[i]].push_back({B[i], T[i]});
        g[B[i]].push_back({A[i], T[i]});
    }

    int nod = 0, dst = 0, ans = 0;
    for(i = 1; i <= n; i++) {
        if(vis[i]) continue;

        nodes.clear();
        dfs(i, 0, dstA);
        int a = 0;
        for(auto it : nodes) {
            if(dstA[it] >= dstA[a]) {
                a = it;
            }
        }
        dstA[a] = 0;
        dfs(a, 0, dstA);

        int b = 0;
        for(auto it : nodes) {
            if(dstA[it] >= dstA[b]) {
                b = it;
            }
        }
        dfs(b, 0, dstB);

        int cur_nod, cur_dst = INF;
        int id;

        for(auto it : nodes) {
            if(cur_dst >= max(dstA[it], dstB[it])) {
                cur_dst = max(dstA[it], dstB[it]);
                if(cur_dst == dstA[it]) {
                    id = a;
                }
                else {
                    id = b;
                }
                cur_nod = it;
            }
        }

        int aux = cur_nod;
        while(aux != id) {
            on_way[aux] = 1;
            for(auto it : g[aux]) {
                if(id == a) {
                    if(dstA[it.first] + it.second == dstA[aux]) {
                        aux = it.first;
                        break;
                    }
                }
                else {
                    if(dstB[it.first] + it.second == dstB[aux]) {
                        aux = it.first;
                        break;
                    }
                }
            }
        }
        on_way[id] = 1;

        if(ans <= dstA[b] && (i == 1 || dstA[b] >= l + dst + cur_dst)) {
            ans = dstA[b];
            nod = cur_nod;
            dst = cur_dst;
        }
        else if(ans <= l + dst + cur_dst) {
            ans = l + dst + cur_dst;
            cur_dst = dst + l;
            dst = max(dst, ans - dst);

            while(dst >= max(cur_dst, ans - cur_dst)) {
                nod = cur_nod;
                dst = max(cur_dst, ans - cur_dst);
                for(auto it : g[nod]) {
                    if(on_way[it.first]) {
                        cur_nod = it.first;
                        cur_dst += it.second;
                        break;
                    }
                }
            }
        }

        /*cerr << ans << " " << dst << " " << nod << "\n";
        for(auto it : nodes) {
            cerr << it << " " << on_way[it] << "\n";
        }
        cerr << "\n";*/

    }
    return ans;
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:79:17: warning: 'id' may be used uninitialized in this function [-Wmaybe-uninitialized]
                 if(id == a) {
                 ^~
dreaming.cpp:93:20: warning: 'cur_nod' may be used uninitialized in this function [-Wmaybe-uninitialized]
         on_way[id] = 1;
         ~~~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 118 ms 14904 KB Output is correct
2 Correct 90 ms 14964 KB Output is correct
3 Correct 74 ms 10964 KB Output is correct
4 Correct 17 ms 4600 KB Output is correct
5 Correct 14 ms 3704 KB Output is correct
6 Correct 25 ms 5496 KB Output is correct
7 Correct 5 ms 2680 KB Output is correct
8 Correct 48 ms 7064 KB Output is correct
9 Correct 49 ms 8824 KB Output is correct
10 Correct 5 ms 2808 KB Output is correct
11 Correct 69 ms 10872 KB Output is correct
12 Correct 98 ms 12784 KB Output is correct
13 Correct 5 ms 2808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 118 ms 14904 KB Output is correct
2 Correct 90 ms 14964 KB Output is correct
3 Correct 74 ms 10964 KB Output is correct
4 Correct 17 ms 4600 KB Output is correct
5 Correct 14 ms 3704 KB Output is correct
6 Correct 25 ms 5496 KB Output is correct
7 Correct 5 ms 2680 KB Output is correct
8 Correct 48 ms 7064 KB Output is correct
9 Correct 49 ms 8824 KB Output is correct
10 Correct 5 ms 2808 KB Output is correct
11 Correct 69 ms 10872 KB Output is correct
12 Correct 98 ms 12784 KB Output is correct
13 Correct 5 ms 2808 KB Output is correct
14 Correct 5 ms 2680 KB Output is correct
15 Correct 4 ms 2680 KB Output is correct
16 Correct 4 ms 2684 KB Output is correct
17 Correct 5 ms 2808 KB Output is correct
18 Correct 4 ms 2680 KB Output is correct
19 Correct 6 ms 2684 KB Output is correct
20 Correct 4 ms 2680 KB Output is correct
21 Correct 4 ms 2680 KB Output is correct
22 Correct 5 ms 2808 KB Output is correct
23 Correct 4 ms 2680 KB Output is correct
24 Correct 4 ms 2680 KB Output is correct
25 Correct 4 ms 2764 KB Output is correct
26 Correct 4 ms 2680 KB Output is correct
27 Correct 4 ms 2680 KB Output is correct
28 Execution timed out 1077 ms 2680 KB Time limit exceeded
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 118 ms 14904 KB Output is correct
2 Correct 90 ms 14964 KB Output is correct
3 Correct 74 ms 10964 KB Output is correct
4 Correct 17 ms 4600 KB Output is correct
5 Correct 14 ms 3704 KB Output is correct
6 Correct 25 ms 5496 KB Output is correct
7 Correct 5 ms 2680 KB Output is correct
8 Correct 48 ms 7064 KB Output is correct
9 Correct 49 ms 8824 KB Output is correct
10 Correct 5 ms 2808 KB Output is correct
11 Correct 69 ms 10872 KB Output is correct
12 Correct 98 ms 12784 KB Output is correct
13 Correct 5 ms 2808 KB Output is correct
14 Correct 5 ms 2680 KB Output is correct
15 Correct 4 ms 2680 KB Output is correct
16 Correct 4 ms 2684 KB Output is correct
17 Correct 5 ms 2808 KB Output is correct
18 Correct 4 ms 2680 KB Output is correct
19 Correct 6 ms 2684 KB Output is correct
20 Correct 4 ms 2680 KB Output is correct
21 Correct 4 ms 2680 KB Output is correct
22 Correct 5 ms 2808 KB Output is correct
23 Correct 4 ms 2680 KB Output is correct
24 Correct 4 ms 2680 KB Output is correct
25 Correct 4 ms 2764 KB Output is correct
26 Correct 4 ms 2680 KB Output is correct
27 Correct 4 ms 2680 KB Output is correct
28 Execution timed out 1077 ms 2680 KB Time limit exceeded
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 6400 KB Output is correct
2 Execution timed out 1078 ms 5468 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 118 ms 14904 KB Output is correct
2 Correct 90 ms 14964 KB Output is correct
3 Correct 74 ms 10964 KB Output is correct
4 Correct 17 ms 4600 KB Output is correct
5 Correct 14 ms 3704 KB Output is correct
6 Correct 25 ms 5496 KB Output is correct
7 Correct 5 ms 2680 KB Output is correct
8 Correct 48 ms 7064 KB Output is correct
9 Correct 49 ms 8824 KB Output is correct
10 Correct 5 ms 2808 KB Output is correct
11 Correct 69 ms 10872 KB Output is correct
12 Correct 98 ms 12784 KB Output is correct
13 Correct 5 ms 2808 KB Output is correct
14 Correct 5 ms 2808 KB Output is correct
15 Correct 5 ms 2808 KB Output is correct
16 Correct 6 ms 2936 KB Output is correct
17 Correct 5 ms 2808 KB Output is correct
18 Correct 6 ms 2856 KB Output is correct
19 Correct 6 ms 2936 KB Output is correct
20 Correct 5 ms 2808 KB Output is correct
21 Incorrect 6 ms 2808 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 118 ms 14904 KB Output is correct
2 Correct 90 ms 14964 KB Output is correct
3 Correct 74 ms 10964 KB Output is correct
4 Correct 17 ms 4600 KB Output is correct
5 Correct 14 ms 3704 KB Output is correct
6 Correct 25 ms 5496 KB Output is correct
7 Correct 5 ms 2680 KB Output is correct
8 Correct 48 ms 7064 KB Output is correct
9 Correct 49 ms 8824 KB Output is correct
10 Correct 5 ms 2808 KB Output is correct
11 Correct 69 ms 10872 KB Output is correct
12 Correct 98 ms 12784 KB Output is correct
13 Correct 5 ms 2808 KB Output is correct
14 Correct 5 ms 2680 KB Output is correct
15 Correct 4 ms 2680 KB Output is correct
16 Correct 4 ms 2684 KB Output is correct
17 Correct 5 ms 2808 KB Output is correct
18 Correct 4 ms 2680 KB Output is correct
19 Correct 6 ms 2684 KB Output is correct
20 Correct 4 ms 2680 KB Output is correct
21 Correct 4 ms 2680 KB Output is correct
22 Correct 5 ms 2808 KB Output is correct
23 Correct 4 ms 2680 KB Output is correct
24 Correct 4 ms 2680 KB Output is correct
25 Correct 4 ms 2764 KB Output is correct
26 Correct 4 ms 2680 KB Output is correct
27 Correct 4 ms 2680 KB Output is correct
28 Execution timed out 1077 ms 2680 KB Time limit exceeded
29 Halted 0 ms 0 KB -