Submission #400279

#TimeUsernameProblemLanguageResultExecution timeMemory
400279ly20Towns (IOI15_towns)C++17
39 / 100
21 ms400 KiB
#include "towns.h" #include <bits/stdc++.h> using namespace std; const int MAXN = 120; /* int ds[MAXN][MAXN]; int getDistance(int a, int b) { return ds[a][b]; } */ int dist[MAXN][MAXN]; int gd(int a, int b) { if(dist[a][b] == 0) { dist[a][b] = getDistance(a, b); dist[b][a] = dist[a][b]; } return dist[a][b]; } int pai[MAXN], sz[MAXN]; int find(int v) { if(v == pai[v]) return v; return pai[v] = find(pai[v]); } void une(int a, int b) { a = find(a); b = find(b); if(a == b) return; if(sz[a] > sz[b]) swap(a, b); pai[a] = b; sz[b] += sz[a]; } int hubDistance(int n, int sub) { //int resp = 0; for(int i = 0; i < MAXN; i++) { for(int j = 0; j < MAXN; j++) { dist[i][j] = 0; } } int mx1 = 1, mx = 0; int a, b; for(int i = 1; i < n; i++) { int d = gd(1, i); if(d > mx) { mx = d; mx1 = i; } } a = mx1; mx = 0; for(int i = 0; i < n; i++) { if(i == a) continue; int d = gd(a, i); if(d > mx) { mx = d; mx1 = i; } } b = mx1; int dim = mx; //set <int> di; int resp = dim; vector <int> ns; for(int i = 0; i < n; i++) { pai[i] = i; sz[i] = 1; if(i == a || i == b) continue; int d = gd(a, i) - (gd(a, i) + gd(b, i) - dim) / 2; resp = min(resp, max(d, dim - d)); ns.push_back(d); } resp = resp * -1; int esq1 = -1, esq2 = -1; for(int i = 0; i < n; i++) { int d = gd(a, i) - (gd(a, i) + gd(b, i) - dim)/ 2; //printf("%d %d %d\n", i, d, dim - d); if(max(d, dim - d) != -resp) continue; //printf("oi\n"); if(d == esq1 || d == esq2) continue; //printf("%d\n", i); if(esq1 == -1) esq1 = d; else esq2 = d; vector <int> cur; int ce = 0, cd = 0; for(int j = 0; j < n; j++) { int dt = gd(a, j) - (gd(a, j) + gd(b, j) - dim) / 2; if(dt < d) { ce++; } else if(dt > d) { cd++; } else cur.push_back(j); } if(ce > n / 2 || cd > n / 2) continue; //return -resp; if(cur.size() <= n / 2) return -resp; //else continue; //printf("%d\n", cur.size()); stack <int> pilha; for(int j = 0; j < cur.size(); j++) { int id = cur[j]; if(pilha.empty()) { pilha.push(id); } else { int k = pilha.top(), l = cur[j]; int d1 = gd(a, k) + gd(b, k) - gd(a, b), d2 = gd(a, l) + gd(b, l) - gd(a, b), db = gd(k, l); if(d1 + d2 != 2 * db) { une(l, pilha.top()); pilha.push(l); } else pilha.pop(); } } if(pilha.empty()) return -resp; int bs = pilha.top(); int qt = 1; for(int j = 0; j < cur.size(); j++) { int id = cur[j]; if(id == bs) continue; int k = find(bs), l = find(id); int d1 = gd(a, k) + gd(b, k) - gd(a, b), d2 = gd(a, l) + gd(b, l) - gd(a, b), db = gd(k, l); if(d1 + d2 != 2 * db) qt++; } if(qt <= n / 2) return -resp; } return resp; } /* int main() { int n; scanf("%d", &n); for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { scanf("%d", &ds[i][j]); } } printf("%d\n", hubDistance(n, 0)); return 0; } */

Compilation message (stderr)

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:93:23: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   93 |         if(cur.size() <= n / 2) return -resp;
      |            ~~~~~~~~~~~^~~~~~~~
towns.cpp:97:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   97 |         for(int j = 0; j < cur.size(); j++) {
      |                        ~~^~~~~~~~~~~~
towns.cpp:115:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  115 |         for(int j = 0; j < cur.size(); j++) {
      |                        ~~^~~~~~~~~~~~
towns.cpp:33:28: warning: unused parameter 'sub' [-Wunused-parameter]
   33 | 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...