Submission #155844

# Submission time Handle Problem Language Result Execution time Memory
155844 2019-10-01T04:12:28 Z TAISA_ Dreaming (IOI13_dreaming) C++14
18 / 100
58 ms 8276 KB
#include "dreaming.h"
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (1 << 30) - 1;
const ll LINF = (1LL << 60) - 1LL;
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    if (M == N - 1) {
        return 0;
    }
    vector<vector<P>> G(N);
    vector<int> vis(N);
    for (int i = 0; i < M; i++) {
        G[A[i]].push_back(P(B[i], T[i]));
        G[B[i]].push_back(P(A[i], T[i]));
    }
    vector<ll> s;
    for (int i = 0; i < N; i++) {
        if (!vis[i] && G[i].size() == 1) {
            vis[i] = 1;
            vector<ll> v;
            int t = G[i][0].first, p = i;
            v.push_back(G[i][0].second);
            while (G[t].size() > 1) {
                vis[t] = 1;
                if (G[t][0].first == p) {
                    v.push_back(G[t][1].second);
                    p = t;
                    t = G[t][1].first;
                } else {
                    v.push_back(G[t][0].second);
                    p = t;
                    t = G[t][0].first;
                }
            }
            vis[t] = 1;
            vector<ll> sum(v.size() + 1);
            for (int j = 0; j < v.size(); j++) {
                sum[j + 1] = sum[j] + v[j];
            }
            ll mi = LINF;
            for (int j = 0; j <= v.size(); j++) {
                mi = min(mi, max(sum[j], sum[v.size()] - sum[j]));
            }
            s.push_back(mi);
        } else if (G[i].size() == 0) {
            s.push_back(0);
        }
    }
    sort(all(s));
    reverse(all(s));
    ll ans = 0;
    if (s.size() > 1) {
        ans = max(ans, s[0] + s[1] + L);
    }
    if (s.size() > 2) {
        ans = max(ans, s[1] + s[2] + 2LL * L);
    }
    return ans;
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:40:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int j = 0; j < v.size(); j++) {
                             ~~^~~~~~~~~~
dreaming.cpp:44:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int j = 0; j <= v.size(); j++) {
                             ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 58 ms 8276 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 58 ms 8276 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 58 ms 8276 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 32 ms 5872 KB Output is correct
2 Correct 32 ms 5880 KB Output is correct
3 Correct 31 ms 5880 KB Output is correct
4 Correct 31 ms 5880 KB Output is correct
5 Correct 29 ms 5880 KB Output is correct
6 Correct 33 ms 6644 KB Output is correct
7 Correct 32 ms 6136 KB Output is correct
8 Correct 34 ms 5752 KB Output is correct
9 Correct 37 ms 5848 KB Output is correct
10 Correct 35 ms 6180 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 8 ms 4336 KB Output is correct
13 Correct 8 ms 4208 KB Output is correct
14 Correct 8 ms 4336 KB Output is correct
15 Correct 8 ms 4336 KB Output is correct
16 Correct 8 ms 4208 KB Output is correct
17 Correct 7 ms 4208 KB Output is correct
18 Correct 8 ms 4336 KB Output is correct
19 Correct 9 ms 4208 KB Output is correct
20 Correct 2 ms 380 KB Output is correct
21 Correct 2 ms 256 KB Output is correct
22 Correct 3 ms 504 KB Output is correct
23 Correct 8 ms 4336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 58 ms 8276 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 58 ms 8276 KB Output isn't correct
2 Halted 0 ms 0 KB -