Submission #1070994

# Submission time Handle Problem Language Result Execution time Memory
1070994 2024-08-22T22:39:58 Z pawned Circle selection (APIO18_circle_selection) C++17
0 / 100
3000 ms 282968 KB
#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")

#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;

const char nl = '\n';

void fastIO() {
	ios::sync_with_stdio(false);
	cin.tie(0);
}

int dirX[9] = {-1, -1, -1, 0, 0, 0, 1, 1, 1};
int dirY[9] = {-1, 0, 1, -1, 0, 1, -1, 0, 1};

int N, R;

int flat(int x, int y) {
	if (x >= 0)
		return x / y;
	else
		return -((-x + y - 1) / y);
}

bool intersect(ii c1, ii c2) {
	ll dx = abs(c1.fi - c2.fi);
	ll dy = abs(c1.se - c2.se);
	if (dx * dx + dy * dy <= 4 * R * R)
		return true;
	return false;
}

int main() {
	fastIO();
	int N;
	cin>>N;
	vector<ii> cr(N);
	// {{x, y}, r}
	for (int i = 0; i < N; i++) {
		cin>>cr[i].fi>>cr[i].se;
		cin>>R;
	}
//	cout<<"R: "<<R<<endl;
	vector<ii> ft(N);
	map<ii, set<int>> all;
	for (int i = 0; i < N; i++) {
		ft[i] = {flat(cr[i].fi, 2 * R), flat(cr[i].se, 2 * R)};
		all[ft[i]].insert(i);
	}
	vector<bool> vis(N, false);
	vi par(N, -1);
	for (int i = 0; i < N; i++) {
		if (vis[i])
			continue;
		int xc = ft[i].fi;
		int yc = ft[i].se;
		for (int j = 0; j < 9; j++) {
			int xn = xc + dirX[j];
			int yn = yc + dirY[j];
			vi toerase;
			for (int x : all[{xn, yn}]) {
				if (!vis[x] && intersect(cr[i], cr[x])) {
					vis[x] = true;
					par[x] = i;
					toerase.pb(x);
				}
			}
			for (int x : toerase)
				all[{xn, yn}].erase(x);
		}
	}
//	cout<<"ANSWER: ";
	for (int x : par)
		cout<<(x + 1)<<" ";
	cout<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3091 ms 20200 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1617 ms 275700 KB Output is correct
2 Correct 1353 ms 282968 KB Output is correct
3 Incorrect 1196 ms 32856 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -