답안 #1058244

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1058244 2024-08-14T09:05:25 Z caterpillow 원 고르기 (APIO18_circle_selection) C++17
7 / 100
3000 ms 18628 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 circles in a set
    spam lower bound to delete bad thingies

subtask 3: 

*/

struct Circle {
    ll x, y, r;
};

#define sq(x) ((x) * (x))

bool inter(Circle& a, Circle& b) {
    return sq(a.x - b.x) + sq(a.y - b.y) <= sq(a.r + b.r);
}

int n; 
vt<Circle> circles;

main() {
    cin.tie(0)->sync_with_stdio(0);
    
    cin >> n;
    circles.resize(n);
    for (auto& [x, y, r] : circles) cin >> x >> y >> r;
    vt<int> ord(n); 
    iota(all(ord), 0);
    sort(all(ord), [&] (int i, int j) { return circles[i].r == circles[j].r ? i < j : circles[i].r > circles[j].r; } );
    vt<int> ans(n, -1);
    for (int i : ord) {
        if (ans[i] != -1) continue;
        ans[i] = i;
        F0R (j, n) {
            if (ans[j] != -1) continue;
            if (inter(circles[i], circles[j])) {
                ans[j] = i;
            }
        }
    }
    F0R (i, n) cout << ans[i] + 1 << " \n"[i == n - 1];
}

Compilation message

circle_selection.cpp:85:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   85 | main() {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 452 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 2 ms 600 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 24 ms 732 KB Output is correct
23 Correct 24 ms 604 KB Output is correct
24 Correct 24 ms 600 KB Output is correct
25 Correct 25 ms 604 KB Output is correct
26 Correct 24 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 86 ms 18516 KB Output is correct
2 Correct 87 ms 18516 KB Output is correct
3 Correct 90 ms 18240 KB Output is correct
4 Correct 102 ms 18628 KB Output is correct
5 Correct 2205 ms 16280 KB Output is correct
6 Execution timed out 3046 ms 14396 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Execution timed out 3036 ms 6224 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3041 ms 17488 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 452 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 2 ms 600 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 24 ms 732 KB Output is correct
23 Correct 24 ms 604 KB Output is correct
24 Correct 24 ms 600 KB Output is correct
25 Correct 25 ms 604 KB Output is correct
26 Correct 24 ms 600 KB Output is correct
27 Correct 3 ms 1112 KB Output is correct
28 Correct 5 ms 1116 KB Output is correct
29 Correct 3 ms 1004 KB Output is correct
30 Correct 103 ms 1036 KB Output is correct
31 Correct 127 ms 1040 KB Output is correct
32 Correct 135 ms 1028 KB Output is correct
33 Correct 29 ms 7252 KB Output is correct
34 Correct 44 ms 7280 KB Output is correct
35 Correct 35 ms 6924 KB Output is correct
36 Execution timed out 3044 ms 6228 KB Time limit exceeded
37 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 452 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 2 ms 600 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 24 ms 732 KB Output is correct
23 Correct 24 ms 604 KB Output is correct
24 Correct 24 ms 600 KB Output is correct
25 Correct 25 ms 604 KB Output is correct
26 Correct 24 ms 600 KB Output is correct
27 Correct 86 ms 18516 KB Output is correct
28 Correct 87 ms 18516 KB Output is correct
29 Correct 90 ms 18240 KB Output is correct
30 Correct 102 ms 18628 KB Output is correct
31 Correct 2205 ms 16280 KB Output is correct
32 Execution timed out 3046 ms 14396 KB Time limit exceeded
33 Halted 0 ms 0 KB -