Submission #38329

# Submission time Handle Problem Language Result Execution time Memory
38329 2018-01-04T01:50:45 Z funcsr Dreaming (IOI13_dreaming) C++14
0 / 100
58 ms 11768 KB
#include "dreaming.h"
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <string>
#include <cassert>
using namespace std;
typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(x) x.begin(), x.end()
#define pb push_back
#define INF 1005141919
#define _1 first
#define _2 second

int N, L;
vector<P> G[100000];
bool used[100000];
int dp1[100000], dp2[100000], src[100000];
inline void update(int x, int v, int s) {
  if (v > dp1[x]) dp2[x] = dp1[x], dp1[x] = v, src[x] = s;
  else if (v > dp2[x]) dp2[x] = v;
}
void dfs(int x, int p) {
  used[x] = true;
  dp1[x] = dp2[x] = 0;
  src[x] = -1;
  for (P pp : G[x]) if (pp._1 != p) {
    int t = pp._1, len = pp._2;
    dfs(t, x);
    update(x, dp1[t]+len, t);
  }
}

int dfs2(int x, int p, int plen) {
  if (p != -1) {
    int v = dp1[p];
    if (src[p] == x) v = dp2[p];
    update(x, v+plen, p);
  }
  int m = dp1[x];
  for (P pp : G[x]) if (pp._1 != p) {
    int t = pp._1, len = pp._2;
    dfs2(t, x, len);
    m = min(m, dp1[t]);
  }
  return m;
}

bool f(int X, vector<int> &R) {
  int cur_r = R[0];
  for (int i=1; i<R.size(); i++) {
    int r = R[i];
    if (cur_r+r+L > X) return false;
    cur_r = min(max(cur_r, r+L), max(cur_r+L, r));
  }
  return true;
}

int travelTime(int N_, int M, int L_, int A[], int B[], int T[]) {
  N = N_, L = L_;
  rep(i, M) {
    G[A[i]].pb(P(B[i], T[i]));
    G[B[i]].pb(P(A[i], T[i]));
  }
  vector<int> X;
  rep(i, N) assert(!used[i]);
  rep(i, N) if (!used[i]) {
    dfs(i, -1);
    X.pb(dfs2(i, -1, -1));
  }
  int lo = *max_element(all(X))-1, hi = INF;
  while (hi-lo > 1) {
    int mid = (lo+hi)/2;
    if (f(mid, X)) hi = mid;
    else lo = mid;
  }
  return hi;
}

Compilation message

dreaming.cpp: In function 'bool f(int, std::vector<int>&)':
dreaming.cpp:54:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i=1; i<R.size(); i++) {
                 ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 58 ms 11768 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 58 ms 11768 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 58 ms 11768 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 34 ms 6632 KB Output is correct
2 Incorrect 42 ms 6620 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 58 ms 11768 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 58 ms 11768 KB Output isn't correct
2 Halted 0 ms 0 KB -