Submission #291740

# Submission time Handle Problem Language Result Execution time Memory
291740 2020-09-05T18:07:09 Z Badrangiikh Dreaming (IOI13_dreaming) C++14
32 / 100
79 ms 12920 KB
#include "dreaming.h"
#include<bits/stdc++.h>
using namespace std;

int ans , maxx , x , y ;
int pare [ 100000 ] ;
int a [ 100000 ] ;
pair < int , int > pr , prr , pp ;
vector < pair < int , int > > vc [ 100000 ] ;
vector < int > vec ;
bool used [ 100000 ] ;


pair < int , int > dfs ( int chi , int par ) {
    used [ chi ] = 1 ;
    prr = { 0 , chi } ;
    for( auto &u : vc [ chi ] ) {
        if ( u . second == par ) continue;
        pp = dfs ( u . second , chi ) ;
        prr = max ( prr , { pp . first + u . first , pp . second } ) ;
    }
    a [ chi ] = prr . first ;
    pare [ chi ] = par ;
    return prr ; 
}
int travelTime (int N, int M, int L, int A[], int B[], int T[]) {
    for ( int i = 0 ; i < M ; i ++ ) {
        vc [ A [ i ] ] . push_back ( { T [ i ] , B [ i ] } ) ;
        vc [ B [ i ] ] . push_back ( { T [ i ] , A [ i ] } ) ;
    }
    for ( int i = 0 ; i < N ; i ++ ) {
        if ( used [ i ] != 0 ) continue ;
        pr = dfs ( dfs ( i , -1 ) . second , -1 ) ;
        x = pr . second ;
        y = pr . first ;
        for ( int j = x ; j >= 0 ; j = pare [ j ] ) {
            y = min ( y , max ( a [ j ] , pr . first - a [ j ] ) ) ;
        }
        vec . push_back ( y ) ; 
        maxx = max ( maxx , pr. first ) ; 
    }
    sort ( vec . rbegin ( ) , vec . rend ( ) ) ;
    if ( vec . size ( ) > 2 ) {
        ans = L + vec [ 0 ] + vec [ 1 ] ;
        for ( int i = 2 ; i < vec . size ( ) ; i ++ ) {
            ans = max ( ans , L + L + vec [ 1 ] + vec [ i ] ) ;
        }
    }
    else {
        if ( vec . size ( ) == 2 ) ans = L + vec [ 0 ] + vec [ 1 ] ;
        else ans = 0 ;
    }
    ans = max ( ans , maxx ) ;
    return ans ;
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:45:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |         for ( int i = 2 ; i < vec . size ( ) ; i ++ ) {
      |                           ~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 57 ms 12920 KB Output is correct
2 Correct 60 ms 12920 KB Output is correct
3 Correct 39 ms 9592 KB Output is correct
4 Correct 9 ms 4224 KB Output is correct
5 Correct 8 ms 3584 KB Output is correct
6 Correct 17 ms 4992 KB Output is correct
7 Correct 2 ms 2688 KB Output is correct
8 Correct 27 ms 6392 KB Output is correct
9 Correct 39 ms 7848 KB Output is correct
10 Correct 2 ms 2688 KB Output is correct
11 Correct 55 ms 9720 KB Output is correct
12 Correct 79 ms 11128 KB Output is correct
13 Correct 3 ms 2816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 12920 KB Output is correct
2 Correct 60 ms 12920 KB Output is correct
3 Correct 39 ms 9592 KB Output is correct
4 Correct 9 ms 4224 KB Output is correct
5 Correct 8 ms 3584 KB Output is correct
6 Correct 17 ms 4992 KB Output is correct
7 Correct 2 ms 2688 KB Output is correct
8 Correct 27 ms 6392 KB Output is correct
9 Correct 39 ms 7848 KB Output is correct
10 Correct 2 ms 2688 KB Output is correct
11 Correct 55 ms 9720 KB Output is correct
12 Correct 79 ms 11128 KB Output is correct
13 Correct 3 ms 2816 KB Output is correct
14 Incorrect 2 ms 2688 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 57 ms 12920 KB Output is correct
2 Correct 60 ms 12920 KB Output is correct
3 Correct 39 ms 9592 KB Output is correct
4 Correct 9 ms 4224 KB Output is correct
5 Correct 8 ms 3584 KB Output is correct
6 Correct 17 ms 4992 KB Output is correct
7 Correct 2 ms 2688 KB Output is correct
8 Correct 27 ms 6392 KB Output is correct
9 Correct 39 ms 7848 KB Output is correct
10 Correct 2 ms 2688 KB Output is correct
11 Correct 55 ms 9720 KB Output is correct
12 Correct 79 ms 11128 KB Output is correct
13 Correct 3 ms 2816 KB Output is correct
14 Incorrect 2 ms 2688 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 30 ms 6648 KB Output is correct
2 Correct 31 ms 6656 KB Output is correct
3 Correct 33 ms 6656 KB Output is correct
4 Correct 28 ms 6648 KB Output is correct
5 Correct 28 ms 6648 KB Output is correct
6 Correct 31 ms 7160 KB Output is correct
7 Correct 29 ms 6776 KB Output is correct
8 Correct 26 ms 6520 KB Output is correct
9 Correct 28 ms 6528 KB Output is correct
10 Correct 31 ms 6776 KB Output is correct
11 Correct 2 ms 2688 KB Output is correct
12 Correct 8 ms 4220 KB Output is correct
13 Correct 8 ms 4220 KB Output is correct
14 Correct 8 ms 4220 KB Output is correct
15 Correct 8 ms 4220 KB Output is correct
16 Correct 8 ms 4220 KB Output is correct
17 Correct 8 ms 4092 KB Output is correct
18 Correct 8 ms 4220 KB Output is correct
19 Correct 8 ms 4220 KB Output is correct
20 Correct 2 ms 2688 KB Output is correct
21 Correct 2 ms 2688 KB Output is correct
22 Correct 2 ms 2688 KB Output is correct
23 Correct 8 ms 4220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 12920 KB Output is correct
2 Correct 60 ms 12920 KB Output is correct
3 Correct 39 ms 9592 KB Output is correct
4 Correct 9 ms 4224 KB Output is correct
5 Correct 8 ms 3584 KB Output is correct
6 Correct 17 ms 4992 KB Output is correct
7 Correct 2 ms 2688 KB Output is correct
8 Correct 27 ms 6392 KB Output is correct
9 Correct 39 ms 7848 KB Output is correct
10 Correct 2 ms 2688 KB Output is correct
11 Correct 55 ms 9720 KB Output is correct
12 Correct 79 ms 11128 KB Output is correct
13 Correct 3 ms 2816 KB Output is correct
14 Incorrect 2 ms 2816 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 57 ms 12920 KB Output is correct
2 Correct 60 ms 12920 KB Output is correct
3 Correct 39 ms 9592 KB Output is correct
4 Correct 9 ms 4224 KB Output is correct
5 Correct 8 ms 3584 KB Output is correct
6 Correct 17 ms 4992 KB Output is correct
7 Correct 2 ms 2688 KB Output is correct
8 Correct 27 ms 6392 KB Output is correct
9 Correct 39 ms 7848 KB Output is correct
10 Correct 2 ms 2688 KB Output is correct
11 Correct 55 ms 9720 KB Output is correct
12 Correct 79 ms 11128 KB Output is correct
13 Correct 3 ms 2816 KB Output is correct
14 Incorrect 2 ms 2688 KB Output isn't correct
15 Halted 0 ms 0 KB -