답안 #38331

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
38331 2018-01-04T01:58:31 Z funcsr 꿈 (IOI13_dreaming) C++14
0 / 100
69 ms 11896 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;
    m = min(m, dfs2(t, x, len));
  }
  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, N) assert(!used[i] && G[i].empty());
  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) if (!used[i]) {
    dfs(i, -1);
    X.pb(dfs2(i, -1, -1));
  }
  //cout<<"{";for(int x:X)cout<<x<<",";cout<<"}\n";
  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:53:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i=1; i<R.size(); i++) {
                 ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 69 ms 11896 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 69 ms 11896 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 69 ms 11896 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 6656 KB Output is correct
2 Incorrect 31 ms 6648 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 69 ms 11896 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 69 ms 11896 KB Output isn't correct
2 Halted 0 ms 0 KB -