답안 #100941

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
100941 2019-03-15T10:51:20 Z E869120 The Forest of Fangorn (CEOI14_fangorn) C++14
100 / 100
441 ms 64960 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#pragma warning (disable: 4996)

struct Point {
	long long px, py;
};

int shogen(Point p1) {
	if (p1.py >= 0) return 1;
	return 2;
}

bool operator<(const Point &a1, const Point &a2) {
	int v1 = shogen(a1), v2 = shogen(a2);
	if (v1 < v2) return true;
	if (v1 > v2) return false;

	if (1LL * a1.px*a2.py > 1LL * a1.py*a2.px) return true;
	return false;
}

bool operator==(const Point &a1, const Point &a2) {
	if (a1.px == a2.px && a1.py == a2.py) return true;
	return false;
}

vector<Point>V[2009]; int H, W, sx, sy, N, C, ex[10009], ey[10009]; vector<int>vec;
Point G[2009], candies[2009], library[2009], INF = Point{ 1000000007LL, 1000000007LL };

bool solve(long long cx, long long cy, int ty) {
	for (int i = 1; i <= N; i++) {
		if (ty == 0) {
			int pos1 = lower_bound(V[i].begin(), V[i].end(), Point{ cx - G[i].px, cy - G[i].py }) - V[i].begin();
			vec.push_back(pos1);
		}
		if (ty == 1) {
			Point E = Point{ cx - G[i].px, cy - G[i].py };
			if (candies[i] == INF || library[i] == INF) {
				if (!(V[i][N - 2] < E || E < V[i][0])) return false;
			}
			else {
				if (!(candies[i] < E && E < library[i])) return false;
			}
		}
	}
	return true;
}

int main() {
	scanf("%d%d%d%d%d", &H, &W, &sx, &sy, &C);
	for (int i = 1; i <= C; i++) scanf("%d%d", &ex[i], &ey[i]);
	scanf("%d", &N);
	for (int i = 1; i <= N; i++) scanf("%d%d", &G[i].px, &G[i].py);
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) {
			if (i == j) continue;
			V[i].push_back(Point{ G[i].px - G[j].px, G[i].py - G[j].py });
		}
		sort(V[i].begin(), V[i].end());
	}

	solve(sx, sy, 0);
	for (int i = 1; i <= N; i++) {
		candies[i] = INF; if (vec[i - 1] >= 1) candies[i] = V[i][vec[i - 1] - 1];
		library[i] = INF; if (vec[i - 1] < N - 1) library[i] = V[i][vec[i - 1]];
	}

	vector<int>res;
	for (int i = 1; i <= C; i++) {
		bool vec2 = solve(ex[i], ey[i], 1);
		if (vec2 == true) res.push_back(i);
	}
	printf("%d\n", (int)res.size());
	for (int i = 0; i < res.size(); i++) { if (i) printf(" "); printf("%d", res[i]); }
	if (res.size() != 0) printf("\n");
	return 0;
}

Compilation message

fangorn.cpp:5:0: warning: ignoring #pragma warning  [-Wunknown-pragmas]
 #pragma warning (disable: 4996)
 
fangorn.cpp: In function 'int main()':
fangorn.cpp:56:63: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
  for (int i = 1; i <= N; i++) scanf("%d%d", &G[i].px, &G[i].py);
                                             ~~~~~~~~          ^
fangorn.cpp:56:63: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'long long int*' [-Wformat=]
fangorn.cpp:77:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < res.size(); i++) { if (i) printf(" "); printf("%d", res[i]); }
                  ~~^~~~~~~~~~~~
fangorn.cpp:53:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d%d%d", &H, &W, &sx, &sy, &C);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fangorn.cpp:54:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 1; i <= C; i++) scanf("%d%d", &ex[i], &ey[i]);
                               ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
fangorn.cpp:55:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
fangorn.cpp:56:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 1; i <= N; i++) scanf("%d%d", &G[i].px, &G[i].py);
                               ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 3 ms 640 KB Output is correct
6 Correct 4 ms 896 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 5 ms 1100 KB Output is correct
11 Correct 5 ms 1280 KB Output is correct
12 Correct 6 ms 1280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 100 ms 16460 KB Output is correct
5 Correct 23 ms 4224 KB Output is correct
6 Correct 386 ms 64732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 439 ms 64748 KB Output is correct
2 Correct 441 ms 64960 KB Output is correct
3 Correct 420 ms 64816 KB Output is correct
4 Correct 279 ms 64888 KB Output is correct