Submission #104326

# Submission time Handle Problem Language Result Execution time Memory
104326 2019-04-05T06:10:22 Z dimash241 Circle selection (APIO18_circle_selection) C++17
72 / 100
3000 ms 48760 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;
    vector < int > nq;
          	          
    for (int pos = 1, j, xx, yy; pos <= n; pos ++) {
    	j = id[pos];
    	
    	if (ans[j]) continue;

    	if (r[j] * 2 <= lim) {
    		lim = r[j];
    		upd ();
    	}
    	
    	ans[j] = j;
        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()) {
                	nq.clear();
                    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)].swap(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 2 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 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 3 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 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 7 ms 768 KB Output is correct
21 Correct 6 ms 768 KB Output is correct
22 Correct 18 ms 1280 KB Output is correct
23 Correct 19 ms 1280 KB Output is correct
24 Correct 18 ms 1152 KB Output is correct
25 Correct 22 ms 1152 KB Output is correct
26 Correct 15 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 213 ms 13404 KB Output is correct
2 Correct 208 ms 12820 KB Output is correct
3 Correct 218 ms 13672 KB Output is correct
4 Correct 191 ms 12384 KB Output is correct
5 Correct 263 ms 12792 KB Output is correct
6 Correct 1109 ms 28408 KB Output is correct
7 Correct 407 ms 14748 KB Output is correct
8 Correct 588 ms 18680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 809 ms 15400 KB Output is correct
3 Correct 2856 ms 45180 KB Output is correct
4 Correct 2898 ms 45200 KB Output is correct
5 Correct 2939 ms 45020 KB Output is correct
6 Correct 1018 ms 23160 KB Output is correct
7 Correct 408 ms 12536 KB Output is correct
8 Correct 51 ms 3064 KB Output is correct
9 Execution timed out 3033 ms 48760 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2239 ms 44956 KB Output is correct
2 Correct 1596 ms 45068 KB Output is correct
3 Correct 732 ms 22176 KB Output is correct
4 Correct 1652 ms 45304 KB Output is correct
5 Correct 1494 ms 45248 KB Output is correct
6 Correct 291 ms 15736 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 2 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 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 3 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 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 7 ms 768 KB Output is correct
21 Correct 6 ms 768 KB Output is correct
22 Correct 18 ms 1280 KB Output is correct
23 Correct 19 ms 1280 KB Output is correct
24 Correct 18 ms 1152 KB Output is correct
25 Correct 22 ms 1152 KB Output is correct
26 Correct 15 ms 1152 KB Output is correct
27 Correct 9 ms 1152 KB Output is correct
28 Correct 8 ms 1024 KB Output is correct
29 Correct 9 ms 1024 KB Output is correct
30 Correct 40 ms 2048 KB Output is correct
31 Correct 32 ms 2048 KB Output is correct
32 Correct 48 ms 1976 KB Output is correct
33 Correct 83 ms 5236 KB Output is correct
34 Correct 93 ms 5140 KB Output is correct
35 Correct 77 ms 4624 KB Output is correct
36 Correct 737 ms 15452 KB Output is correct
37 Correct 784 ms 15480 KB Output is correct
38 Correct 708 ms 15480 KB Output is correct
39 Correct 603 ms 14504 KB Output is correct
40 Correct 688 ms 14388 KB Output is correct
41 Correct 643 ms 14416 KB Output is correct
42 Correct 519 ms 15352 KB Output is correct
43 Correct 484 ms 15288 KB Output is correct
44 Correct 458 ms 15164 KB Output is correct
45 Correct 490 ms 15228 KB Output is correct
46 Correct 414 ms 15224 KB Output is correct
47 Correct 427 ms 15236 KB Output is correct
48 Correct 467 ms 15352 KB Output is correct
49 Correct 487 ms 15224 KB Output is correct
50 Correct 451 ms 15352 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 2 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 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 3 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 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 7 ms 768 KB Output is correct
21 Correct 6 ms 768 KB Output is correct
22 Correct 18 ms 1280 KB Output is correct
23 Correct 19 ms 1280 KB Output is correct
24 Correct 18 ms 1152 KB Output is correct
25 Correct 22 ms 1152 KB Output is correct
26 Correct 15 ms 1152 KB Output is correct
27 Correct 213 ms 13404 KB Output is correct
28 Correct 208 ms 12820 KB Output is correct
29 Correct 218 ms 13672 KB Output is correct
30 Correct 191 ms 12384 KB Output is correct
31 Correct 263 ms 12792 KB Output is correct
32 Correct 1109 ms 28408 KB Output is correct
33 Correct 407 ms 14748 KB Output is correct
34 Correct 588 ms 18680 KB Output is correct
35 Correct 2 ms 384 KB Output is correct
36 Correct 809 ms 15400 KB Output is correct
37 Correct 2856 ms 45180 KB Output is correct
38 Correct 2898 ms 45200 KB Output is correct
39 Correct 2939 ms 45020 KB Output is correct
40 Correct 1018 ms 23160 KB Output is correct
41 Correct 408 ms 12536 KB Output is correct
42 Correct 51 ms 3064 KB Output is correct
43 Execution timed out 3033 ms 48760 KB Time limit exceeded
44 Halted 0 ms 0 KB -