답안 #756624

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
756624 2023-06-12T02:13:22 Z fanwen 원 고르기 (APIO18_circle_selection) C++17
0 / 100
1373 ms 195528 KB
/**
 *      author : pham van sam
 *      created : 12 June 2023 (Monday)
 **/

#include <bits/stdc++.h>

using namespace std;
using namespace chrono;

#define MASK(x) (1LL << (x))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(x) (x).begin(), (x).end()
#define REP(i, n) for (int i = 0, _n = n; i < _n; ++i)
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define FORE(it, s) for (__typeof(s.begin()) it = (s).begin(); it != (s).end(); ++it)

template <typename U, typename V> bool maximize(U &A, const V &B) { return (A < B) ? (A = B, true) : false; }
template <typename U, typename V> bool minimize(U &A, const V &B) { return (A > B) ? (A = B, true) : false; }

#define int long long

const int MAXN = 3e5 + 5;

long long sqr(int x) { return 1LL * x * x; }

struct circle_t {
    int x, y, r; // coordinate and radius
    circle_t(int x = 0, int y = 0, int r = 0) : x(x), y(y), r(r) {};
    bool intersects(const circle_t &t) {
        return sqr(x - t.x) + sqr(y - t.y) <= sqr(r + t.r);
    }
} points[MAXN];

struct cmp {
    bool operator() (int i, int j) const {
        return (points[i].r > points[j].r || (points[i].r == points[j].r && i < j));
    }
};

set <int, cmp> S;
int N, ans[MAXN], adj[MAXN];
map <int, vector <pair <int, int>>> mp;
// void update(int i, int j) {
//     if((points[i].r > points[j].r || (points[i].r == points[j].r && i < j))) return void(ans[i] = ans[j] = i);
//     return void(ans[i] = ans[j] = j);
// }

void process(void) {
    cin >> N;
    FOR(i, 1, N) {
        cin >> points[i].x >> points[i].y >> points[i].r;
        mp[points[i].y + points[i].r].push_back(make_pair(i, 0));
        mp[points[i].y - points[i].r].push_back(make_pair(i, 1));
    }
    FOR(i, 1, N) adj[i] = i;
    multiset <pair <int, int>> s;
    for (auto [y, cur] : mp) {
        for (auto [i, type] : cur) if(type == 1) {
            s.insert(make_pair(points[i].x, i));
        }
        for (auto [i, type] : cur) if(type == 1) {
            auto it = s.lower_bound(make_pair(points[i].x, 0));
            if(it != s.end()) if(points[i].intersects(points[it -> second])) {
                adj[i] = it -> second;
                adj[it -> second] = i;
            }
            if(it != s.begin()) {
                --it;
                if(points[i].intersects(points[it -> second])) {
                    adj[i] = it -> second;
                    adj[it -> second] = i;
                }
            }
        }
        for (auto [i, type] : cur) if(type == 0) s.erase(s.find(make_pair(points[i].x, i)));
    }
    FOR(i, 1, N) S.insert(i);
    while((int) S.size()) {
        int u = *S.begin(); S.erase(S.begin());
        ans[u] = u;
        if(adj[u] != u) {
            ans[adj[u]] = u;
            S.erase(S.find(adj[u]));
        }
    }
    FOR(i, 1, N) cout << ans[i] << " ";
}

signed main() {

    #define TASK "TASK"
    if(fopen(TASK".inp", "r")) {
        freopen(TASK".inp", "r", stdin);
        freopen(TASK".out", "w", stdout);
    }

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    auto start_time = steady_clock::now();
    int test = 1;
    // cin >> test;
    for (int i = 1; i <= test; ++i) {
        process();
        // cout << '\n';
    }

    auto end_time = steady_clock::now();

    cerr << "\nExecution time : " << duration_cast<milliseconds> (end_time - start_time).count() << "[ms]" << endl;

    return (0 ^ 0);
}

Compilation message

circle_selection.cpp: In function 'int main()':
circle_selection.cpp:95:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   95 |         freopen(TASK".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
circle_selection.cpp:96:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   96 |         freopen(TASK".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7380 KB Output is correct
2 Correct 4 ms 7252 KB Output is correct
3 Correct 5 ms 7252 KB Output is correct
4 Incorrect 4 ms 7252 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1373 ms 195528 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 7380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 834 ms 93812 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7380 KB Output is correct
2 Correct 4 ms 7252 KB Output is correct
3 Correct 5 ms 7252 KB Output is correct
4 Incorrect 4 ms 7252 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7380 KB Output is correct
2 Correct 4 ms 7252 KB Output is correct
3 Correct 5 ms 7252 KB Output is correct
4 Incorrect 4 ms 7252 KB Output isn't correct
5 Halted 0 ms 0 KB -