답안 #256007

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
256007 2020-08-02T07:58:20 Z 구재현(#5035) Mixture (BOI20_mixture) C++17
60 / 100
2000 ms 2040 KB
#include <bits/stdc++.h>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;
const int MAXN = 100005;

inline int frcmp(int x1, int d1, int x2, int d2){
	lint p = 1ll * x2 * d1 - 1ll * x1 * d2;
	if(p > 0) return 1;
	if(p < 0) return -1;
	return 0;
}

struct pnt{
	int x, y, d;
	bool operator<(const pnt &b)const{
		int t = frcmp(x, d, b.x, b.d);
		if(t != 0) return t > 0;
		return frcmp(y, d, b.y, b.d) > 0;
	}
	bool operator==(const pnt &p)const{
		return x == p.x && y == p.y && d == p.d;
	}
	bool operator>(const pnt &b)const{
		return b < *this;
	}
};

pnt input(){
	int x, y, z; scanf("%d %d %d",&x,&y,&z);
	int g = gcd(x, gcd(y, z));
	x /= g; y /= g; z /= g;
	return (pnt){x, y, x + y + z};
}

inline int ccw(pnt p1, pnt p2, pnt p3){
	lint lhs = 1ll * p1.d * p2.x * p3.y - 1ll * p1.x * p2.d * p3.y - 1ll * p1.y * p2.x * p3.d;
	lint rhs = 1ll * p1.d * p2.y * p3.x - 1ll * p1.x * p2.y * p3.d - 1ll * p1.y * p2.d * p3.x;
	if(lhs > rhs) return 1;
	if(lhs < rhs) return -1;
	return 0;
}

pnt c, a[MAXN];
bool mark[MAXN];
int cnt;


int type(pnt p){
	if(c == p) return -1;
	if(c < p) return 0;
	return 1;
}

auto cmp = [](pnt a, pnt b){ return ccw(c, a, b) > 0; };
vector<multiset<pnt,  decltype(cmp)>> s;


bool in_cvxh(){
	vector<pnt> v, uh, lh;
	for(int i=1; i<=cnt; i++){
		if(!mark[i]) v.push_back(a[i]);
	}
	if(sz(v) <= 2) return 0;
	sort(all(v));
	int n = sz(v);
	for(int i=0; i<n; i++){
		while(lh.size() >= 2 && ccw(lh[lh.size()-2], lh.back(), v[i]) <= 0){
			lh.pop_back();
		}
		lh.push_back(v[i]);
	}
	for(int i=n-1; i>=0; i--){
		while(uh.size() >= 2 && ccw(uh[uh.size()-2], uh.back(), v[i]) <= 0){
			uh.pop_back();
		}
		uh.push_back(v[i]);
	}
	reverse(uh.begin(), uh.end());
	pnt x = c;
	bool bad = (x < lh[0] || x < uh[0] || lh.back() < x || uh.back() < x);
	auto lo = upper_bound(lh.begin(), lh.end(), x);
	for(int i=0; i<5 && lo != lh.begin(); i++){
		auto t = lo; t--;
		if(ccw(*t, *lo, x) == -1){
			bad = 1;
			break;
		}
		lo--;
	}
	lo = upper_bound(uh.begin(), uh.end(), x);
	for(int i=0; i<5 && lo != uh.begin(); i++){
		auto t = lo; t--;
		if(ccw(*t, *lo, x) == 1){
			bad = 1;
			break;
		}
		lo--;
	}
	return !bad;
}

int main(){
	int onecnt = 0;
	for(int i=0; i<2; i++){
		s.emplace_back(cmp);
	}
	c = input();
	int q; scanf("%d",&q);
	char buf[69];
	while(q--){
		scanf("%s", buf);
		if(*buf == 'A'){
			a[++cnt] = input();
			int v = type(a[cnt]);
			if(v == -1) onecnt++;
			else{
				s[v].insert(a[cnt]);
			}
		}
		else{
			int x; scanf("%d",&x);
			mark[x] = 1;
			int v = type(a[x]);
			if(v == -1) onecnt--;
			else{
				s[v].erase(s[v].find(a[x]));
			}
		}
		if(onecnt > 0) puts("1");
		else{
			auto j = s[1].begin(); 
			bool good = 0;
			for(auto &i : s[0]){
				while(j != s[1].end() && ccw(c, i, *j) > 0) j++;
				if(j != s[1].end() && ccw(c, i, *j) == 0){
					puts("2");
					good = 1;
					break;
				}
			}
			if(!good){
				puts(in_cvxh() ? "3" : "0");
			}
		}
		continue;
		for(auto &i : s[0]) printf("%d %d %d\n", i.x, i.y, i.d);
		puts("ok");
		for(auto &i : s[1]) printf("%d %d %d\n", i.x, i.y, i.d);
		puts("--");
	}
}

Compilation message

Mixture.cpp: In function 'pnt input()':
Mixture.cpp:33:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int x, y, z; scanf("%d %d %d",&x,&y,&z);
               ~~~~~^~~~~~~~~~~~~~~~~~~~~
Mixture.cpp: In function 'int main()':
Mixture.cpp:112:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int q; scanf("%d",&q);
         ~~~~~^~~~~~~~~
Mixture.cpp:115:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s", buf);
   ~~~~~^~~~~~~~~~~
Mixture.cpp:125:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    int x; scanf("%d",&x);
           ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 1 ms 256 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 1 ms 256 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 1 ms 256 KB Output is correct
21 Correct 0 ms 256 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 3 ms 384 KB Output is correct
28 Correct 11 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 4 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 11 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 3 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 1 ms 256 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 1 ms 256 KB Output is correct
21 Correct 0 ms 256 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 3 ms 384 KB Output is correct
28 Correct 11 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 4 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 11 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 3 ms 384 KB Output is correct
37 Correct 4 ms 384 KB Output is correct
38 Correct 3 ms 384 KB Output is correct
39 Correct 4 ms 384 KB Output is correct
40 Correct 29 ms 384 KB Output is correct
41 Correct 36 ms 384 KB Output is correct
42 Correct 28 ms 384 KB Output is correct
43 Correct 24 ms 384 KB Output is correct
44 Correct 18 ms 384 KB Output is correct
45 Correct 16 ms 384 KB Output is correct
46 Correct 9 ms 512 KB Output is correct
47 Correct 212 ms 552 KB Output is correct
48 Correct 5 ms 384 KB Output is correct
49 Correct 20 ms 384 KB Output is correct
50 Correct 18 ms 384 KB Output is correct
51 Correct 636 ms 828 KB Output is correct
52 Correct 106 ms 632 KB Output is correct
53 Correct 1206 ms 940 KB Output is correct
54 Correct 1386 ms 1072 KB Output is correct
55 Correct 3 ms 512 KB Output is correct
56 Correct 3 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 1 ms 256 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 1 ms 256 KB Output is correct
21 Correct 0 ms 256 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 3 ms 384 KB Output is correct
28 Correct 11 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 4 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 11 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 3 ms 384 KB Output is correct
37 Correct 4 ms 384 KB Output is correct
38 Correct 3 ms 384 KB Output is correct
39 Correct 4 ms 384 KB Output is correct
40 Correct 29 ms 384 KB Output is correct
41 Correct 36 ms 384 KB Output is correct
42 Correct 28 ms 384 KB Output is correct
43 Correct 24 ms 384 KB Output is correct
44 Correct 18 ms 384 KB Output is correct
45 Correct 16 ms 384 KB Output is correct
46 Correct 9 ms 512 KB Output is correct
47 Correct 212 ms 552 KB Output is correct
48 Correct 5 ms 384 KB Output is correct
49 Correct 20 ms 384 KB Output is correct
50 Correct 18 ms 384 KB Output is correct
51 Correct 636 ms 828 KB Output is correct
52 Correct 106 ms 632 KB Output is correct
53 Correct 1206 ms 940 KB Output is correct
54 Correct 1386 ms 1072 KB Output is correct
55 Correct 3 ms 512 KB Output is correct
56 Correct 3 ms 512 KB Output is correct
57 Correct 34 ms 512 KB Output is correct
58 Correct 556 ms 584 KB Output is correct
59 Correct 553 ms 632 KB Output is correct
60 Correct 8 ms 640 KB Output is correct
61 Correct 355 ms 2040 KB Output is correct
62 Execution timed out 2075 ms 1472 KB Time limit exceeded
63 Halted 0 ms 0 KB -