Submission #400265

#TimeUsernameProblemLanguageResultExecution timeMemory
400265ly20Towns (IOI15_towns)C++17
25 / 100
24 ms936 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 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++) { 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; //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) 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 = bs, l = 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:80:23: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   80 |         if(cur.size() <= n / 2) return -resp;
      |            ~~~~~~~~~~~^~~~~~~~
towns.cpp:83:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |         for(int j = 0; j < cur.size(); j++) {
      |                        ~~^~~~~~~~~~~~
towns.cpp:98:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   98 |         for(int j = 0; j < cur.size(); j++) {
      |                        ~~^~~~~~~~~~~~
towns.cpp:21:28: warning: unused parameter 'sub' [-Wunused-parameter]
   21 | 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...