Submission #104325

# Submission time Handle Problem Language Result Execution time Memory
104325 2019-04-05T06:06:36 Z dimash241 Circle selection (APIO18_circle_selection) C++17
72 / 100
3000 ms 51448 KB
# include <stdio.h>
# include <bits/stdc++.h>
 
 
#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define For(i,x,y)  for (int i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (int i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red
 
using namespace std;
inline double Time() {return (clock() * 1.0) / CLOCKS_PER_SEC; } 
inline bool isvowel (char c) {
	c = tolower(c);
    if (c == 'a' || c == 'e' || c == 'i' || c == 'y' || c == 'o' || c == 'u') return 1;
    return 0;
}
 
const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 3e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;
 
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
int n, m, k;
int id[N];
ll r[N];
ll x[N];
ll y[N];
int ans[N];
int lim;

bool cmp (int x, int y) {
	return r[x] > r[y] || (r[x] == r[y] && x < y);
}
map < pair < int, int > , vector < int > > q;
void upd () {
	q.clear();
	for (int i = 1; i <= n; i ++) {
		if (!ans[i]) 
			q[mp(x[i] / lim, y[i] / lim)].pb(i);
	}
}
ll sq (ll x) {
	return x * x;
}

bool in (int i, int j) {
	return sq(x[i] - x[j]) + sq(y[i] - y[j]) <= sq(r[i] + r[j]);
}

int main () {
	SpeedForce;               

    cin >> n;
    for (int i = 1; i <= n; i ++) {
    	cin >> x[i] >> y[i] >> r[i];
    	id[i] = i;
    }

    sort(id + 1, id + n + 1, &cmp);
    lim = inf;
    for (int pos = 1, j; pos <= n; pos ++) {
    	j = id[pos];
    	
    	if (ans[j]) continue;

    	if (r[j] * 2 <= lim) {
    		lim = r[j];
    		upd ();
    	}
    	
    	ans[j] = j;
        int xx = x[j] / lim, yy = y[j] / lim;
        for(int x = xx - 2; x <= xx + 2; x ++) {
            for(int y = yy - 2; y <= yy + 2; y ++) {
                if (q.find(make_pair(x, y)) != q.end()) {
                    vector < int > nq;
                    for(auto i : q[make_pair(x, y)]) {
                    	if (ans[i]) continue;
                        if(in(i, j)) {
                            ans[i] = j;
                        } else {
                            nq.push_back(i);
                        }
                    }
                    q[make_pair(x, y)] = nq;
                }
            }
        }
    }
    for (int i = 1; i <= n; i ++)
    	cout << ans[i] << ' ';
    return Accepted;
}
 
// B...a D....
# Verdict Execution time Memory 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 3 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 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 3 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 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 8 ms 768 KB Output is correct
20 Correct 6 ms 768 KB Output is correct
21 Correct 5 ms 640 KB Output is correct
22 Correct 16 ms 1152 KB Output is correct
23 Correct 19 ms 1152 KB Output is correct
24 Correct 16 ms 1152 KB Output is correct
25 Correct 17 ms 1152 KB Output is correct
26 Correct 18 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 216 ms 11980 KB Output is correct
2 Correct 276 ms 12404 KB Output is correct
3 Correct 219 ms 19852 KB Output is correct
4 Correct 283 ms 18768 KB Output is correct
5 Correct 334 ms 17144 KB Output is correct
6 Correct 1210 ms 32620 KB Output is correct
7 Correct 448 ms 18788 KB Output is correct
8 Correct 638 ms 22920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 784 ms 17784 KB Output is correct
3 Correct 2992 ms 51212 KB Output is correct
4 Execution timed out 3017 ms 51244 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2258 ms 44744 KB Output is correct
2 Correct 1610 ms 44664 KB Output is correct
3 Correct 785 ms 21496 KB Output is correct
4 Correct 1634 ms 51448 KB Output is correct
5 Correct 1681 ms 51448 KB Output is correct
6 Correct 345 ms 21816 KB Output is correct
# Verdict Execution time Memory 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 3 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 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 3 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 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 8 ms 768 KB Output is correct
20 Correct 6 ms 768 KB Output is correct
21 Correct 5 ms 640 KB Output is correct
22 Correct 16 ms 1152 KB Output is correct
23 Correct 19 ms 1152 KB Output is correct
24 Correct 16 ms 1152 KB Output is correct
25 Correct 17 ms 1152 KB Output is correct
26 Correct 18 ms 1152 KB Output is correct
27 Correct 8 ms 1024 KB Output is correct
28 Correct 11 ms 1152 KB Output is correct
29 Correct 9 ms 1024 KB Output is correct
30 Correct 36 ms 2048 KB Output is correct
31 Correct 39 ms 2020 KB Output is correct
32 Correct 40 ms 2048 KB Output is correct
33 Correct 75 ms 7924 KB Output is correct
34 Correct 75 ms 7828 KB Output is correct
35 Correct 85 ms 7180 KB Output is correct
36 Correct 652 ms 17628 KB Output is correct
37 Correct 641 ms 17760 KB Output is correct
38 Correct 605 ms 17784 KB Output is correct
39 Correct 534 ms 14616 KB Output is correct
40 Correct 486 ms 14472 KB Output is correct
41 Correct 530 ms 14620 KB Output is correct
42 Correct 428 ms 16632 KB Output is correct
43 Correct 397 ms 17420 KB Output is correct
44 Correct 442 ms 17540 KB Output is correct
45 Correct 383 ms 17408 KB Output is correct
46 Correct 440 ms 17376 KB Output is correct
47 Correct 426 ms 17528 KB Output is correct
48 Correct 465 ms 17616 KB Output is correct
49 Correct 396 ms 17464 KB Output is correct
50 Correct 455 ms 17428 KB Output is correct
# Verdict Execution time Memory 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 3 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 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 3 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 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 8 ms 768 KB Output is correct
20 Correct 6 ms 768 KB Output is correct
21 Correct 5 ms 640 KB Output is correct
22 Correct 16 ms 1152 KB Output is correct
23 Correct 19 ms 1152 KB Output is correct
24 Correct 16 ms 1152 KB Output is correct
25 Correct 17 ms 1152 KB Output is correct
26 Correct 18 ms 1152 KB Output is correct
27 Correct 216 ms 11980 KB Output is correct
28 Correct 276 ms 12404 KB Output is correct
29 Correct 219 ms 19852 KB Output is correct
30 Correct 283 ms 18768 KB Output is correct
31 Correct 334 ms 17144 KB Output is correct
32 Correct 1210 ms 32620 KB Output is correct
33 Correct 448 ms 18788 KB Output is correct
34 Correct 638 ms 22920 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 784 ms 17784 KB Output is correct
37 Correct 2992 ms 51212 KB Output is correct
38 Execution timed out 3017 ms 51244 KB Time limit exceeded
39 Halted 0 ms 0 KB -