Submission #964767

#TimeUsernameProblemLanguageResultExecution timeMemory
964767guechotjrhhCity Mapping (NOI18_citymapping)C++14
92.28 / 100
2 ms760 KiB
#include "citymapping.h" #include<vector> #include<algorithm> #include<random> #include<iostream> using namespace std; #define ll long long #define pi pair<ll,ll> #define x first #define y second random_device rd; mt19937 g(rd()); random_device r; default_random_engine e1(r()); uniform_int_distribution<int> ud(0, 1e9 + 7); int * a, * b, * w, p = 0; void func(vector<pi> &v) {//sorted? int n = v.size(); if (n == 1) return; int piv = ud(e1) % v.size(); while(piv == 0) piv = ud(e1)%v.size(); vector<int> lv; vector<vector<pi>> nv; lv.push_back(0); lv.push_back(piv); nv.push_back({}); nv.push_back({}); int s = 1; for (int i = 1; i < n; i++) { if (i == piv) continue; ll w = get_distance(v[i].x, v[lv[s]].x); ll t = (v[i].y + v[lv[s]].y - w) / 2; if (w == v[lv[s]].y - v[i].y) { lv[s] = i; lv.push_back(piv); nv.push_back({}); s++; } else { int j = 0; while (t > v[lv[j]].y) j++; if (j == s) { nv.push_back({}); lv.push_back(i); s++; } else { nv[j].push_back(v[i]); } } } for (int i = 1; i <= s; i++) { a[p] = v[lv[i]].x; b[p] = v[lv[i - 1]].x; w[p] = v[lv[i]].y - v[lv[i - 1]].y; p++; } for (int i = 0; i <= s; i++) { if (nv[i].size()) { a[p] = v[lv[i]].x; b[p] = nv[i][0].x; w[p] = nv[i][0].y - v[lv[i]].y; p++; ll o = nv[i][0].y; for (int j = 0; j < nv[i].size(); j++) nv[i][j].y -= o; func(nv[i]); } } } void find_roads(int N, int Q, int A[], int B[], int W[]) { a = A; b = B; w = W; int st = ud(e1) % N + 1; ll mx = 0, mi = st; for (int i = 1; i <= N; i++){ if (i == st) continue; ll z = get_distance(st, i); if (z > mx) { mx = z; mi = i; } } vector<pi> vu = { { 0,mi } }; for (int i = 1; i <= N; i++) if (i != mi) vu.push_back({ get_distance(mi,i), i }); sort(vu.begin(), vu.end()); vector<pi> vc(N); for (int i = 0; i < N; i++) vc[i] = { vu[i].y,vu[i].x }; func(vc); return; }

Compilation message (stderr)

citymapping.cpp: In function 'void func(std::vector<std::pair<long long int, long long int> >&)':
citymapping.cpp:61:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |    for (int j = 0; j < nv[i].size(); j++) nv[i][j].y -= o;
      |                    ~~^~~~~~~~~~~~~~
#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...