답안 #49637

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
49637 2018-06-01T12:20:58 Z gs13105 원 고르기 (APIO18_circle_selection) C++17
38 / 100
1358 ms 30972 KB
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <iterator>

using namespace std;

struct cir
{
    int x, y, r, i;
    bool operator <(const cir &a) const
    {
        return r != a.r ? r > a.r : i < a.i;
    }
};

const int MAXN = 300000;
const int MAXV = 1000000000;
cir arr[MAXN + 10];
int num[MAXN + 10];
int res[MAXN + 10];
int n;

bool inter(const cir &a, const cir &b)
{
    return 1LL * (a.x - b.x) * (a.x - b.x) + 1LL * (a.y - b.y) * (a.y - b.y) <= 1LL * (a.r + b.r) * (a.r + b.r);
}

vector<long long> com;
long long tmp[MAXN + 10];
vector<int> lis[MAXN + 10];

inline int idx(long long x)
{
    return lower_bound(com.begin(), com.end(), x) - com.begin();
}

inline long long idx2(int x, int y, int r)
{
    return (2LL * MAXV + 1) * ((x + MAXV) / r) + (y + MAXV) / r;
}

void init(int s, int mx)
{
    com.clear();
    for(int i = 0; i < n - s; i++)
        lis[i].clear();

    for(int i = s; i <= n; i++)
    {
        tmp[i] = idx2(arr[i].x, arr[i].y, mx);
        com.push_back(tmp[i]);
    }

    sort(com.begin(), com.end());
    com.erase(unique(com.begin(), com.end()), com.end());

    for(int i = s; i <= n; i++)
        lis[idx(tmp[i])].push_back(i);
}

int main()
{
    //freopen("in", "r", stdin);
    //freopen("out", "w", stdout);

    int i, j, k;
    scanf("%d", &n);
    for(i = 1; i <= n; i++)
    {
        int x, y, r;
        scanf("%d%d%d", &x, &y, &r);
        arr[i] = { x, y, r, i };
    }

    sort(arr + 1, arr + n + 1);

    int mx = arr[1].r;
    init(1, mx);
    for(i = 1; i <= n; i++)
    {
        if(num[i])
            continue;

        if(arr[i].r <= mx / 2)
        {
            mx = arr[i].r;
            init(i, mx);
        }

        for(j = -2; j <= 2; j++)
        {
            for(k = -2; k <= 2; k++)
            {
                int nx = max(0LL + -MAXV, min(0LL + MAXV, arr[i].x + 1LL * j * mx));
                int ny = max(0LL + -MAXV, min(0LL + MAXV, arr[i].y + 1LL * k * mx));

                long long t = idx2(nx, ny, mx);
                int t2 = idx(t);
                if(t2 == com.size() || com[t2] != t)
                    continue;

                vector<int> nex;
                for(int &x : lis[t2])
                {
                    if(inter(arr[i], arr[x]))
                        num[x] = arr[i].i;
                    else
                        nex.push_back(x);
                }
                lis[t2] = nex;
            }
        }
    }

    for(i = 1; i <= n; i++)
        res[arr[i].i] = num[i];

    for(i = 1; i <= n; i++)
        printf("%d ", res[i]);

    return 0;
}

Compilation message

circle_selection.cpp: In function 'int main()':
circle_selection.cpp:112:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 if(t2 == com.size() || com[t2] != t)
                    ~~~^~~~~~~~~~~~~
circle_selection.cpp:80:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
circle_selection.cpp:84:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d", &x, &y, &r);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7420 KB Output is correct
2 Correct 8 ms 7420 KB Output is correct
3 Correct 8 ms 7456 KB Output is correct
4 Correct 8 ms 7520 KB Output is correct
5 Correct 8 ms 7520 KB Output is correct
6 Correct 8 ms 7616 KB Output is correct
7 Correct 7 ms 7652 KB Output is correct
8 Correct 8 ms 7652 KB Output is correct
9 Incorrect 7 ms 7652 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 216 ms 23928 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 23928 KB Output is correct
2 Correct 392 ms 23928 KB Output is correct
3 Correct 1194 ms 30928 KB Output is correct
4 Correct 1285 ms 30928 KB Output is correct
5 Correct 1316 ms 30928 KB Output is correct
6 Correct 465 ms 30928 KB Output is correct
7 Correct 233 ms 30928 KB Output is correct
8 Correct 43 ms 30928 KB Output is correct
9 Correct 1358 ms 30928 KB Output is correct
10 Correct 1227 ms 30928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1032 ms 30928 KB Output is correct
2 Correct 923 ms 30972 KB Output is correct
3 Correct 450 ms 30972 KB Output is correct
4 Correct 968 ms 30972 KB Output is correct
5 Correct 1008 ms 30972 KB Output is correct
6 Correct 352 ms 30972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7420 KB Output is correct
2 Correct 8 ms 7420 KB Output is correct
3 Correct 8 ms 7456 KB Output is correct
4 Correct 8 ms 7520 KB Output is correct
5 Correct 8 ms 7520 KB Output is correct
6 Correct 8 ms 7616 KB Output is correct
7 Correct 7 ms 7652 KB Output is correct
8 Correct 8 ms 7652 KB Output is correct
9 Incorrect 7 ms 7652 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7420 KB Output is correct
2 Correct 8 ms 7420 KB Output is correct
3 Correct 8 ms 7456 KB Output is correct
4 Correct 8 ms 7520 KB Output is correct
5 Correct 8 ms 7520 KB Output is correct
6 Correct 8 ms 7616 KB Output is correct
7 Correct 7 ms 7652 KB Output is correct
8 Correct 8 ms 7652 KB Output is correct
9 Incorrect 7 ms 7652 KB Output isn't correct
10 Halted 0 ms 0 KB -