Submission #756623

#TimeUsernameProblemLanguageResultExecution timeMemory
756623fanwenCircle selection (APIO18_circle_selection)C++17
0 / 100
1420 ms180920 KiB
/** * 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; } 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 (stderr)

circle_selection.cpp: In function 'int main()':
circle_selection.cpp:93:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   93 |         freopen(TASK".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
circle_selection.cpp:94:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   94 |         freopen(TASK".out", "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...
#Verdict Execution timeMemoryGrader output
Fetching results...