답안 #90985

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
90985 2018-12-25T11:55:33 Z tincamatei 원 고르기 (APIO18_circle_selection) C++14
49 / 100
3000 ms 353640 KB
#include <bits/stdc++.h>

using namespace std;

unordered_map<int, unordered_map<int, vector<int> > > grid;

const int MAX_N = 300000;
int xc[1+MAX_N], yc[1+MAX_N], rc[1+MAX_N];
int rez[1+MAX_N];
int poz[1+MAX_N];

void rescale(int n, int d) {
	grid.clear();
	for(int i = 1; i <= n; ++i)
		if(rez[i] == 0)
			grid[xc[i] / d][yc[i] / d].push_back(i);
}

bool cmp(int a, int b) {
	return rc[a] > rc[b] || (rc[a] == rc[b] && a < b);
}

double dist(int a, int b) {
	return sqrt((long long)(xc[a] - xc[b]) * (xc[a] - xc[b]) +
	            (long long)(yc[a] - yc[b]) * (yc[a] - yc[b]));
}

int main() {
#ifdef HOME
	FILE *fin = fopen("input.in", "r");
	FILE *fout = fopen("output.out", "w");
#else
	FILE *fin = stdin;
	FILE *fout = stdout;
#endif

	int n;
	int mnx, mny;

	mnx = mny = 1000000000;
	
	fscanf(fin, "%d", &n);
	for(int i = 1; i <= n; ++i) {
		fscanf(fin, "%d%d%d", &xc[i], &yc[i], &rc[i]);
		mnx = min(mnx, xc[i]);
		mny = min(mny, yc[i]);
		poz[i - 1] = i;
	}

	for(int i = 1; i <= n; ++i) {
		xc[i] -= mnx;
		yc[i] -= mny;
	}

	sort(poz, poz + n, cmp);

	int lastr = (1 << 30);
	rescale(n, lastr);

	for(int i = 0; i < n; ++i) {
		int p = poz[i];
		if(rez[p] == 0) {
			while(rc[p] * 2 <= lastr) {
				lastr = rc[p];
				rescale(n, lastr);
			}

			int x = xc[p] / lastr, y = yc[p] / lastr;

			for(int i = x - 2; i <= x + 2; ++i)
				for(int j = y - 2; j <= y + 2; ++j) {
					vector<int> *xd = &grid[i][j];
					for(auto it: *xd)
						if(rez[it] == 0 && dist(p, it) <= rc[p] + rc[it])
							rez[it] = p;
				}
		}
	}

	for(int i = 1; i <= n; ++i)
		fprintf(fout, "%d ", rez[i]);

#ifdef HOME
	fclose(fin);
	fclose(fout);
#endif
	return 0;
}

Compilation message

circle_selection.cpp: In function 'int main()':
circle_selection.cpp:42:8: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  fscanf(fin, "%d", &n);
  ~~~~~~^~~~~~~~~~~~~~~
circle_selection.cpp:44:9: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   fscanf(fin, "%d%d%d", &xc[i], &yc[i], &rc[i]);
   ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 500 KB Output is correct
