Submission #246677

#TimeUsernameProblemLanguageResultExecution timeMemory
246677xiryssDrzava (COCI15_drzava)C++17
104 / 160
1098 ms28944 KiB
//#pragma GCC optimize("Ofast,no-stack-protector") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") #pragma GCC optimize("unroll-loops") //#pragma GCC optimize("fast-math") /*#pragma GCC optimize("section-anchors") #pragma GCC optimize("profile-values,profile-reorder-functions,tracer") #pragma GCC optimize("vpt") #pragma GCC optimize("rename-registers") #pragma GCC optimize("move-loop-invariants") #pragma GCC optimize("unswitch-loops") #pragma GCC optimize("function-sections") #pragma GCC optimize("data-sections") #pragma GCC optimize("branch-target-load-optimize") #pragma GCC optimize("branch-target-load-optimize2") #pragma GCC optimize("btr-bb-exclusive")*/ //#pragma comment(linker, "/STACK:367077216") #define _CRT_SECURE_NO_WARNINGS #include <chrono> #include <set> #include <map> #include <deque> #include <string> #include <cstdint> #include <cmath> #include <queue> #include <cassert> #include <random> #include <bitset> #include <iomanip> #include <numeric> #include <time.h>////////////// #include <ctime> #include <string> #include <cstdio> #include <vector> #include <cstdlib> #include <iostream> #include <algorithm> #include <unordered_map> #include <unordered_set> //++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++ //#define endl '\n' #define mp make_pair #define pbc push_back #define pob pop_back() #define empb emplace_back #define queuel queue<long long> #define sqr(a) ((a) * (a)) #define sqrl(a) (ll(a)*ll(a)) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define pin(p) cin >> p.first >> p.second; #define uniq(a) sort(all(a));(a).resize(unique(all(a)) - a.begin()); #define rev(v) reverse(v.begin(), v.end()); #define sout(s, c) for (auto i : s) cout << i << c; #define pout(p) cout << p.first << " " << p.second; #define er(v, l, r) erase(v.begin() + l, v.begin() + r); #define vin(v) for (ll i = 0; i < v.size(); ++i) cin >> v[i]; #define vout(v, c) for (int i = 0; i < v.size(); ++i) cout << v[i] << c; #define pushi(v, a) for (int i = 0; i < a.size(); ++i) v.push_back(a[i]); #define fastio() ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); srand(time(NULL)) #define dab(v) for(auto i:v)cout<<i<<' '; #define sp system("pause") //++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++ using namespace std; //++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++ typedef long long ll; typedef long double ld; typedef unsigned long long ull; //++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++ mt19937 rnd(time(0) + 228 + 'k' + 'e' + 'k' + 'e' + 'r' + 'o' + 'f' + 'e' + 'y'); const ld EPS = 1e-5;//(cos,-sin), (sin, cos) bool checkprime(int x) { for (int i = 2; i * i <= x; ++i) if (x % i == 0) return 0; return 1; } const ld PI = acos(-1); const int MOD7 = 1000000007; const int MOD9 = 1000000009; const ll INF = 1e18; int mod = MOD7; const int inf = 1e9; const int MAXN = 5e4 + 2; int p[MAXN]; int sz[MAXN]; vector<int> have[MAXN]; pair<pair<int, int>, int> a[MAXN]; inline void make(int v) { p[v] = v, sz[v] = 1; have[v] = { a[v - 1].second }; } inline int fin(int v) { return (v == p[v] ? v : p[v] = fin(p[v])); } bool flg = 0; int n, k; inline void unite(int a, int b) { a = fin(a); b = fin(b); if (a == b) return; if (sz[a] < sz[b]) swap(a, b); for (int j : have[b]) have[a].pbc(j); p[b] = a; sz[a] += sz[b]; if (sz[a] >= k) flg = 1; } int f[MAXN]; inline void add(int i, int x) { for (; i < MAXN; i |= (i + 1)) f[i] += x; } inline int get(int r) { int ans = 0; for (; r >= 0; r = (r & (r + 1)) - 1) ans += f[r]; return ans; } inline int get(int l, int r) { return get(r) - get(l - 1); } ld dist(pair<int, int> a, pair<int, int> b) { return sqrt(sqrl(a.first - b.first) + sqrl(a.second - b.second)); } struct query { int r, i, x, y; bool type; query(int a, int b, int c, int d, bool e) { tie(r, i, x, y, type) = { a,b,c,d,e }; } query() { r = i = x = y = type = 0; } }; vector<pair<int, int>> tree[4 * MAXN]; void build(int v, int l, int r, vector<pair<int, int>>& kek) { if (l == r - 1) { tree[v] = { kek[l] }; return; } build(2 * v + 1, l, (l + r) / 2, kek); build(2 * v + 2, (l + r) / 2, r, kek); merge(all(tree[2 * v + 1]), all(tree[2 * v + 2]), back_inserter(tree[v])); } vector<int> joint; void get(int v, int l, int r, int ql, int qr, int x, int y) { if (l >= qr || ql >= r) return; if (l >= ql && r <= qr) { int xa = lower_bound(all(tree[v]), mp(x, -inf)) - tree[v].begin(); for (int j = xa; j < tree[v].size() && tree[v][j].first <= y; ++j) joint.pbc(tree[v][j].second); return; } get(2 * v + 1, l, (l + r) / 2, ql, qr, x, y); get(2 * v + 2, (l + r) / 2, r, ql, qr, x, y); } bool cmp(query a, query b) { return a.r < b.r; } int xs[MAXN]; int ys[MAXN]; int ta[MAXN]; int answers[MAXN]; query handle[MAXN * 2]; int hsz = 0; vector<int> available[MAXN]; vector<query> keks[MAXN]; bool check(int dst) { hsz = 0; // if (n >= 1e4 && cnt >= 20) assert(0); fill(f, f + MAXN, 0); fill(answers, answers + MAXN, 0); for (int i = 0; i < n; ++i) { int xm = a[i].first.first - dst, xmm = a[i].first.first + dst; int ym = a[i].first.second - dst, ymm = a[i].first.second + dst; int xfs = lower_bound(xs, xs + n, xm) - xs; int xss = upper_bound(xs, xs + n, xmm) - xs - 1; int yfs = lower_bound(ys, ys + n, ym) - ys; int yss = upper_bound(ys, ys + n, ymm) - ys - 1; if (xfs - 1 >= 0) handle[hsz++] = query(xfs - 1, i, yfs, yss, 0); handle[hsz++] = query(xss, i, yfs, yss, 1); } stable_sort(handle, handle + hsz, cmp); int lft = 0; for (int i = 0; i < n; ++i) { int nowy = lower_bound(ys, ys + n, a[ta[i]].first.second) - ys; add(nowy, 1); while (lft < hsz && handle[lft].r < i) ++lft; while (lft < hsz && handle[lft].r == i) { int now = get(handle[lft].x, handle[lft].y); if (handle[lft].type == 0) answers[handle[lft].i] -= now; else answers[handle[lft].i] += now; if (answers[handle[lft].i] >= 8 * k + 3) return 1; ++lft; } } return 0; } bool check2(ld dst) { flg = 0; for (int i = 1; i <= n; ++i) make(i); for (int i = 0; i < n; ++i) { for (int j : available[i]) { if (dist(a[i].first, a[j].first) <= dst) { unite(i + 1, j + 1); if (flg) return 1; } } } vector<bool> used(n + 1); for (int i = 0; i < n; ++i) { if (used[fin(i + 1)]) continue; used[fin(i + 1)] = 1; vector<int> means = have[fin(i + 1)]; vector<vector<bool>> dp(means.size() + 1, vector<bool>(k + 1)); dp[0][0] = 1; for (int j = 0; j < means.size(); ++j) { for (int w = 0; w <= k; ++w) { if (!dp[j][w]) continue; dp[j + 1][w] = 1; int tw = w + means[j]; if (tw == k) return 1; tw %= k; dp[j + 1][tw] = 1; } } } return 0; } signed main() { fastio(); scanf("%d%d", &n, &k); for (int i = 0; i < n; ++i) { scanf("%d%d%d", &a[i].first.first, &a[i].first.second, &a[i].second); a[i].second %= k; } iota(ta, ta + n, 0); sort(ta, ta + n, [&](int x, int y) {return a[x].first.first < a[y].first.first; }); ld kekw = 2e9; for (int cnt =0 ;cnt< 4;++cnt) { int i = cnt; for (int j = 0; j < n; ++j) { if (i == j) continue; if ((a[i].second + a[j].second) % k == 0)kekw = min(kekw, dist(a[i].first, a[j].first)); } } for (int i = 0; i < n; ++i) xs[i] = a[ta[i]].first.first; for (int i = 0; i < n; ++i) ys[i] = a[ta[i]].first.second; sort(ys, ys + n); vector<pair<int, int>> now; for (int i : ta) { int nowy = lower_bound(ys, ys + n, (ld)a[i].first.second) - ys; now.pbc({ nowy, i }); } int l = 0, r = min((int)1.5e8, (int)kekw +1); while (r - l > 1) { int m = (l + r) / 2; if (check(m))r = m; else l = m; } build(0, 0, n, now); //if (n >= 1e4)assert(0); ld dst = r; for (int i = 0; i < n; ++i) { ld xm = a[i].first.first - dst, xmm = a[i].first.first + dst; ld ym = a[i].first.second - dst, ymm = a[i].first.second + dst; int xfs = lower_bound(xs, xs + n, ld(xm)) - xs; int xss = upper_bound(xs, xs + n, xmm) - xs - 1; int yfs = lower_bound(ys, ys + n, ld(ym)) - ys; int yss = upper_bound(ys, ys + n, ymm) - ys - 1; joint.clear(); get(0, 0, n, xfs, xss + 1, yfs, yss); if (joint.size() >= 10 * k + 3) assert(0); for (int j : joint) { if (dist(a[i].first, a[j].first) <= dst) { available[i].pbc(j); } } } // if (n >= 1e4) assert(0); ld lll = 0; ld rr = r + 0.5; for (int cnt = 0; cnt < 47; ++cnt) { //if (abs(r - l) < 1e-4) break; ld m = (lll + rr) / 2; if (check2(m)) rr = m; else lll = m; } cout << fixed << setprecision(3) << rr; sp; }

Compilation message (stderr)

drzava.cpp: In function 'void get(int, int, int, int, int, int, int)':
drzava.cpp:165:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j = xa; j < tree[v].size() && tree[v][j].first <= y; ++j) joint.pbc(tree[v][j].second);
                    ~~^~~~~~~~~~~~~~~~
drzava.cpp: In function 'bool check2(ld)':
drzava.cpp:243:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j = 0; j < means.size(); ++j)
                   ~~^~~~~~~~~~~~~~
drzava.cpp: In function 'int main()':
drzava.cpp:311:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (joint.size() >= 10 * k + 3) assert(0);
       ~~~~~~~~~~~~~^~~~~~~~~~~~~
drzava.cpp:261:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &k);
  ~~~~~^~~~~~~~~~~~~~~~
drzava.cpp:264:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d", &a[i].first.first, &a[i].first.second, &a[i].second);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drzava.cpp:63:18: warning: ignoring return value of 'int system(const char*)', declared with attribute warn_unused_result [-Wunused-result]
 #define sp system("pause")
            ~~~~~~^~~~~~~~~
drzava.cpp:332:2: note: in expansion of macro 'sp'
  sp;
  ^~
#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...
#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...
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...