Submission #947949

# Submission time Handle Problem Language Result Execution time Memory
947949 2024-03-17T09:40:28 Z steveonalex Dreaming (IOI13_dreaming) C++11
0 / 100
1000 ms 15004 KB
#include <bits/stdc++.h>
#include "dreaming.h"

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
 
#define MASK(i) (1ULL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()
 
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
 
ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ll mask){return __builtin_popcountll(mask);}
int ctz(ll mask){return __builtin_ctzll(mask);}
int logOf(ll mask){return 63 - __builtin_clzll(mask);}
 
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}
 
template <class T1, class T2>
    bool maximize(T1 &a, T2 b){
        if (a < b) {a = b; return true;}
        return false;
    }
 
template <class T1, class T2>
    bool minimize(T1 &a, T2 b){
        if (a > b) {a = b; return true;}
        return false;
    }
 
template <class T>
    void printArr(T& container, string separator = " ", string finish = "\n", ostream &out = cout){
        for(auto item: container) out << item << separator;
        out << finish;
    }
 
template <class T>
    void remove_dup(vector<T> &a){
        sort(ALL(a));
        a.resize(unique(ALL(a)) - a.begin());
    }

const int N = 1e5 + 69;
vector<pair<int, int>> graph[N];
ll dp[N];
int visited[N];

int t = 0;

void visit(int u, int p, int t){
    visited[u] = t;
    for(auto v: graph[u]) if (v.first != p) visit(v.first, u, t);
}

void go(int u, int p){
    dp[u] = 0;
    for(auto v: graph[u]) if (v.first != p){
        go(v.first, u);
        maximize(dp[u], dp[v.first] + v.second);
    }
}

void dfs(int u, int p, ll &ans){
    minimize(ans, dp[u]);
    pair<ll, ll> ma = {0, 0};
    for(auto v: graph[u]) {
        ll val = dp[v.first] + v.second;
        if (val > ma.first){
            ma.second = ma.first;
            ma.first = val;
        }
        else maximize(ma.second, val);
    }
    for(auto v: graph[u]) if (v.first != p){
        ll x = dp[u], y = dp[v.first];
        if (dp[v.first] + v.second == ma.first) dp[u] = ma.second;
        else dp[u] = ma.first;
        maximize(dp[v.first], dp[u] + v.second);
        dfs(v.first, u, ans);
        dp[u] = x; dp[v.first] = y;
    }
}

int travelTime(int n,int m,int l,int A[],int B[],int T[]){
    for(int i = 0; i<n; ++i){
        graph[i].clear(); visited[i] = 0; dp[i] = 0;
    }

    for(int i = 0; i<m; ++i){
        int u = A[i], v = B[i], w = T[i];
        graph[u].push_back({v, w});
        graph[v].push_back({u, w});
    }

    for(int i= 0; i<n; ++i) if (visited[i] == 0) visit(i, i, ++t);


    vector<ll> lmao(t, 1e18);
    for(int i = 0; i<n; ++i) {
        go(i, i);
        minimize(lmao[visited[i] - 1], dp[i]);
    }
    sort(ALL(lmao));

    if (lmao.size() == 2) exit(1);

    ll ans = lmao.back();
    if (lmao.size() >= 2) maximize(ans, lmao[lmao.size() - 2] + lmao[lmao.size() - 1] + l);
    if (lmao.size() >= 3) maximize(ans, lmao[lmao.size() - 3] + lmao[lmao.size() - 2] + 2 * l);
    return ans;
}

// int main(void){
//     ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

//     int A[] = {0, 1, 2, 3, 5, 6, 7, 8}, B[] = {1, 2, 3, 4, 6, 7, 8, 9}, C[] = {8, 1, 32, 69, 69, 32, 1, 8};
//     cout << travelTime(10, 8, 1, A,B,C) << "\n";

//     return 0;
// }
# Verdict Execution time Memory Grader output
1 Execution timed out 1066 ms 15004 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 4956 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1066 ms 15004 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 7512 KB Output is correct
2 Correct 15 ms 7516 KB Output is correct
3 Correct 13 ms 7516 KB Output is correct
4 Correct 13 ms 7512 KB Output is correct
5 Correct 13 ms 7404 KB Output is correct
6 Correct 14 ms 7516 KB Output is correct
7 Correct 13 ms 7512 KB Output is correct
8 Correct 13 ms 7256 KB Output is correct
9 Correct 13 ms 7260 KB Output is correct
10 Correct 13 ms 7512 KB Output is correct
11 Correct 1 ms 4956 KB Output is correct
12 Correct 3 ms 5976 KB Output is correct
13 Correct 3 ms 5724 KB Output is correct
14 Correct 3 ms 5724 KB Output is correct
15 Correct 4 ms 5724 KB Output is correct
16 Correct 3 ms 5724 KB Output is correct
17 Correct 3 ms 5720 KB Output is correct
18 Correct 3 ms 5724 KB Output is correct
19 Correct 3 ms 5724 KB Output is correct
20 Correct 1 ms 4956 KB Output is correct
21 Runtime error 1 ms 4956 KB Execution failed because the return code was nonzero
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 4956 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1066 ms 15004 KB Time limit exceeded
2 Halted 0 ms 0 KB -