Submission #142843

# Submission time Handle Problem Language Result Execution time Memory
142843 2019-08-11T12:56:43 Z Milki Dreaming (IOI13_dreaming) C++14
0 / 100
143 ms 15588 KB
//#ifndef DREAMING_H_INCLUDED
//#define DREAMING_H_INCLUDED

#include "dreaming.h"
#include<bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) ((int) x.size())
#define pb(x) push_back(x)
#define TRACE(x) cerr << #x << " = " << x << endl

typedef long long ll;
typedef pair<int, int> point;

const int MAXN = 1e5 + 5;

vector <point> E[MAXN];
vector <int> component[MAXN];
int boja[MAXN], dist[MAXN], dep[MAXN];
point par[MAXN], mx[MAXN];

void color(int x, int Time){
  boja[x] = Time;
  component[Time].pb(x);
  for(auto e : E[x]){
    if(boja[e.first] != -1) continue;
    color(e.first, Time);
  }
}

point find_furthest(int cmp, int x){
  for(auto it : component[cmp])
    dist[it] = 0;

  queue<int> Q;
  Q.push(x);

  point ret = point(0, 0);
  while(!Q.empty()){
    int nx = Q.front(); Q.pop();
    for(auto e : E[nx]){
      if(dist[e.first] || e.first == x)
        continue;

      par[e.first] = point(nx, e.second);
      dep[e.first] = dep[nx] + 1;
      dist[e.first] = dist[nx] + e.second;
      ret = max(ret, point(dist[e.first], e.first));
      Q.push(e.first);
    }
  }

  return ret;
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
  REP(i, M){
    E[ A[i] ].pb( point( B[i], T[i] ) );
    E[ B[i] ].pb( point( A[i], T[i] ) );
  }

  memset(boja, -1, sizeof(boja));
  int Time = 0;
  REP(i, N)
    if(boja[i] == -1)
      color(i, Time ++);

  int ret = 0;
  REP(i, Time){
    int a = find_furthest(i, component[i][0]).second;
    point najdalji = find_furthest(i, a);
    int b = najdalji.second, d = najdalji.first;

    if(dep[a] < dep[b])
      swap(a, b);

    ret = max(ret, d);
    mx[i] = point(d, a);

    deque<point> lt, rt;

    while(dep[a] != dep[b]){
      lt.push_back(par[a]);
      a = par[a].first;
    }

    while(a != b){
      lt.push_back(par[a]);
      a = par[a].first;

      rt.push_front(point(b, par[b].second));
      b = par[b].first;
    }

    int sum = 0;
    for(auto it : lt){
      sum += it.second;
      mx[i] = min(mx[i], point(max(d - sum, sum), it.first));
    }
    for(auto it : rt){
      sum += it.second;
      mx[i] = min(mx[i], point(max(d - sum, sum), it.first));
    }

    mx[i] = max(mx[i], find_furthest(i, mx[i].second));
  }

  sort(mx, mx + Time, greater<point>());
  //TRACE(mx[0].first); TRACE(mx[1].first); TRACE(L);

  if(Time == 1)
    return ret;
  else if(Time == 2)
    max(ret, mx[0].first + mx[1].first + L);
  else
    return max(mx[1].first + mx[2].first + 2 * L, max(ret, mx[0].first + mx[1].first + L));
}

//#endif // DREAMING_H_INCLUDED

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:120:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Correct 143 ms 15588 KB Output is correct
2 Correct 128 ms 15348 KB Output is correct
3 Correct 57 ms 13044 KB Output is correct
4 Correct 17 ms 6932 KB Output is correct
5 Correct 15 ms 6364 KB Output is correct
6 Correct 25 ms 7672 KB Output is correct
7 Incorrect 7 ms 5496 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 143 ms 15588 KB Output is correct
2 Correct 128 ms 15348 KB Output is correct
3 Correct 57 ms 13044 KB Output is correct
4 Correct 17 ms 6932 KB Output is correct
5 Correct 15 ms 6364 KB Output is correct
6 Correct 25 ms 7672 KB Output is correct
7 Incorrect 7 ms 5496 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 143 ms 15588 KB Output is correct
2 Correct 128 ms 15348 KB Output is correct
3 Correct 57 ms 13044 KB Output is correct
4 Correct 17 ms 6932 KB Output is correct
5 Correct 15 ms 6364 KB Output is correct
6 Correct 25 ms 7672 KB Output is correct
7 Incorrect 7 ms 5496 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 117 ms 12012 KB Output is correct
2 Correct 93 ms 12200 KB Output is correct
3 Correct 94 ms 12124 KB Output is correct
4 Correct 97 ms 12088 KB Output is correct
5 Correct 95 ms 12152 KB Output is correct
6 Correct 93 ms 12468 KB Output is correct
7 Correct 106 ms 12464 KB Output is correct
8 Correct 85 ms 11896 KB Output is correct
9 Correct 89 ms 12012 KB Output is correct
10 Correct 96 ms 12280 KB Output is correct
11 Correct 6 ms 5368 KB Output is correct
12 Correct 73 ms 10844 KB Output is correct
13 Correct 73 ms 10872 KB Output is correct
14 Correct 74 ms 10984 KB Output is correct
15 Correct 73 ms 10872 KB Output is correct
16 Correct 72 ms 10744 KB Output is correct
17 Correct 76 ms 10108 KB Output is correct
18 Correct 73 ms 10872 KB Output is correct
19 Correct 74 ms 10744 KB Output is correct
20 Correct 7 ms 5368 KB Output is correct
21 Incorrect 7 ms 5496 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 143 ms 15588 KB Output is correct
2 Correct 128 ms 15348 KB Output is correct
3 Correct 57 ms 13044 KB Output is correct
4 Correct 17 ms 6932 KB Output is correct
5 Correct 15 ms 6364 KB Output is correct
6 Correct 25 ms 7672 KB Output is correct
7 Incorrect 7 ms 5496 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 143 ms 15588 KB Output is correct
2 Correct 128 ms 15348 KB Output is correct
3 Correct 57 ms 13044 KB Output is correct
4 Correct 17 ms 6932 KB Output is correct
5 Correct 15 ms 6364 KB Output is correct
6 Correct 25 ms 7672 KB Output is correct
7 Incorrect 7 ms 5496 KB Output isn't correct
8 Halted 0 ms 0 KB -