Submission #1058287

# Submission time Handle Problem Language Result Execution time Memory
1058287 2024-08-14T09:14:05 Z caterpillow Circle selection (APIO18_circle_selection) C++17
12 / 100
554 ms 42388 KB
#include <bits/stdc++.h>
#include <ratio>

using namespace std;

using db = long double;
using ll = long long;
using pl = pair<ll, ll>;
using pi = pair<int, int>;
#define vt vector
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(), x.end() 
#define size(x) ((int) (x).size())
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define F0R(i, b) FOR (i, 0, b)
#define endl '\n'
const ll INF = 1e18;
const int inf = 1e9;

template<typename... Args> // tuples
ostream& operator<<(ostream& os, tuple<Args...> t) { 
    apply([&](Args... args) { string dlm = "{"; ((os << dlm << args, dlm = ", "), ...); }, t);
    return os << "}";
}

template<typename T, typename V> // pairs
ostream& operator<<(ostream& os, pair<T, V> p) { return os << "{" << p.f << ", " << p.s << "}"; }

template<class T, class = decltype(begin(declval<T>()))> // iterables
typename enable_if<!is_same<T, string>::value, ostream&>::type operator<<(ostream& os, const T& v) {
    string dlm = "{";
    for (auto& i : v) os << dlm << i, dlm = ", ";
    return os << "}";  
}

template <typename T, typename... V>
void printer(string pfx, const char *names, T&& head, V&& ...tail) {
    int i = 0;
    while (names[i] && names[i] != ',') i++;
    constexpr bool is_str = is_same_v<decay_t<T>, const char*>;
    if (is_str) cerr << " " << head;
    else cerr << pfx, cerr.write(names, i) << " = " << head; 
    if constexpr (sizeof...(tail)) printer(is_str ? "" : ",", names + i + 1, tail...);
    else cerr << endl;
}

#ifdef LOCAL
#define dbg(...) printer(to_string(__LINE__) + ": ", #__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(x...)
#define cerr if (0) std::cerr
#endif

/*

circle a intersects with circle b if
    dx^2 + dy^2 <= (ra + rb)^2

subtask 1: brute force

subtask 2: line case
    keep set of lefts and rights


subtask 3: 

*/

int n; 
vt<pl> circles;

main() {
    cin.tie(0)->sync_with_stdio(0);
    
    cin >> n;
    circles.resize(n);
    F0R (i, n) {
        ll x, y, r; cin >> x >> y >> r;
        circles[i] = {x - r, x + r};
    }
    vt<int> ord(n); 
    iota(all(ord), 0);
    sort(all(ord), [&] (int i, int j) { return circles[i].s - circles[i].f == circles[j].s - circles[j].f ? i < j : circles[i].s - circles[i].f > circles[j].s - circles[j].f; } );
    vt<int> ans(n, -1);

    set<pi> lefts, rights;
    F0R (i, n) {
        lefts.insert({circles[i].f, i});
        rights.insert({circles[i].s, i});
    }

    for (int i : ord) {
        if (ans[i] != -1) continue;
        ans[i] = i;
        auto [l, r] = circles[i];
        ans[i] = i;
        lefts.erase({l, i});
        rights.erase({r, i});

        while (true) {
            auto it = lefts.lower_bound({l, -1});
            if (it == lefts.end() || it->f > r) break;
            rights.erase({circles[it->s].s, it->s});
            ans[it->s] = i;
            lefts.erase(it);
        }

        while (true) {
            auto it = rights.upper_bound({r, INF});
            if (it == rights.begin()) break; 
            it--;
            if (it->f < l) break;
            lefts.erase({circles[it->s].f, it->s});
            ans[it->s] = i;
            rights.erase(it);
        }
    }
    F0R (i, n) cout << ans[i] + 1 << " \n"[i == n - 1];
}

Compilation message

circle_selection.cpp:75:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   75 | main() {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 469 ms 37664 KB Output is correct
2 Correct 517 ms 37556 KB Output is correct
3 Correct 530 ms 37396 KB Output is correct
4 Correct 554 ms 37724 KB Output is correct
5 Correct 438 ms 37348 KB Output is correct
6 Correct 431 ms 37672 KB Output is correct
7 Correct 439 ms 42388 KB Output is correct
8 Correct 410 ms 42324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 303 ms 37284 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -