답안 #678784

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
678784 2023-01-06T14:56:51 Z vjudge1 Printed Circuit Board (CEOI12_circuit) C++17
0 / 100
100 ms 25136 KB
#include <bits/stdc++.h> 

#define X first
#define Y second
#define pb push_back

using namespace std; 

typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ld, ld> pdd;

const int N = 1e5 + 10;
const ld INF = 1e13;
const ld DIFF = 1e-7;

int n, on[N];
ld ang = 1;

ld abs2(ld a){
	if(a < 0) return -a;
	return a;
}

bool eq(ld a, ld b){
	return abs2(a - b) <= DIFF;
}

struct line{
	ld a, b;
	bool ver;
	line(ld x1, ld y1, ld x2, ld y2){
		ver = false;
		if(x1 != x2){
			a = (y2 - y1) / (x2 - x1);
			b = y1 - a * x1; 
		} else {
			a = x1;
			b = 0;
			ver = true;	
		}	
	}
};

ld inter(line a){if(a.ver) return a.a; else if(eq(ang, a.a)) return -INF; return a.b / (ang - a.a); }
bool operator< (const line &a, const line &b) { return inter(a) < inter(b); } 

struct dot{
	ld x, y;
	
	dot(){};
	dot(int a, int b){ x = a; y = b; };
	bool operator< (dot b){	return (y / x) > (b.y / b.x) || (eq(y / x, b.y / b.x) && x > b.x); };
};

dot pol[N];

vector<pair<dot, int>> cs;
vector<line> ln;
vector<int> edge[N], ans;

set<line> s;

bool comp(pair<dot, int> a, pair<dot, int> b){ return a.X < b.X; }

void debug(line x){
	printf("(%.3LF, %.3LF) %.3Lf\n", x.a, x.b, inter(x));
}

int main(){
	scanf("%d", &n);
	
	for(int i = 0; i < n; i++){
		ld x, y; 
		scanf("%Lf%Lf", &x, &y);
		cs.pb({dot(x, y), i});		
		pol[i] = dot(x, y);
	}
	
	for(int i = 0; i < n; i++){
		edge[i].pb(ln.size());
		edge[(i + 1) % n].pb(ln.size());
		ln.pb(line(pol[i].x, pol[i].y, pol[(i + 1) % n].x, pol[(i + 1) % n].y));		
	}
	
	sort(cs.begin(), cs.end(), comp);
	
	for(pair<dot, int> par : cs){ 
		dot d = par.X;
		int ind = par.Y;
		
		//printf("%d\n", ind);
		
		ang = d.y / d.x;
		
		for(int i : edge[ind]) 
			if(on[i]){
				s.erase(ln[i]); 
				//if(i == 2) debug(ln[i]);
			}
			
		if(s.empty() || d.x < inter(*s.begin())){ 
			ans.pb(ind);
		}
		
		if(!s.empty() && ind == 7){
			line l = *(s.begin());
			//debug(l);
		}
		
		for(int i : edge[ind]) 
			if(!on[i]){
				s.insert(ln[i]);
				on[i] = 1;
			}	
	}
	
	sort(ans.begin(), ans.end());
	for(int i = 0; i < (int) ans.size(); i++) printf("%d ", ans[i] + 1);
	printf("\n");
	return 0;
}

Compilation message

circuit.cpp: In function 'int main()':
circuit.cpp:107:9: warning: variable 'l' set but not used [-Wunused-but-set-variable]
  107 |    line l = *(s.begin());
      |         ^
circuit.cpp:71:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
circuit.cpp:75:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |   scanf("%Lf%Lf", &x, &y);
      |   ~~~~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 2644 KB Output isn't correct
2 Incorrect 3 ms 2772 KB Output isn't correct
3 Incorrect 5 ms 3248 KB Output isn't correct
4 Incorrect 6 ms 3348 KB Output isn't correct
5 Incorrect 16 ms 4872 KB Output isn't correct
6 Incorrect 20 ms 4836 KB Output isn't correct
7 Incorrect 32 ms 7016 KB Output isn't correct
8 Incorrect 12 ms 4176 KB Output isn't correct
9 Incorrect 15 ms 4632 KB Output isn't correct
10 Incorrect 16 ms 4844 KB Output isn't correct
11 Incorrect 17 ms 5020 KB Output isn't correct
12 Incorrect 23 ms 6960 KB Output isn't correct
13 Incorrect 46 ms 8480 KB Output isn't correct
14 Incorrect 44 ms 11400 KB Output isn't correct
15 Incorrect 60 ms 12788 KB Output isn't correct
16 Execution timed out 121 ms 22904 KB Time limit exceeded
17 Execution timed out 180 ms 23084 KB Time limit exceeded
18 Runtime error 48 ms 24848 KB Execution killed with signal 11
19 Runtime error 47 ms 24964 KB Execution killed with signal 11
20 Runtime error 49 ms 25136 KB Execution killed with signal 11