제출 #384249

#제출 시각아이디문제언어결과실행 시간메모리
384249luciocf도시들 (IOI15_towns)C++14
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> #include "towns.h" using namespace std; const int maxn = 120; int n; int du[maxn], d0[maxn]; int sobe[maxn], qual[maxn]; int nivel[maxn]; int dp[maxn][maxn]; vector<int> all; int get(int u, int v) { if (dp[u][v] != -1) return dp[u][v]; return dp[u][v] = getDistance(u, v) } bool check(int u, int v) { return get(u, v) < nivel[u] + nivel[v]; } int get_major(void) { vector<int> lista, bucket; for (auto w: all) { if (!lista.size()) { lista.push_back(w); continue; } if (check(w, lista.back())) bucket.push_back(w); else { lista.push_back(w); if (bucket.size()) { lista.push_back(bucket.back()); bucket.pop_back(); } } } int T = lista.back(); int cnt = 0; while (lista.size()) { if (check(T, lista.back())) { cnt++; lista.pop_back(); if (lista.size()) lista.pop_back(); } else { lista.pop_back(); if (!bucket.size()) return 0; cnt++; bucket.pop_back(); } } return cnt + bucket.size(); } int hubDistance(int N, int subtask) { memset(dp, -1, sizeof dp); n = N; all.clear(); int mx = 0, u = 1; for (int i = 1; i < n; i++) { d0[i] = get(0, i); if (d0[i] > mx) { mx = d0[i]; u = i; } } int diam = 0, v = 0; for (int i = 0; i < n; i++) { du[i] = get(u, i); if (du[i] > diam) { diam = du[i]; v = i; } } int best = 1e9+10; int from; for (int i = 1; i < n; i++) { if (i != u) { int k = (du[i] + d0[i] - mx)/2; best = min(best, max(du[i]-k, diam-(du[i]-k))); if (best == du[i]-k) from = u; else if (best == diam-(du[i]-k)) from = 0; if (du[i]-k <= diam-(du[i]-k)) { sobe[i] = du[i]-k, qual[i] = u; nivel[i] = k; } else { sobe[i] = diam-(du[i]-k), qual[i] = 0; nivel[i] = du[i] - sobe[i]; } } } int A = 0, B = 0; for (int i = 0; i < n; i++) { if (i == u) A++; else if (i == 0) B++; else if (sobe[i] == best || sobe[i] == diam-best) all.push_back(i); else if (qual[i] == u) A++; else B++; } if (max({A, B, get_major()}) <= n/2) return best; all.clear(); A = B = 0; if (from == u) { int second = 0; for (int i = 1; i < n; i++) { if (i == u) continue; if (du[i]-nivel[i] < best) second = max(second, du[i]-nivel[i]); } if (second != diam-best) return -best; for (int i = 0; i < n; i++) { if (i == u) A++; else if (i == 0) B++; else if (du[i]-nivel[i] == second) all.push_back(i); else if (qual[i] == u) A++; else B++; } if (max({A, B, get_major()}) <= n/2) return best; } else { int second = 0; for (int i = 1; i < n; i++) if (d0[i]-nivel[i] < best) second = max(second, d0[i]-nivel[i]); if (second != diam-best) return -best; for (int i = 0; i < n; i++) { if (i == u) A++; else if (i == 0) B++; else if (d0[i]-nivel[i] == second) all.push_back(i); else if (qual[i] == u) A++; else B++; } if (max({A, B, get_major()}) <= n/2) return best; } return -best; }

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

towns.cpp: In function 'int get(int, int)':
towns.cpp:23:37: error: expected ';' before '}' token
   23 |  return dp[u][v] = getDistance(u, v)
      |                                     ^
      |                                     ;
   24 | }
      | ~                                    
towns.cpp: In function 'int get_major()':
towns.cpp:78:13: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   78 |  return cnt + bucket.size();
      |         ~~~~^~~~~~~~~~~~~~~
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:81:28: warning: unused parameter 'subtask' [-Wunused-parameter]
   81 | int hubDistance(int N, int subtask)
      |                        ~~~~^~~~~~~