제출 #623947

#제출 시각아이디문제언어결과실행 시간메모리
6239478e7도시들 (IOI15_towns)C++17
23 / 100
15 ms456 KiB
//Challenge: Accepted #include <bits/stdc++.h> using namespace std; #ifdef zisk void debug(){cout << endl;} template<class T, class ... U> void debug(T a, U ...b){cout << a << " ", debug(b...);} template<class T> void pary(T l, T r) { while (l != r) cout << *l << " ", l++; cout << endl; } #else #define debug(...) 0 #define pary(...) 0 #endif #define ll long long #define maxn 155 #define pii pair<int, int> #define ff first #define ss second #include "towns.h" int n; int save[maxn][maxn]; bool done[maxn][maxn]; int query(int u, int v) { if (u == v || u >= n || v >= n) return 0; if (done[u][v]) return save[u][v]; save[u][v] = save[v][u] = getDistance(u, v); done[u][v] = done[v][u] = 1; return save[u][v]; } int hubDistance(int N, int sub) { n = N; for (int i = 0;i < n;i++) { for (int j = 0;j < n;j++) done[i][j] = 0; } vector<int> da, db, l(n), w(n), ws; int b = 0, ma = 0; for (int i = 0;i < n;i++) { da.push_back(query(0, i)); if (da.back() > ma) { ma = da.back(); b = i; } } int len = ma; for (int i = 0;i < n;i++) { db.push_back(query(b, i)); ma = max(ma, db.back()); } //debug(ma); int R = 1<<30; for (int i = 0;i < n;i++) { l[i] = (da[i] + db[i] - len) / 2; w[i] = db[i] - l[i]; //debug(l[i], w[i]); ws.push_back(w[i]); R = min(R, max(w[i], ma - w[i])); } sort(ws.begin(), ws.end()); ws.resize(int(unique(ws.begin(), ws.end()) - ws.begin())); int siz = ws.size(); vector<vector<int> > col(siz, vector<int>()); vector<int> pref(siz, 0), suf(siz, 0); for (int i = 0;i < n;i++) { int ind = lower_bound(ws.begin(), ws.end(), w[i]) - ws.begin(); col[ind].push_back(i); debug(i, ind); } for (int i = 0;i < siz;i++) pref[i] = col[i].size() + (i ? pref[i-1] : 0); for (int i = siz-1;i >= 0;i--) suf[i] = col[i].size() + (i < siz-1 ? suf[i+1] : 0); vector<int> vec, tmp; for (int i = 0;i < siz;i++) { int v = max(ws[i], ma - ws[i]); if (v == R) { if ((i == 0 || pref[i-1] <= n/2) && (i == siz-1 || suf[i+1] <= n/2) && col[i].size() <= n/2) { return R; } else if (col[i].size() > n/2) { vec = col[i]; for (int j = 0;j < n - col[i].size();j++) vec.push_back(n+j); break; } } } if (vec.size() == 0) return -R; tmp = vec; //pary(vec.begin(), vec.end()); auto same = [&] (int i, int j) { int v = query(i, j); if (v == 0) return 0; int d = l[i] + l[j] - v; //debug("same", i, j, d ? 1 : 0); return d ? 1 : 0; }; //pary(vec.begin(), vec.end()); while (vec.size() > 1) { vector<int> nxt; for (int i = 0;i < vec.size();i += 2) { if (i == (int)vec.size()-1) { nxt.push_back(vec[i]); } else { if (same(vec[i], vec[i+1])) nxt.push_back(vec[i]); } } //pary(nxt.begin(), nxt.end()); vec = nxt; } if (vec.size() == 0) return R; else { int c = vec[0]; int cnt = 0; for (int i = 0;i < n;i++) { if (tmp[i] == c) { cnt++; } else { if (same(c, tmp[i])) cnt++; } } //debug(c, cnt); if (cnt > n/2) return -R; else return R; } } /* 1 1 6 0 20 12 12 12 12 20 0 12 12 12 12 12 12 0 2 2 2 12 12 2 0 2 2 12 12 2 2 0 2 12 12 2 2 2 0 */

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

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:64:19: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   64 |  int siz = ws.size();
      |            ~~~~~~~^~
towns.cpp:68:53: warning: conversion from '__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type' {aka 'long int'} to 'int' may change value [-Wconversion]
   68 |   int ind = lower_bound(ws.begin(), ws.end(), w[i]) - ws.begin();
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
towns.cpp:12:20: warning: statement has no effect [-Wunused-value]
   12 | #define debug(...) 0
      |                    ^
towns.cpp:70:3: note: in expansion of macro 'debug'
   70 |   debug(i, ind);
      |   ^~~~~
towns.cpp:72:54: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} may change value [-Wconversion]
   72 |  for (int i = 0;i < siz;i++) pref[i] = col[i].size() + (i ? pref[i-1] : 0);
      |                                        ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
towns.cpp:73:56: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} may change value [-Wconversion]
   73 |  for (int i = siz-1;i >= 0;i--) suf[i] = col[i].size() + (i < siz-1 ? suf[i+1] : 0);
      |                                          ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
towns.cpp:79:89: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   79 |    if ((i == 0 || pref[i-1] <= n/2) && (i == siz-1 || suf[i+1] <= n/2) && col[i].size() <= n/2) {
      |                                                                           ~~~~~~~~~~~~~~^~~~~~
towns.cpp:81:29: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   81 |    } else if (col[i].size() > n/2) {
      |               ~~~~~~~~~~~~~~^~~~~
towns.cpp:83:22: 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 < n - col[i].size();j++) vec.push_back(n+j);
      |                    ~~^~~~~~~~~~~~~~~~~~~
towns.cpp:103:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  103 |   for (int i = 0;i < vec.size();i += 2) {
      |                  ~~^~~~~~~~~~~~
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...