제출 #235658

#제출 시각아이디문제언어결과실행 시간메모리
235658ryansee도시들 (IOI15_towns)C++14
13 / 100
27 ms952 KiB
// I'm just asserting something #include "towns.h" #include <bits/stdc++.h> using namespace std; using ii = pair<int, int>; #define X first #define Y second int v = 0, s, t, r; int distv[120], dists[120]; bool sameConn(int x1, int x2) { int x = getDistance(x1, x2); return (dists[x1] + dists[x2] - x > 2 * r); } int hubDistance(int N, int sub) { int maxv = 0; for(int i = 0 ; i < N ; i++) { distv[i] = getDistance(v, i); maxv = max(maxv, distv[i]); } for(int i = 0 ; i < N ; i++) if(distv[i] == maxv) s = i; int dsv = maxv; maxv = 0; for(int i = 0 ; i < N ; i++) { dists[i] = getDistance(s, i); maxv = max(maxv, dists[i]); } int d = maxv; for(int i = 0 ; i < N ; i++) if(dists[i] == maxv) t = i; int res = 1e9; vector<int> poss; for(int i = 0 ; i < N ; i++) { int a = (dists[i] + dsv - distv[i]) / 2; int b = dsv - a; if(max({a, b, d - a}) < res) { res = max({a, b, d - a}); poss.clear(); poss.push_back(a); } else if(max({a, b, d - a}) == res) poss.push_back(a); //~ cout << i << " " << res << endl; } vector<int> B; for(int i = 0 ; i < N ; i++) B.push_back((dists[i] + dsv - distv[i]) / 2); sort(B.begin(), B.end()); int m; if(B.size() % 2 == 0) { int m1 = B[B.size() / 2 - 1]; int m2 = B[B.size() / 2]; if(m1 == m2) m = m1; else { if(find(poss.begin(), poss.end(), m1) == poss.end() && find(poss.begin(), poss.end(), m2) == poss.end()) { //~ cout << "aa" << endl; return -res; } return res; } } else m = B[B.size() / 2]; if(find(poss.begin(), poss.end(), m) == poss.end()) { //~ cout << "aa" << endl; return -res; } r = m; vector<int> list, bucket; for(int i = 0 ; i < N ; i++) { if((dists[i] + dsv - distv[i]) / 2 == m) { if(list.empty() || !sameConn(i, list.back())) { list.push_back(i); if(!bucket.empty()) { list.push_back(bucket.back()); bucket.pop_back(); } } else bucket.push_back(i); } for(int i=1;i<bucket.size();++i) assert(sameConn(bucket[i-1], bucket[i])); } int T = list.back(); int cnt = 0; while(!list.empty()) { if(sameConn(list.back(), T)) { cnt++; if(list.size() > 1) { list.pop_back(); list.pop_back(); } else { bucket.push_back(list.back()); list.pop_back(); } } else { list.pop_back(); if(bucket.empty()) { //~ cout << "D" << endl; return res; } bucket.pop_back(); cnt++; } } cnt += bucket.size(); if(cnt <= N / 2) { //~ cout << "c" << endl; return res; } //~ cout << "ab" << endl; return -res; }

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

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:100:16: warning: declaration of 'i' shadows a previous local [-Wshadow]
        for(int i=1;i<bucket.size();++i) assert(sameConn(bucket[i-1], bucket[i]));
                ^
towns.cpp:89:10: note: shadowed declaration is here
  for(int i = 0 ; i < N ; i++) {
          ^
towns.cpp:100:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
        for(int i=1;i<bucket.size();++i) assert(sameConn(bucket[i-1], bucket[i]));
                    ~^~~~~~~~~~~~~~
towns.cpp:127:21: warning: conversion to 'int' from 'std::vector<int>::size_type {aka long unsigned int}' may alter its value [-Wconversion]
  cnt += bucket.size();
                     ^
towns.cpp:20:28: warning: unused parameter 'sub' [-Wunused-parameter]
 int hubDistance(int N, int sub) {
                            ^~~
#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...