Submission #730974

#TimeUsernameProblemLanguageResultExecution timeMemory
730974Vu_CG_CoderTowns (IOI15_towns)C++14
35 / 100
22 ms852 KiB
#include "towns.h" #include <bits/stdc++.h> using namespace std; int f[110][110]; // int getDistance(int x , int y){ // return f[x][y]; // } int sub1(int N,int sub){ int n = N; pair <int,int> tmp; vector <int> val , value; val.assign(n,0); value.assign(n,0); for (int i = 1 ; i < n ; i++){ int x = getDistance(0,i); tmp = max(tmp,make_pair(x,i)); } int u = tmp.second; tmp.first = 0; for (int i = 0 ; i < n ; i++) if (i != u){ int x = getDistance(i,u); val[i] = x; tmp = max(tmp,make_pair(x,i)); } int v = tmp.second; int R = 1e9; for (int i = 0 ; i < n ; i++) if (i != u && i != v){ int x = getDistance(v,i); value[i] = x; int y = val[i]; int z = val[v]; int a = (x + y - z)/2; int b = x - a; int c = z - b; int r = max(a,max(b,c)); if (r < R){ tmp = make_pair(b,c); R = r; } } if (sub < 3) return R; int cntu = 1 , cntv = 1 , cnt = 0; for (int i = 0 ; i < n ; i++) if (i != u && i != v) { int x = val[i]; int y = val[v]; int z = value[i]; int a = (x + y - z)/2; if (a < tmp.second) cntu++; if (a == tmp.second) cnt++; if (a > tmp.second) cntv++; } if (cntu > n/2 || cntv > n/2 || cnt > n/2) return -R; return R; } struct node{ int v , val , pre; node(){} node(int v , int val , int pre): v(v), val(val), pre(pre) {} }; int sub3(int n){ pair <int,int> tmp; vector <vector<int> > val; val.assign(n,vector<int>(n,0)); for (int i = 0 ; i < n ; i++) for (int j = i + 1 ; j < n ; j++){ int x = getDistance(i,j); val[i][j] = x; val[j][i] = x; } for (int i = 1 ; i < n ; i++){ int x = val[0][i]; tmp = max(tmp,make_pair(x,i)); } int u = tmp.second; tmp.first = 0; for (int i = 0 ; i < n ; i++) if (i != u){ int x = val[i][u]; tmp = max(tmp,make_pair(x,i)); } int v = tmp.second; int R = 1e9; for (int i = 0 ; i < n ; i++) if (i != u && i != v){ int x = val[i][v]; int y = val[u][i]; int z = val[u][v]; int a = (x + y - z)/2; int b = x - a; int c = z - b; int r = max(a,max(b,c)); if (r < R){ tmp = make_pair(b,c); R = r; } } int cntu = 1 , cntv = 1 , cnt = 0; vector <int> pt; for (int i = 0 ; i < n ; i++) if (i != u && i != v) { int x = val[i][u]; int y = val[v][u]; int z = val[v][i]; int a = (x + y - z)/2; if (a < tmp.second) cntu++; if (a == tmp.second) { pt.push_back(i); } if (a > tmp.second) cntv++; } if (cntu > n/2 || cntv > n/2) return -R; while (!pt.empty()){ vector <int> kt; v = pt[0]; int d = 1; for (int p : pt) if (p != v){ int x = val[v][p]; int y = val[v][u]; int z = val[p][u]; int a = (x + y - z)/2; int b = x - a; int c = z - b; if (c > tmp.second) d++; else kt.push_back(p); } if (d > n/2) return -R; pt = kt; } return R; } int hubDistance(int N, int sub) { if (sub < 3 || sub == 4) return sub1(N,sub); return sub3(N); } // int main(){ // freopen("txt.inp","r",stdin); // freopen("txt.out","w",stdout); // int n; // cin >> n; // for (int i = 0 ; i < n ; i++) // for (int j = 0 ; j < n ; j++) // cin >> f[i][j]; // cout << hubDistance(n,3); // return 0; // }

Compilation message (stderr)

towns.cpp: In constructor 'node::node(int, int, int)':
towns.cpp:68:32: warning: declaration of 'pre' shadows a member of 'node' [-Wshadow]
   68 |     node(int v , int val , int pre): v(v), val(val), pre(pre) {}
      |                            ~~~~^~~
towns.cpp:66:19: note: shadowed declaration is here
   66 |     int v , val , pre;
      |                   ^~~
towns.cpp:68:22: warning: declaration of 'val' shadows a member of 'node' [-Wshadow]
   68 |     node(int v , int val , int pre): v(v), val(val), pre(pre) {}
      |                  ~~~~^~~
towns.cpp:66:13: note: shadowed declaration is here
   66 |     int v , val , pre;
      |             ^~~
towns.cpp:68:14: warning: declaration of 'v' shadows a member of 'node' [-Wshadow]
   68 |     node(int v , int val , int pre): v(v), val(val), pre(pre) {}
      |          ~~~~^
towns.cpp:66:9: note: shadowed declaration is here
   66 |     int v , val , pre;
      |         ^
towns.cpp: In constructor 'node::node(int, int, int)':
towns.cpp:68:32: warning: declaration of 'pre' shadows a member of 'node' [-Wshadow]
   68 |     node(int v , int val , int pre): v(v), val(val), pre(pre) {}
      |                            ~~~~^~~
towns.cpp:66:19: note: shadowed declaration is here
   66 |     int v , val , pre;
      |                   ^~~
towns.cpp:68:22: warning: declaration of 'val' shadows a member of 'node' [-Wshadow]
   68 |     node(int v , int val , int pre): v(v), val(val), pre(pre) {}
      |                  ~~~~^~~
towns.cpp:66:13: note: shadowed declaration is here
   66 |     int v , val , pre;
      |             ^~~
towns.cpp:68:14: warning: declaration of 'v' shadows a member of 'node' [-Wshadow]
   68 |     node(int v , int val , int pre): v(v), val(val), pre(pre) {}
      |          ~~~~^
towns.cpp:66:9: note: shadowed declaration is here
   66 |     int v , val , pre;
      |         ^
towns.cpp: In constructor 'node::node(int, int, int)':
towns.cpp:68:32: warning: declaration of 'pre' shadows a member of 'node' [-Wshadow]
   68 |     node(int v , int val , int pre): v(v), val(val), pre(pre) {}
      |                            ~~~~^~~
towns.cpp:66:19: note: shadowed declaration is here
   66 |     int v , val , pre;
      |                   ^~~
towns.cpp:68:22: warning: declaration of 'val' shadows a member of 'node' [-Wshadow]
   68 |     node(int v , int val , int pre): v(v), val(val), pre(pre) {}
      |                  ~~~~^~~
towns.cpp:66:13: note: shadowed declaration is here
   66 |     int v , val , pre;
      |             ^~~
towns.cpp:68:14: warning: declaration of 'v' shadows a member of 'node' [-Wshadow]
   68 |     node(int v , int val , int pre): v(v), val(val), pre(pre) {}
      |          ~~~~^
towns.cpp:66:9: note: shadowed declaration is here
   66 |     int v , val , pre;
      |         ^
towns.cpp: In function 'int sub3(int)':
towns.cpp:113:31: warning: unused variable 'cnt' [-Wunused-variable]
  113 |     int cntu = 1 , cntv = 1 , cnt = 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...