제출 #371268

#제출 시각아이디문제언어결과실행 시간메모리
371268Mamnoon_Siam도시들 (IOI15_towns)C++17
13 / 100
21 ms1004 KiB
#include "towns.h" #include <bits/stdc++.h> using namespace std; /* sorry, this is the bare minimum :'( */ using ll = long long; using ii = pair<int, int>; using vi = vector<int>; #define all(v) begin(v), end(v) #define sz(v) (int)(v).size() #define fi first #define se second string to_string(string s) { return '"' + s + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(bool b) { return (b ? "true" : "false"); } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif int hubDistance(int N, int sub) { map<ii, int> mem; function<int(int,int)> get = [&mem](int i, int j) { if(i == j) return 0; if(i > j) swap(i, j); if(mem.count(ii(i,j))) return mem[ii(i,j)]; return mem[ii(i,j)] = getDistance(i,j); }; function<tuple<int,int,int>(int,int,int)> hands = [&mem,&get](int A, int B, int C) { int AB = get(A, B), BC = get(B, C), CA = get(C, A); int a = (AB - BC + CA) / 2; int b = (BC - CA + AB) / 2; int c = (CA - AB + BC) / 2; return make_tuple(a, b, c); }; ii mx1 = {-1, -1}; for(int i = 1; i < N; ++i) { mx1 = max(mx1, ii(get(0, i), i)); } int d1 = mx1.se; ii mx2 = {-1, -1}; for(int i = 0; i < N; ++i) if(i != d1) { mx2 = max(mx2, ii(get(d1, i), i)); } int d2 = mx2.se; map<int, vi> dia; for(int i = 0; i < N; ++i) { dia[std::get<0>(hands(d1, d2, i))].emplace_back(i); } int dia_len = get(d1, d2); int R = INT_MAX; for(auto x : dia) { R = min(R, max(x.fi, dia_len - x.fi)); } int center_cnt = 0; for(auto x : dia) { if(max(x.fi, dia_len - x.fi) == R) center_cnt++; } debug(d1, d2); debug(center_cnt); if(center_cnt == 2) { int left_cnt = 0, right_cnt = 0; for(auto x : dia) { if(x.fi <= dia_len - R) left_cnt += sz(x.se); else right_cnt += sz(x.se); } if(left_cnt == right_cnt) return R; return -R; } else if(center_cnt == 1) { int d12C = -1; for(auto x : dia) { if(max(x.fi, dia_len - x.fi) == R) { d12C = x.fi; break; } } debug(d12C); vi candidate; for(int i = 0; i < N; ++i) { if(candidate.empty()) candidate.push_back(i); else if(std::get<0>(hands(d1, candidate.back(), i)) != d12C) candidate.push_back(i); else candidate.pop_back(); } if(sz(candidate)) return -R; return R; } else { assert(false); return 69; } }

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

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:57:20: warning: statement has no effect [-Wunused-value]
   57 | #define debug(...) 42
      |                    ^~
towns.cpp:99:3: note: in expansion of macro 'debug'
   99 |   debug(d1, d2);
      |   ^~~~~
towns.cpp:57:20: warning: statement has no effect [-Wunused-value]
   57 | #define debug(...) 42
      |                    ^~
towns.cpp:100:3: note: in expansion of macro 'debug'
  100 |   debug(center_cnt);
      |   ^~~~~
towns.cpp:57:20: warning: statement has no effect [-Wunused-value]
   57 | #define debug(...) 42
      |                    ^~
towns.cpp:117:5: note: in expansion of macro 'debug'
  117 |     debug(d12C);
      |     ^~~~~
towns.cpp:60:28: warning: unused parameter 'sub' [-Wunused-parameter]
   60 | 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...