제출 #714860

#제출 시각아이디문제언어결과실행 시간메모리
714860lam도시들 (IOI15_towns)C++14
0 / 100
14 ms980 KiB
#include "towns.h" #include <bits/stdc++.h> using namespace std; typedef pair<int,int> ii; typedef pair<int,ii> iii; #define ff first #define ss second const int maxn = 510; int n; int d[maxn][maxn]; int ds[maxn],up[maxn]; map<ii,int> cnt; int Ask(int u, int v) { if (u==v) return 0; if (u>v) swap(u,v); if (d[u][v] == -1) { d[u][v] = getDistance(u,v); } return d[u][v]; } bool check(int dist) { vector<int> to_mid(n+1,0); for (int i=0; i<n; i++) if (ds[i]<dist) to_mid[i]=dist-ds[i]+up[i]; else to_mid[i]=ds[i]-dist+up[i]; vector <int> sz(n+1,0); int alive = 0; int num=1; for (int i=1; i<n; i++) if (num==0) { num=1; sz[i]++; alive=i; } else { if (Ask(i,alive)==to_mid[i]+to_mid[alive]) { num--; sz[i]++; } else { num++; sz[alive]++; } } if (num<=0) return 1; num=0; for (int i=0; i<n; i++) if (sz[i]!=0) { if (Ask(i,alive)==to_mid[i]+to_mid[alive]) num-=sz[i]; else num+=sz[i]; } return num<=0; } int hubDistance(int N, int sub) { n=N; cnt.clear(); for (int i=0; i<n; i++) for (int j=0; j<n; j++) d[i][j] = -1; int u,v,dist; u=0; for (int i=1; i<n; i++) if (dist<Ask(0,i)) { u=i; dist=Ask(0,i); } v=0; dist=0; for (int i=1; i<n; i++) if (dist<Ask(u,i)) { dist=Ask(u,i); v=i; } int R=1e9; for (int i=0; i<n; i++) { int x=Ask(u,i); int y=Ask(i,0); int z=Ask(u,0); up[i] = (x+y-z)/2; ds[i] = Ask(u,i)-up[i]; R=min(R,max(ds[i],Ask(u,v)-ds[i])); cnt[{ds[i],Ask(u,v)-ds[i]}]++; } int sum = 0; int it = 0; int dau = 1; for (auto i:cnt) { int sz = i.ss; if (max(i.ff.ff,i.ff.ss)==R) { if (sz<=n/2&&sum<=n/2&&(n-sz-sum<=n/2)) { dau=1; it=0; break; } else if (sum<=n/2&&(n-sz-sum)<=n/2) { it=i.ff.ff; } } sum+=sz; } if (it!=0) { if (check(it)) dau=1; else dau=-1; } // cerr<<R<<endl; return dau*R; }

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

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:59:28: warning: unused parameter 'sub' [-Wunused-parameter]
   59 | int hubDistance(int N, int sub) {
      |                        ~~~~^~~
towns.cpp:66:29: warning: 'dist' may be used uninitialized in this function [-Wmaybe-uninitialized]
   66 |     for (int i=1; i<n; i++) if (dist<Ask(0,i))
      |                             ^~
#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...