Submission #998018

#TimeUsernameProblemLanguageResultExecution timeMemory
998018green_gold_dogIzvanzemaljci (COI21_izvanzemaljci)C++17
26 / 100
2616 ms14232 KiB
//#pragma GCC optimize("Ofast") //#pragma GCC target("avx,avx2,sse,sse2,sse3,ssse3,sse4,abm,popcnt,mmx") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef double db; typedef long double ldb; typedef complex<double> cd; constexpr ll INF64 = 9'000'000'000'000'000'000, INF32 = 2'000'000'000, MOD = 1'000'000'007; constexpr db PI = acos(-1); constexpr bool IS_FILE = false, IS_TEST_CASES = false; random_device rd; mt19937 rnd32(rd()); mt19937_64 rnd64(rd()); template<typename T> bool assign_max(T& a, T b) { if (b > a) { a = b; return true; } return false; } template<typename T> bool assign_min(T& a, T b) { if (b < a) { a = b; return true; } return false; } template<typename T> T square(T a) { return a * a; } template<> struct std::hash<pair<ll, ll>> { ll operator() (pair<ll, ll> p) const { return ((__int128)p.first * MOD + p.second) % INF64; } }; ll gmaxpref(map<ll, vector<ll>>& all, ll s) { ll nx = all.begin()->first; ll miny = INF32, maxy = -INF32; auto now = all.begin(); while (now != all.end()) { auto[x, ys] = *now; if (x - nx > s) { return x; } for (auto y : ys) { assign_min(miny, y); assign_max(maxy, y); } if (maxy - miny > s) { return x; } now++; } return INF32; } ll gmaxsuff(map<ll, vector<ll>>& all, ll s) { ll nx = all.rbegin()->first; ll miny = INF32, maxy = -INF32; auto now = all.rbegin(); while (now != all.rend()) { auto[x, ys] = *now; if (nx - x > s) { return x; } for (auto y : ys) { assign_min(miny, y); assign_max(maxy, y); } if (maxy - miny > s) { return x; } now++; } return -INF32; } pair<bool, vector<tuple<ll, ll, ll>>> s2h(ll s, vector<pair<ll, ll>>& arr) { map<ll, vector<ll>> all; for (auto[x, y] : arr) { all[x].push_back(y); } ll mpref = gmaxpref(all, s), msuff = gmaxsuff(all, s); vector<tuple<ll, ll, ll>> ans; if (mpref <= msuff) { return make_pair(false, ans); } ll maxx1 = -INF32, minx1 = INF32; ll maxy1 = -INF32, miny1 = INF32; ll maxx2 = -INF32, minx2 = INF32; ll maxy2 = -INF32, miny2 = INF32; for (auto[x, y] : arr) { if (x < mpref) { assign_max(maxx1, x); assign_min(minx1, x); assign_max(maxy1, y); assign_min(miny1, y); } else { assign_max(maxx2, x); assign_min(minx2, x); assign_max(maxy2, y); assign_min(miny2, y); } } ans.emplace_back(maxx1 - s, maxy1 - s, s); ans.emplace_back(minx2, miny2, s); return make_pair(true, ans); } pair<bool, vector<tuple<ll, ll, ll>>> s2v(ll s, vector<pair<ll, ll>>& arr) { map<ll, vector<ll>> all; for (auto[x, y] : arr) { all[y].push_back(x); } ll mpref = gmaxpref(all, s), msuff = gmaxsuff(all, s); vector<tuple<ll, ll, ll>> ans; if (mpref <= msuff) { return make_pair(false, ans); } ll maxx1 = -INF32, minx1 = INF32; ll maxy1 = -INF32, miny1 = INF32; ll maxx2 = -INF32, minx2 = INF32; ll maxy2 = -INF32, miny2 = INF32; for (auto[x, y] : arr) { if (y < mpref) { assign_max(maxx1, x); assign_min(minx1, x); assign_max(maxy1, y); assign_min(miny1, y); } else { assign_max(maxx2, x); assign_min(minx2, x); assign_max(maxy2, y); assign_min(miny2, y); } } ans.emplace_back(maxx1 - s, maxy1 - s, s); ans.emplace_back(minx2, miny2, s); return make_pair(true, ans); } void solve() { ll n, k; cin >> n >> k; vector<pair<ll, ll>> arr(n); for (ll i = 0; i < n; i++) { cin >> arr[i].first >> arr[i].second; } if (k == 1) { ll maxx = -INF32, minx = INF32; ll maxy = -INF32, miny = INF32; for (auto[x, y] : arr) { assign_max(maxx, x); assign_min(minx, x); assign_max(maxy, y); assign_min(miny, y); } cout << minx << ' ' << miny << ' ' << max(1ll, max(maxx - minx, maxy - miny)) << '\n'; return; } if (k == 2) { ll l = 0, r = INF32; while (r - l > 1) { ll mid = (l + r) / 2; if (s2h(mid, arr).first || s2v(mid, arr).first) { r = mid; } else { l = mid; } } if (s2h(r, arr).first) { for (auto[a, b, c] : s2h(r, arr).second) { cout << a << ' ' << b << ' ' << c << '\n'; } } else { for (auto[a, b, c] : s2v(r, arr).second) { cout << a << ' ' << b << ' ' << c << '\n'; } } return; } } int main() { if (IS_FILE) { freopen("", "r", stdin); freopen("", "w", stdout); } ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll t = 1; if (IS_TEST_CASES) { cin >> t; } for (ll i = 0; i < t; i++) { solve(); } }

Compilation message (stderr)

izvanzemaljci.cpp: In function 'int main()':
izvanzemaljci.cpp:200:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  200 |                 freopen("", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~
izvanzemaljci.cpp:201:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  201 |                 freopen("", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~
#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...