제출 #1019072

#제출 시각아이디문제언어결과실행 시간메모리
1019072parsadox2도시들 (IOI15_towns)C++17
39 / 100
10 ms948 KiB
#include "towns.h" #include <bits/stdc++.h> #define F first #define S second using namespace std; const int N = 1e2 + 20; int n , dis[N][N] , r[N] , L[N] , R[N] , cnt[N]; bool Solve(int D) { int lef = 0 , rig = 0 , mid = 0; for(int x = 0 ; x < n ; x++) cnt[x] = 0; vector <int> vec; int mx = -1 , cnt = 0; for(int x = 0 ; x < n ; x++) { if(L[x] < D) lef++; else if(L[x] > D) rig++; else { if(cnt == 0) { cnt = 1; mx = x; continue; } else { dis[mx][x] = dis[x][mx] = getDistance(x , mx); if(dis[x][mx] != r[x] + r[mx]) cnt++; else cnt--; } } } mid = 1; for(int x = 0 ; x < n ; x++) if(L[x] == D && x != mx) { dis[x][mx] = dis[mx][x] = getDistance(x , mx); if(dis[x][mx] != r[x] + r[mx]) mid++; } return (lef <= n / 2 && rig <= n/2 && mid <= n / 2); } bool Solvec(int D) { int lef = 0 , rig = 0 , mid = 0; for(int x = 0 ; x < n ; x++) cnt[x] = 0; vector <int> vec; for(int x = 0 ; x < n ; x++) { if(L[x] < D) lef++; else if(L[x] > D) rig++; else { bool flg = false; for(auto u : vec) { dis[u][x] = dis[x][u] = getDistance(u , x); if(dis[u][x] != r[u] + r[x]) { flg = true; cnt[u]++; break; } } if(!flg) { vec.push_back(x); cnt[x] = 1; } } } for(int i = 0 ; i < n ; i++) mid = max(mid , cnt[i]); return (lef <= n / 2 && rig <= n/2 && mid <= n / 2); } int hubDistance(int nn , int sub) { n = nn; pair <int , int> D = make_pair(0 , 1); for(int i = 1 ; i < n ; i++) { dis[0][i] = dis[i][0] = getDistance(0 , i); if(dis[0][i] > dis[D.F][D.S]) D = make_pair(0 , i); } for(int i = 0 ; i < n ; i++) if(i != D.S) { dis[i][D.S] = dis[D.S][i] = getDistance(i , D.S); if(dis[i][D.S] > dis[D.F][D.S]) D = make_pair(i , D.S); } int ans = dis[D.F][D.S]; for(int x = 0 ; x < n ; x++) { dis[x][D.F] = dis[D.F][x] = getDistance(x , D.F); r[x] = (dis[x][D.F] + dis[x][D.S] - dis[D.F][D.S]) / 2; L[x] = dis[x][D.F] - r[x]; R[x] = dis[x][D.S] - r[x]; ans = min(ans , max(L[x] , R[x])); } ans = -ans; set <int> st; for(int x = 0 ; x < n ; x++) if(L[x] == abs(ans) || R[x] == abs(ans)) { st.insert(L[x]); } if(st.size() == 2) { int lef = 0 , rig = 0; for(int i = 0 ; i < n ; i++) { if(L[i] <= *st.begin()) lef++; else rig++; } if(lef > n / 2) { auto it = st.end(); it--; auto now = *it; st.erase(it); } else if(rig > n / 2) { auto now = *st.begin(); st.erase(now); } else { return abs(ans); } } for(auto ch : st) if(Solve(ch)) ans = abs(ans); return ans; }

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

towns.cpp: In function 'bool Solve(int)':
towns.cpp:18:16: warning: declaration of 'cnt' shadows a global declaration [-Wshadow]
   18 |  int mx = -1 , cnt = 0;
      |                ^~~
towns.cpp:10:42: note: shadowed declaration is here
   10 | int n , dis[N][N] , r[N] , L[N] , R[N] , cnt[N];
      |                                          ^~~
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:133:9: warning: unused variable 'now' [-Wunused-variable]
  133 |    auto now = *it;
      |         ^~~
towns.cpp:90:30: warning: unused parameter 'sub' [-Wunused-parameter]
   90 | int hubDistance(int nn , 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...