답안 #107298

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
107298 2019-04-23T07:37:05 Z leduykhongngu 원 고르기 (APIO18_circle_selection) C++11
49 / 100
3000 ms 65944 KB
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a),_b=(b); i<=_b; ++i)
#define FORR(i,a,b) for (int i=(a),_b=(b); i>=_b; --i)
#define REP(i,b) for (int i=0,_b=(b); i<_b; ++i)
#define endl '\n'
#define sz(x) (int) x.size()
#define mod %
#define fillchar(x,y,z) memset(x,z,y)
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
typedef long long int64;
typedef unsigned long long qword;
using namespace std;
int ReadInt()
{
    char c;
    for (c = getchar(); c!='-'&&(c < '0' || c > '9'); c = getchar());
    int nega=0;
    int ans = c - '0';
    if (c=='-') nega=1,ans=0;
    for (c = getchar(); c >= '0' && c <= '9'; c = getchar())
        ans = ans * 10 + c - '0';
    if (nega) return -ans;
    return ans;
}
void WriteInt(int x)
{
    if (x > 9) WriteInt(x / 10);
    putchar(x % 10 + '0');
}
const int maxn=3e5+5;
inline int64 sqr(int64 x)
{
    return x*x;
}
struct Circle{
    int64 x,y,r;
    int id;

    bool IsIntersect(const Circle &c)
    {
        return sqr(x-c.x)+sqr(y-c.y)<=sqr(r+c.r);
    }
}cir[maxn];
bool operator <(const Circle &b,const Circle &c)
    {
        return mp(-b.r,b.id)<mp(-c.r,c.id);
    }
vector<set<pii> > Point;
vector<int> X;
int n;
int ans[maxn];
pii tmp[maxn];
int main()
{
    #ifdef meomeomeooooo
        freopen("input.txt","r",stdin);
        //freopen(".txt","w",stdout);
    #endif // meomeomeooooo
    iostream::sync_with_stdio(false);
    cin.tie(0);
    n=ReadInt();
    set<Circle> myset;
    FOR(i,1,n) {
        //cin >> cir[i].x >> cir[i].y >> cir[i].r;
        cir[i].x=ReadInt(); cir[i].y=ReadInt(); cir[i].r=ReadInt();
        X.push_back(cir[i].x);
        cir[i].id=i;
        myset.insert(cir[i]);
    }
    sort(X.begin(),X.end());
    X.resize(unique(X.begin(),X.end())-X.begin());
    #define GetDec(x) (lower_bound(X.begin(),X.end(),x)-X.begin())
    Point.resize(X.size());
    FOR(i,1,n) {
        int x=GetDec(cir[i].x);
        Point[x].insert({cir[i].y,cir[i].id});
    }
    while (myset.size()) {
        Circle cur=*myset.begin(); myset.erase(cur);
        ans[cur.id]=cur.id;
        int x=cur.x,y=cur.y,r=cur.r;
        int Lx=max(1ll*x-2*r,-1000000000ll);
        int Rx=min(1ll*x+2*r,1000000000ll);
        Lx=GetDec(Lx);
        for (int i=Lx; i<X.size()&&X[i]<=Rx; ++i) {
            int top=0;
            int64 meomeo=ceil(sqrt(4ll*r*r-sqr(X[i]-x)));
            int Ly=max(1ll*y-meomeo,-1000000000ll);
            int Ry=min(1ll*y+meomeo,1000000000ll);
            assert(Ly>=max(1ll*y-2*r,-1000000000ll));
            assert(Ry<=min(1ll*y+2*r,1000000000ll));
            for (auto j=Point[i].lower_bound(mp(Ly,0)); j!=Point[i].end()&&(*j).fi<=Ry; ++j) {
                int id=(*j).se;
                if (cur.IsIntersect(cir[id])) {
                    assert(ans[id]==0||ans[id]==cur.id);
                    ans[id]=cur.id;
                    myset.erase(cir[id]);
                    tmp[++top]=*j;
                }
            }
            FOR(j,1,top)
                Point[i].erase(tmp[j]);
        }
    }
    FOR(i,1,n) {
        WriteInt(ans[i]); putchar(' ');
    }
    return 0;
}

Compilation message

