Submission #114082

# Submission time Handle Problem Language Result Execution time Memory
114082 2019-05-30T02:13:05 Z dndhk The Forest of Fangorn (CEOI14_fangorn) C++14
100 / 100
593 ms 896 KB
#include <bits/stdc++.h>

#define pb push_back
#define all(v) ((v).begin(), (v).end())
#define sortv(v) sort(all(v))
#define sz(v) ((int)(v).size())
#define uniqv(v) (v).erase(unique(all(v)), (v).end())
#define umax(a, b) (a)=max((a), (b))
#define umin(a, b) (a)=min((a), (b))
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define rep(i,n) FOR(i,1,n)
#define rep0(i,n) FOR(i,0,(int)(n)-1)
#define FI first
#define SE second
#define INF 2000000000
#define INFLL 1000000000000000000LL


using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAX_C = 10000;

ll ccw(pll a, pll b){
	return a.first*b.second-a.second*b.first;
}

bool cmp(pll a, pll b){
	if((a>(pll){0, 0}) ^ (b>(pll){0, 0}))	return (a>(pll){0, 0});
	if(ccw(a, b)!=0)	return (ccw(a, b)>0);
	return false;
}

int cmp2(pll a, pll b){
	if((a>(pll){0, 0}) ^ (b>(pll){0, 0}))	return (a>(pll){0, 0})?1:-1;
	if(ccw(a, b)!=0)	return (ccw(a, b)>0)?1:-1;
	return 0;
}

int N, C;
ll W, H;
vector<pll> camp, tree, vt;
bool tf[MAX_C+1];

int main(){
	scanf("%lld%lld", &W, &H);
	pll p;
	scanf("%lld%lld", &p.first, &p.second); camp.pb(p);
	scanf("%d", &C);
	for(int i=0; i<C; i++){
		tf[i+1] = true;
		scanf("%lld%lld", &p.first, &p.second); camp.pb(p);
	}
	scanf("%d", &N);
	for(int i=0; i<N; i++){
		scanf("%lld%lld", &p.first, &p.second); tree.pb(p);
	}
	for(int i=0; i<N; i++){
		vt.clear();
		for(int j=0; j<N; j++){
			if(i!=j){
				vt.pb({tree[i].first-tree[j].first, tree[i].second-tree[j].second});
			}
		}
		sort(vt.begin(), vt.end(), cmp);
		/*for(int i=0; i<vt.size(); i++){
			printf("%lld %lld\n", vt[i].first, vt[i].second);
		}*/
		int idx=-1;
		for(int j=0; j<vt.size(); j++){
			if(!cmp({camp[0].first-tree[i].first, camp[0].second-tree[i].second} , vt[j])){
				idx = j;
			}
		}
		//cout<<idx<<endl<<endl;
		if(idx==-1 || idx==vt.size()-1){
			for(int j=1; j<=C; j++){
				if(!(cmp2({camp[j].first-tree[i].first, camp[j].second-tree[i].second}, vt[0])==1 || cmp2({camp[j].first-tree[i].first, camp[j].second-tree[i].second}, vt.back())==-1)){
					tf[j] = false;
				}
			}
		}else{
			for(int j=1; j<=C; j++){
				if(!(cmp2({camp[j].first-tree[i].first, camp[j].second-tree[i].second}, vt[idx])==-1 && cmp2({camp[j].first-tree[i].first, camp[j].second-tree[i].second}, vt[idx+1])==1)){
					tf[j] = false;
				}
			}
		}
	}
	int ans = 0;
	for(int i=1; i<=C; i++){
		if(tf[i])	ans++;
	}
	printf("%d\n", ans);
	for(int i=1; i<=C; i++){
		if(tf[i])	printf("%d ", i);
	}
	return 0;
}

Compilation message

fangorn.cpp: In function 'int main()':
fangorn.cpp:72:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0; j<vt.size(); j++){
                ~^~~~~~~~~~
fangorn.cpp:78:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(idx==-1 || idx==vt.size()-1){
                 ~~~^~~~~~~~~~~~~
fangorn.cpp:48:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld", &W, &H);
  ~~~~~^~~~~~~~~~~~~~~~~~~~
fangorn.cpp:50:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld", &p.first, &p.second); camp.pb(p);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fangorn.cpp:51:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &C);
  ~~~~~^~~~~~~~~~
fangorn.cpp:54:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld", &p.first, &p.second); camp.pb(p);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fangorn.cpp:56:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
fangorn.cpp:58:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld", &p.first, &p.second); tree.pb(p);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 432 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 7 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 4 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 90 ms 408 KB Output is correct
5 Correct 20 ms 384 KB Output is correct
6 Correct 426 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 420 ms 564 KB Output is correct
2 Correct 537 ms 896 KB Output is correct
3 Correct 593 ms 896 KB Output is correct
4 Correct 328 ms 768 KB Output is correct