Submission #772048

# Submission time Handle Problem Language Result Execution time Memory
772048 2023-07-03T14:46:09 Z CyberCow Circle selection (APIO18_circle_selection) C++17
7 / 100
1235 ms 83464 KB
//#include <bits/stdc++.h>
#include <random>
#include <algorithm>
#include <bitset>
#include <chrono>
#include <cmath>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <chrono>
#define fr first
#define sc second
#define ad push_back
using namespace std;
using ll = long long;
mt19937 rnd(348502);
const int N = 300005;
vector<pair<ll, pair<ll, ll>>> v;
ll color[N];
ll ans[N];

void solve()
{
    ll n, i, j, x, y, r;
    cin >> n;
    if (n <= 5000)
    {
        for (i = 0; i < n; i++)
        {
            cin >> x >> y >> r;
            v.push_back({ r, {x, y} });
        }
        ll qan = 0;
        for (i = 0; i < n; i++)
        {
            ll ma = 0;
            for (j = 0; j < n; j++)
            {
                if (color[j] == 0)
                {
                    ma = max(v[j].first, ma);
                }
            }
            for (j = 0; j < n; j++)
            {
                if (color[j] == 0 && v[j].first == ma)
                {
                    color[j] = 1;
                    ans[j] = j + 1;
                    qan++;
                    for (ll h = 0; h < n; h++)
                    {
                        if (color[h] == 0 && (v[j].second.first - v[h].second.first) * (v[j].second.first - v[h].second.first) + (v[j].second.second - v[h].second.second) * (v[j].second.second - v[h].second.second) <= (v[j].first + v[h].first) * (v[j].first + v[h].first))
                        {
                            color[h] = 1;
                            ans[h] = j + 1;
                            qan++;
                        }
                    }
                    break;
                }
            }
            if (qan == n)
                break;
        }
        for (i = 0; i < n; i++)
        {
            cout << ans[i] << ' ';
        }
    }
    else
    {
        multiset<pair<pair<ll, ll>, ll>> mar;
        multiset<pair<ll, ll>> hert;
        multiset<pair<ll, ll>> hert1;
        for (i = 0; i < n; i++)
        {
            cin >> x >> y >> r;
            v.push_back({ r, {x, y} });
            mar.insert({ {r, -i}, x});
            hert.insert({ x + r, i });
            hert1.insert({ x - r, i });
        }
        while (!mar.empty())
        {
            x = (--mar.end())->second;
            r = (--mar.end())->first.first;
            ll ind = -(--mar.end())->first.second;
            color[ind] = 1;
            ans[ind] = ind + 1;
            auto gn = --hert.upper_bound({ x + r, -1 });
            vector<pair<ll, ll>> herthan1, herthan;
            while (1)
            {
                if (gn == hert.end())
                    gn--;
                ll xx = gn->first;
                ll indind = gn->second;
                if (xx >= x - r)
                {
                    if (color[indind] == 0)
                    {
                        color[indind] = 1;
                        ans[indind] = ind + 1;
                    }
                    herthan.push_back({xx, indind});
                }
                else

                    break;
                if (gn == hert.begin())
                    break;
                else
                    gn--;
            }
            auto gn1 = hert1.lower_bound({ x - r, -1 });
            while (1)
            {
                if (gn1 == hert1.end())
                    break;
                ll xx = gn1->first;
                ll indind = gn1->second;
                if (xx <= x + r)
                {
                    if (color[indind] == 0)
                    {
                        color[indind] = 1;
                        ans[indind] = ind + 1;
                    }
                    herthan1.push_back({ xx, indind });
                }
                else
                    break;
                gn1++;
            }
            for ( i = 0; i < herthan.size(); i++)
            {
                hert.erase(herthan[i]);
                mar.erase({ {v[herthan[i].second].first, -herthan[i].second}, v[herthan[i].second].second.first});
            }
            for (i = 0; i < herthan1.size(); i++)
            {
                hert1.erase(herthan1[i]);
                mar.erase({ {v[herthan1[i].second].first, -herthan1[i].second}, v[herthan1[i].second].second.first });
            }
        }
        for ( i = 0; i < n; i++)
        {
            cout << ans[i] << ' ';
        }
    }
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll tt = 1;
    //cin >> tt;
    while (tt--) {
        solve();
    }
    return 0;
}

Compilation message

circle_selection.cpp: In function 'void solve()':
circle_selection.cpp:147:28: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  147 |             for ( i = 0; i < herthan.size(); i++)
      |                          ~~^~~~~~~~~~~~~~~~
circle_selection.cpp:152:27: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  152 |             for (i = 0; i < herthan1.size(); i++)
      |                         ~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 2 ms 700 KB Output is correct
20 Correct 2 ms 660 KB Output is correct
21 Correct 2 ms 596 KB Output is correct
22 Correct 129 ms 660 KB Output is correct
23 Correct 129 ms 660 KB Output is correct
24 Correct 131 ms 660 KB Output is correct
25 Correct 149 ms 660 KB Output is correct
26 Correct 135 ms 788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1179 ms 83464 KB Output is correct
2 Correct 1188 ms 79080 KB Output is correct
3 Correct 1235 ms 79284 KB Output is correct
4 Correct 1117 ms 82124 KB Output is correct
5 Correct 1053 ms 71320 KB Output is correct
6 Incorrect 972 ms 78880 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 232 ms 23608 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 802 ms 70092 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 2 ms 700 KB Output is correct
20 Correct 2 ms 660 KB Output is correct
21 Correct 2 ms 596 KB Output is correct
22 Correct 129 ms 660 KB Output is correct
23 Correct 129 ms 660 KB Output is correct
24 Correct 131 ms 660 KB Output is correct
25 Correct 149 ms 660 KB Output is correct
26 Correct 135 ms 788 KB Output is correct
27 Incorrect 12 ms 3144 KB Output isn't correct
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 2 ms 700 KB Output is correct
20 Correct 2 ms 660 KB Output is correct
21 Correct 2 ms 596 KB Output is correct
22 Correct 129 ms 660 KB Output is correct
23 Correct 129 ms 660 KB Output is correct
24 Correct 131 ms 660 KB Output is correct
25 Correct 149 ms 660 KB Output is correct
26 Correct 135 ms 788 KB Output is correct
27 Correct 1179 ms 83464 KB Output is correct
28 Correct 1188 ms 79080 KB Output is correct
29 Correct 1235 ms 79284 KB Output is correct
30 Correct 1117 ms 82124 KB Output is correct
31 Correct 1053 ms 71320 KB Output is correct
32 Incorrect 972 ms 78880 KB Output isn't correct
33 Halted 0 ms 0 KB -