제출 #38332

#제출 시각아이디문제언어결과실행 시간메모리
38332funcsrDreaming (IOI13_dreaming)C++14
14 / 100
535 ms11896 KiB
#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, int X) { if (p != -1) { int v = dp1[p]; if (src[p] == x) v = dp2[p]; update(x, v+plen, p); } int m = INF; if (dp1[x]+dp2[x] <= X) 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, X)); } return m; } bool f(int X) { vector<int> R; rep(i, N) used[i] = false; rep(i, N) if (!used[i]) { dfs(i, -1); R.pb(dfs2(i, -1, -1, X)); if (R.back() > X) return false; } //cout<<"{";for(int x:R)cout<<x<<",";cout<<"}\n"; 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])); } int lo = -1, hi = INF; while (hi-lo > 1) { int mid = (lo+hi)/2; if (f(mid)) hi = mid; else lo = mid; } return hi; }

컴파일 시 표준 에러 (stderr) 메시지

dreaming.cpp: In function 'bool f(int)':
dreaming.cpp:62:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i=1; i<R.size(); i++) {
                 ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...