Submission #964014

#TimeUsernameProblemLanguageResultExecution timeMemory
964014guechotjrhhCity Mapping (NOI18_citymapping)C++14
65.67 / 100
10 ms2908 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()); int* a, * b, * w; int p = 0; void rec(vector<int>& v) { int n = v.size(); if (n == 1) return; shuffle(v.begin(), v.end(), g); int u1 = v[0], u2 = v[1]; vector<ll> d1(n, 0), d2(n, 0); vector<int> v1, v2; int t1 = 1, t2 = 0; for (int i = 0; i < n; i++) { if (v[i] != u1) d1[i] = get_distance(v[i], u1); if (v[i] != u2) d2[i] = get_distance(v[i], u2); if (d1[i] < d2[i]) { v1.push_back(v[i]); if (d2[i] < d2[t2]) t2 = i; } else { v2.push_back(v[i]); if (d1[i] < d1[t1]) t1 = i; } } a[p] = v[t1]; b[p] = v[t2]; w[p] = d1[t1] - d1[t2]; p++; rec(v1); rec(v2); } void func(vector<pi> &v) {//sorted? //cout << "v:\n"; //for (pi p : v) {cout << p.x << ' ' << p.y << endl;} int n = v.size(); if (n == 1) return; vector<int> lv; vector<vector<pi>> nv; lv.push_back(0); lv.push_back(1); nv.push_back({}); nv.push_back({}); int s = 1; for (int i = 2; i < n; i++) { ll w = get_distance(v[i].x, v[lv[s]].x); ll t = (v[i].y + v[lv[s]].y - w) / 2; 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; /*ll u = 0, mi = 1; for (int i = 2; i <= N; i++) { ll x = get_distance(1, i); if (x > u) { u = x; mi = i; } } vector<pi> vec; for (int i = 1; i <= N; i++) { if (i != mi) vec.push_back({ get_distance(mi,i),i }); } sort(vec.begin(), vec.end()); A[0] = mi; B[0] = vec[0].y; W[0] = vec[0].x; for (int i = 1; i < N-1; i++) { A[i] = vec[i].y; B[i] = vec[i - 1].y; W[i] = vec[i].x - vec[i - 1].x; }*/ //vector<int> v(N); for (int i = 1; i <= N; i++) v[i - 1] = i; //rec(v); ll mx = 0, mi = 1; for (int i = 2; i <= N; i++){ ll z = get_distance(1, 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); //for (int i = 0; i < N - 1; i++) cout << a[i] << ' ' << b[i] << ' ' << w[i] << endl; return; } /* 5 500000 1 1 4 8 4 2 1 4 3 7 3 5 3 */

Compilation message (stderr)

citymapping.cpp: In function 'void func(std::vector<std::pair<long long int, long long int> >&)':
citymapping.cpp:76: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]
   76 |    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...