Submission #429639

# Submission time Handle Problem Language Result Execution time Memory
429639 2021-06-16T08:09:44 Z 송준혁(#7525) Power plants (CPSPC17_power) C++17
35 / 100
6000 ms 9280 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define lb lower_bound
#define MOD 1000000007
#define INF (1ll<<61)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

int N, M, Q;
int chk[101010];
pii B[101010];
LL ans, X[101010], Y[101010];
vector<int> V[101010], ansX, ansY;
vector<pii> C;

int bid(LL x, LL k){
	int lo=0, hi=MOD, ret=0;
	while (lo<=hi){
		LL m=lo+hi>>1;
		if (m*m <= 4*x*x/k) ret=m, lo=m+1;
		else hi=m-1;
	}
	return ret;
}

int id(int x, int y){
	int t = lb(C.begin(), C.end(), pii(x,y))-C.begin();
	if (t >= C.size() || C[t] != pii(x,y)) return -1;
	return t;
}

bool dfs(int u, int c, LL k){
	if (chk[u]) return chk[u]*c < 0;
	chk[u] = c;
	for (int dx=-2; dx<=2; dx++) for (int dy=-2; dy<=2; dy++){
		int t = id(B[u].fi+dx, B[u].se+dy);
		if (t < 0) continue;
		for (int v : V[t]) if (v != u && (X[u]-X[v])*(X[u]-X[v])+(Y[u]-Y[v])*(Y[u]-Y[v]) <= k){
			if (dfs(v, -c, k)) return true;
		}
	}
	return false;
}

bool f(LL k){
	for (int i=0; i<C.size(); i++) V[i].clear();
	for (int i=1; i<=N; i++) chk[i] = 0;
	C.clear();
	for (int i=1; i<=N; i++){
		B[i].fi = bid(X[i], k);
		B[i].se = bid(Y[i], k);
		C.pb(B[i]);
	}
	sort(C.begin(), C.end());
	for (int i=1; i<=N; i++){
		int t = id(B[i].fi, B[i].se);
		V[t].pb(i);
		if (V[t].size() > 2) return false;
	}
	for (int i=1; i<=N; i++){
		if (chk[i]) continue;
		if (dfs(i, 1, k)) return false;
	}
	return true;
}

int main(){
	scanf("%d", &N);
	for (int i=1; i<=N; i++) scanf("%lld %lld", &X[i], &Y[i]);
	LL lo=0, hi=INF;
	while (lo<=hi){
		LL m = lo+hi>>1;
		if (f(m)) ans = m, lo = m + 1;
		else hi = m - 1;
	}
	printf("%lld\n", ans+1);
	f(ans);
	for (int i=1; i<=N; i++){
		if (chk[i] > 0) ansX.pb(i);
		else ansY.pb(i);
	}
	printf("%d\n", ansX.size());
	for (int x : ansX) printf("%d ", x);
	printf("\n");
	printf("%d\n", ansY.size());
	for (int x : ansY) printf("%d ", x);
	printf("\n");
	return 0;
}

Compilation message

Main.cpp: In function 'int bid(LL, LL)':
Main.cpp:22:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   22 |   LL m=lo+hi>>1;
      |        ~~^~~
Main.cpp: In function 'int id(int, int)':
Main.cpp:31:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |  if (t >= C.size() || C[t] != pii(x,y)) return -1;
      |      ~~^~~~~~~~~~~
Main.cpp: In function 'bool f(LL)':
Main.cpp:49:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |  for (int i=0; i<C.size(); i++) V[i].clear();
      |                ~^~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:75:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   75 |   LL m = lo+hi>>1;
      |          ~~^~~
Main.cpp:85:11: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wformat=]
   85 |  printf("%d\n", ansX.size());
      |          ~^     ~~~~~~~~~~~
      |           |              |
      |           int            std::vector<int>::size_type {aka long unsigned int}
      |          %ld
Main.cpp:88:11: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wformat=]
   88 |  printf("%d\n", ansY.size());
      |          ~^     ~~~~~~~~~~~
      |           |              |
      |           int            std::vector<int>::size_type {aka long unsigned int}
      |          %ld
Main.cpp:71:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |  scanf("%d", &N);
      |  ~~~~~^~~~~~~~~~
Main.cpp:72:32: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |  for (int i=1; i<=N; i++) scanf("%lld %lld", &X[i], &Y[i]);
      |                           ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2636 KB Output is correct
2 Correct 4 ms 2636 KB Output is correct
3 Correct 4 ms 2636 KB Output is correct
4 Correct 3 ms 2636 KB Output is correct
5 Correct 4 ms 2636 KB Output is correct
6 Correct 3 ms 2600 KB Output is correct
7 Correct 4 ms 2636 KB Output is correct
8 Correct 4 ms 2696 KB Output is correct
9 Correct 4 ms 2636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2636 KB Output is correct
2 Correct 4 ms 2636 KB Output is correct
3 Correct 4 ms 2636 KB Output is correct
4 Correct 3 ms 2636 KB Output is correct
5 Correct 4 ms 2636 KB Output is correct
6 Correct 3 ms 2600 KB Output is correct
7 Correct 4 ms 2636 KB Output is correct
8 Correct 4 ms 2696 KB Output is correct
9 Correct 4 ms 2636 KB Output is correct
10 Correct 56 ms 2764 KB Output is correct
11 Correct 67 ms 2764 KB Output is correct
12 Correct 47 ms 2768 KB Output is correct
13 Correct 35 ms 2892 KB Output is correct
14 Correct 59 ms 3000 KB Output is correct
15 Correct 24 ms 3032 KB Output is correct
16 Correct 52 ms 2764 KB Output is correct
17 Correct 74 ms 2764 KB Output is correct
18 Correct 64 ms 2972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2636 KB Output is correct
2 Correct 4 ms 2636 KB Output is correct
3 Correct 4 ms 2636 KB Output is correct
4 Correct 3 ms 2636 KB Output is correct
5 Correct 4 ms 2636 KB Output is correct
6 Correct 3 ms 2600 KB Output is correct
7 Correct 4 ms 2636 KB Output is correct
8 Correct 4 ms 2696 KB Output is correct
9 Correct 4 ms 2636 KB Output is correct
10 Correct 56 ms 2764 KB Output is correct
11 Correct 67 ms 2764 KB Output is correct
12 Correct 47 ms 2768 KB Output is correct
13 Correct 35 ms 2892 KB Output is correct
14 Correct 59 ms 3000 KB Output is correct
15 Correct 24 ms 3032 KB Output is correct
16 Correct 52 ms 2764 KB Output is correct
17 Correct 74 ms 2764 KB Output is correct
18 Correct 64 ms 2972 KB Output is correct
19 Execution timed out 6065 ms 9280 KB Time limit exceeded
20 Halted 0 ms 0 KB -