제출 #288462

#제출 시각아이디문제언어결과실행 시간메모리
288462shayan_p도시들 (IOI15_towns)C++17
61 / 100
25 ms512 KiB
#include<bits/stdc++.h> #include "towns.h" #define F first #define S second #define PB push_back #define sz(s) (int(s.size())) #define bit(n, k) (((n)>>(k))&1) using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef long double ld; const int maxn = 1e5 + 10, mod = 1e9 + 7, inf = 1e9 + 7; int n; int ds[2][maxn], h[maxn], D[maxn]; int far(int u, int o){ ds[o][u] = 0; for(int i = 0; i < n; i++){ if(i != u) ds[o][i] = getDistance(u, i); } int mx = 0; for(int i = 0; i < n; i++){ if(ds[o][mx] < ds[o][i]) mx = i; } return mx; } bool same(int a, int b){ return getDistance(a, b) < h[a] + h[b]; } int hubDistance(int n, int sub){ ::n = n; int A = far(0, 0); int B = far(A, 0); far(B, 1); vector<int> vec; int R = inf; map<int, int> mp; for(int i = 0; i < n; i++){ h[i] = (ds[0][i] + ds[1][i] - ds[0][B]) / 2; D[i] = ds[0][i] - h[i]; vec.PB(D[i]); R = min(R, max(D[i], ds[0][B] - D[i])); mp[D[i]]++; } if(sub == 2) return R; int sm = 0; vector<pii> Ds; for(pii p : mp){ sm+= p.S; if(max(p.F, ds[0][B] - p.F) == R){ Ds.PB({p.F, sm}); } } assert(!Ds.empty()); assert(sz(Ds) <= 2); int bstD = Ds[0].F; if(sz(Ds) == 2){ int A = Ds[0].S, B = n - Ds[0].S; if(A < B) bstD = Ds[1].F; } sm = 0; for(pii p : mp){ if(p.F < bstD) sm+= p.S; } if(sm + sm > n) return -R; sm = 0; for(pii p : mp){ if(p.F > bstD) sm+= p.S; } if(sm + sm > n) return -R; if(mp[bstD] * 2 <= n) return R; if(sub == 4) return -R; int U = -1, CNT = 0; for(int i = 0; i < n; i++){ if(D[i] == bstD){ if(CNT == 0 || same(U, i)) U = i, CNT++; else CNT--; } } if(CNT == 0) return R; CNT = 1; for(int i = 0; i < n; i++){ if(D[i] == bstD && i != U && same(U, i)) CNT++; } if(CNT + CNT <= n) return R; return -R; }

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

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:38:31: warning: declaration of 'n' shadows a global declaration [-Wshadow]
   38 | int hubDistance(int n, int sub){
      |                               ^
towns.cpp:18:5: note: shadowed declaration is here
   18 | int n;
      |     ^
towns.cpp:69:6: warning: declaration of 'A' shadows a previous local [-Wshadow]
   69 |  int A = Ds[0].S, B = n - Ds[0].S;
      |      ^
towns.cpp:40:9: note: shadowed declaration is here
   40 |     int A = far(0, 0);
      |         ^
towns.cpp:69:19: warning: declaration of 'B' shadows a previous local [-Wshadow]
   69 |  int A = Ds[0].S, B = n - Ds[0].S;
      |                   ^
towns.cpp:41:9: note: shadowed declaration is here
   41 |     int B = far(A, 0);
      |         ^
#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...