circle_selection.cpp: In function 'int main()':
circle_selection.cpp:88:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i=Lx; i<X.size()&&X[i]<=Rx; ++i) {
                        ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 3 ms 512 KB Output is correct
17 Correct 3 ms 512 KB Output is correct
18 Correct 4 ms 640 KB Output is correct
19 Correct 7 ms 1508 KB Output is correct
20 Correct 8 ms 1536 KB Output is correct
21 Correct 9 ms 1408 KB Output is correct
22 Correct 9 ms 1408 KB Output is correct
23 Correct 12 ms 1408 KB Output is correct
24 Correct 9 ms 1408 KB Output is correct
25 Correct 7 ms 1408 KB Output is correct
26 Correct 8 ms 1408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1294 ms 65856 KB Output is correct
2 Correct 1218 ms 65924 KB Output is correct
3 Correct 1210 ms 65676 KB Output is correct
4 Correct 1196 ms 65944 KB Output is correct
5 Correct 1038 ms 61156 KB Output is correct
6 Correct 1105 ms 65708 KB Output is correct
7 Correct 1069 ms 65024 KB Output is correct
8 Correct 1084 ms 65172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 458 ms 22136 KB Output is correct
3 Correct 1783 ms 65892 KB Output is correct
4 Correct 1768 ms 65800 KB Output is correct
5 Correct 2731 ms 63908 KB Output is correct
6 Correct 851 ms 34532 KB Output is correct
7 Correct 272 ms 18288 KB Output is correct
8 Correct 31 ms 3968 KB Output is correct
9 Correct 2181 ms 65764 KB Output is correct
10 Execution timed out 3045 ms 63816 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 932 ms 65792 KB Output is correct
2 Correct 577 ms 65844 KB Output is correct
3 Execution timed out 3052 ms 63812 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 3 ms 512 KB Output is correct
17 Correct 3 ms 512 KB Output is correct
18 Correct 4 ms 640 KB Output is correct
19 Correct 7 ms 1508 KB Output is correct
20 Correct 8 ms 1536 KB Output is correct
21 Correct 9 ms 1408 KB Output is correct
22 Correct 9 ms 1408 KB Output is correct
23 Correct 12 ms 1408 KB Output is correct
24 Correct 9 ms 1408 KB Output is correct
25 Correct 7 ms 1408 KB Output is correct
26 Correct 8 ms 1408 KB Output is correct
27 Correct 16 ms 2560 KB Output is correct
28 Correct 18 ms 2560 KB Output is correct
29 Correct 17 ms 2532 KB Output is correct
30 Correct 21 ms 2560 KB Output is correct
31 Correct 23 ms 2560 KB Output is correct
32 Correct 15 ms 2560 KB Output is correct
33 Correct 278 ms 22132 KB Output is correct
34 Correct 314 ms 22104 KB Output is correct
35 Correct 328 ms 22156 KB Output is correct
36 Correct 337 ms 22072 KB Output is correct
37 Correct 291 ms 22184 KB Output is correct
38 Correct 327 ms 22228 KB Output is correct
39 Correct 1190 ms 17520 KB Output is correct
40 Correct 1245 ms 17520 KB Output is correct
41 Correct 1346 ms 17500 KB Output is correct
42 Correct 296 ms 17392 KB Output is correct
43 Correct 210 ms 22128 KB Output is correct
44 Correct 199 ms 22128 KB Output is correct
45 Correct 196 ms 22128 KB Output is correct
46 Correct 187 ms 22128 KB Output is correct
47 Correct 189 ms 22132 KB Output is correct
48 Correct 230 ms 22128 KB Output is correct
49 Correct 169 ms 22100 KB Output is correct
50 Correct 201 ms 22052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 3 ms 512 KB Output is correct
17 Correct 3 ms 512 KB Output is correct
18 Correct 4 ms 640 KB Output is correct
19 Correct 7 ms 1508 KB Output is correct
20 Correct 8 ms 1536 KB Output is correct
21 Correct 9 ms 1408 KB Output is correct
22 Correct 9 ms 1408 KB Output is correct
23 Correct 12 ms 1408 KB Output is correct
24 Correct 9 ms 1408 KB Output is correct
25 Correct 7 ms 1408 KB Output is correct
26 Correct 8 ms 1408 KB Output is correct
27 Correct 1294 ms 65856 KB Output is correct
28 Correct 1218 ms 65924 KB Output is correct
29 Correct 1210 ms 65676 KB Output is correct
30 Correct 1196 ms 65944 KB Output is correct
31 Correct 1038 ms 61156 KB Output is correct
32 Correct 1105 ms 65708 KB Output is correct
33 Correct 1069 ms 65024 KB Output is correct
34 Correct 1084 ms 65172 KB Output is correct
35 Correct 2 ms 384 KB Output is correct
36 Correct 458 ms 22136 KB Output is correct
37 Correct 1783 ms 65892 KB Output is correct
38 Correct 1768 ms 65800 KB Output is correct
39 Correct 2731 ms 63908 KB Output is correct
40 Correct 851 ms 34532 KB Output is correct
41 Correct 272 ms 18288 KB Output is correct
42 Correct 31 ms 3968 KB Output is correct
43 Correct 2181 ms 65764 KB Output is correct
44 Execution timed out 3045 ms 63816 KB Time limit exceeded