3 Correct 2 ms 500 KB Output is correct
4 Correct 2 ms 500 KB Output is correct
5 Correct 2 ms 540 KB Output is correct
6 Correct 2 ms 640 KB Output is correct
7 Correct 2 ms 640 KB Output is correct
8 Correct 2 ms 640 KB Output is correct
9 Correct 2 ms 644 KB Output is correct
10 Correct 2 ms 644 KB Output is correct
11 Correct 2 ms 672 KB Output is correct
12 Correct 2 ms 672 KB Output is correct
13 Correct 2 ms 716 KB Output is correct
14 Correct 2 ms 716 KB Output is correct
15 Correct 2 ms 716 KB Output is correct
16 Correct 2 ms 716 KB Output is correct
17 Correct 2 ms 716 KB Output is correct
18 Correct 3 ms 716 KB Output is correct
19 Correct 5 ms 736 KB Output is correct
20 Correct 5 ms 748 KB Output is correct
21 Correct 5 ms 764 KB Output is correct
22 Correct 32 ms 5132 KB Output is correct
23 Correct 32 ms 5132 KB Output is correct
24 Correct 34 ms 5404 KB Output is correct
25 Correct 42 ms 6444 KB Output is correct
26 Correct 33 ms 6444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 206 ms 10492 KB Output is correct
2 Correct 203 ms 10756 KB Output is correct
3 Correct 206 ms 10756 KB Output is correct
4 Correct 197 ms 10756 KB Output is correct
5 Correct 239 ms 12920 KB Output is correct
6 Correct 1762 ms 84472 KB Output is correct
7 Correct 308 ms 84472 KB Output is correct
8 Correct 509 ms 84472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 84472 KB Output is correct
2 Correct 1578 ms 84472 KB Output is correct
3 Execution timed out 3036 ms 247844 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3046 ms 353640 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 500 KB Output is correct
3 Correct 2 ms 500 KB Output is correct
4 Correct 2 ms 500 KB Output is correct
5 Correct 2 ms 540 KB Output is correct
6 Correct 2 ms 640 KB Output is correct
7 Correct 2 ms 640 KB Output is correct
8 Correct 2 ms 640 KB Output is correct
9 Correct 2 ms 644 KB Output is correct
10 Correct 2 ms 644 KB Output is correct
11 Correct 2 ms 672 KB Output is correct
12 Correct 2 ms 672 KB Output is correct
13 Correct 2 ms 716 KB Output is correct
14 Correct 2 ms 716 KB Output is correct
15 Correct 2 ms 716 KB Output is correct
16 Correct 2 ms 716 KB Output is correct
17 Correct 2 ms 716 KB Output is correct
18 Correct 3 ms 716 KB Output is correct
19 Correct 5 ms 736 KB Output is correct
20 Correct 5 ms 748 KB Output is correct
21 Correct 5 ms 764 KB Output is correct
22 Correct 32 ms 5132 KB Output is correct
23 Correct 32 ms 5132 KB Output is correct
24 Correct 34 ms 5404 KB Output is correct
25 Correct 42 ms 6444 KB Output is correct
26 Correct 33 ms 6444 KB Output is correct
27 Correct 8 ms 353640 KB Output is correct
28 Correct 9 ms 353640 KB Output is correct
29 Correct 8 ms 353640 KB Output is correct
30 Correct 91 ms 353640 KB Output is correct
31 Correct 71 ms 353640 KB Output is correct
32 Correct 97 ms 353640 KB Output is correct
33 Correct 72 ms 353640 KB Output is correct
34 Correct 71 ms 353640 KB Output is correct
35 Correct 79 ms 353640 KB Output is correct
36 Correct 1597 ms 353640 KB Output is correct
37 Correct 1748 ms 353640 KB Output is correct
38 Correct 1467 ms 353640 KB Output is correct
39 Correct 430 ms 353640 KB Output is correct
40 Correct 443 ms 353640 KB Output is correct
41 Correct 516 ms 353640 KB Output is correct
42 Correct 179 ms 353640 KB Output is correct
43 Correct 978 ms 353640 KB Output is correct
44 Correct 939 ms 353640 KB Output is correct
45 Correct 841 ms 353640 KB Output is correct
46 Correct 941 ms 353640 KB Output is correct
47 Correct 942 ms 353640 KB Output is correct
48 Correct 1031 ms 353640 KB Output is correct
49 Correct 970 ms 353640 KB Output is correct
50 Correct 1010 ms 353640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 500 KB Output is correct
3 Correct 2 ms 500 KB Output is correct
4 Correct 2 ms 500 KB Output is correct
5 Correct 2 ms 540 KB Output is correct
6 Correct 2 ms 640 KB Output is correct
7 Correct 2 ms 640 KB Output is correct
8 Correct 2 ms 640 KB Output is correct
9 Correct 2 ms 644 KB Output is correct
10 Correct 2 ms 644 KB Output is correct
11 Correct 2 ms 672 KB Output is correct
12 Correct 2 ms 672 KB Output is correct
13 Correct 2 ms 716 KB Output is correct
14 Correct 2 ms 716 KB Output is correct
15 Correct 2 ms 716 KB Output is correct
16 Correct 2 ms 716 KB Output is correct
17 Correct 2 ms 716 KB Output is correct
18 Correct 3 ms 716 KB Output is correct
19 Correct 5 ms 736 KB Output is correct
20 Correct 5 ms 748 KB Output is correct
21 Correct 5 ms 764 KB Output is correct
22 Correct 32 ms 5132 KB Output is correct
23 Correct 32 ms 5132 KB Output is correct
24 Correct 34 ms 5404 KB Output is correct
25 Correct 42 ms 6444 KB Output is correct
26 Correct 33 ms 6444 KB Output is correct
27 Correct 206 ms 10492 KB Output is correct
28 Correct 203 ms 10756 KB Output is correct
29 Correct 206 ms 10756 KB Output is correct
30 Correct 197 ms 10756 KB Output is correct
31 Correct 239 ms 12920 KB Output is correct
32 Correct 1762 ms 84472 KB Output is correct
33 Correct 308 ms 84472 KB Output is correct
34 Correct 509 ms 84472 KB Output is correct
35 Correct 2 ms 84472 KB Output is correct
36 Correct 1578 ms 84472 KB Output is correct
37 Execution timed out 3036 ms 247844 KB Time limit exceeded
38 Halted 0 ms 0 KB -