Submission #388363

# Submission time Handle Problem Language Result Execution time Memory
388363 2021-04-11T05:51:05 Z abra_stone None (KOI18_footprint) C++14
100 / 100
1728 ms 185668 KB
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#define N 3005
using namespace std;

typedef long long ll;
struct st{
	ll x, y, id;
} o, a[N];
ll n, ans, d1[N][N], d2[N][N], h1[N][N], h2[N][N];
vector<st> lt, rt;

ll ccw(st p, st q, st r) {
	return p.x * q.y + q.x * r.y + r.x * p.y - q.x * p.y - r.x * q.y - p.x * r.y;
}

bool cmp(st p, st q) {return ccw(o, p, q) > 0;}

bool cmpmn(st p, st q) {
	if (p.y != q.y) return p.y < q.y;
	else return p.x < q.x;
}

void print(ll p, ll q, ll r) {
	if (p == 0) {printf("%lld %lld\n", a[p].x, a[p].y); return;}
	if (r == 1) print(q, h1[p][q], 2);
	else print(q, h2[p][q], 1);
	printf("%lld %lld\n", a[p].x, a[p].y);
}

int main()
{
	ll i, j, k;
	cin >> n;
	for (i = 0; i < n; i++) {
		scanf("%lld %lld", &a[i].x, &a[i].y);
	}
	sort(a, a + n, cmpmn);
	o = a[0];
	sort(a + 1, a + n, cmp);
	for (i = 0; i < n; i++) a[i].id = i;

	for (i = 1; i < n; i++) d1[i][0] = 2;
	for (i = 1; i < n; i++) {
		lt.clear(); rt.clear();
		rt.push_back(a[0]);
		for (j = 1; j < i; j++) if (ccw(a[0], a[i], a[j])) rt.push_back(a[j]);
		for (j = i + 1; j < n; j++) if (ccw(a[0], a[i], a[j])) lt.push_back(a[j]);
		o = a[i];
		sort(lt.begin(), lt.end(), cmp);
		sort(rt.begin(), rt.end(), cmp);

		ll mx = -1e9, mi = 0;
		ll I = a[i].id;
		for (j = 0, k = 0; j < lt.size(); j++) {
			ll J = lt[j].id;
			for (; k < rt.size(); k++) {
				ll K = rt[k].id;
				if (ccw(rt[k], a[i], lt[j]) <= 0) break;
				if (d1[I][K] + 1 > mx) mx = d1[I][K] + 1, mi = K;
			}
			d2[J][I] = mx;
			h2[J][I] = mi;
		}
		mx = -1e9, mi = 0;
		for (j = (ll)lt.size() - 1, k = (ll)rt.size() - 1; j >= 0; j--) {
			ll J = lt[j].id;
			for (; k >= 0; k--) {
				ll K = rt[k].id;
				if (ccw(rt[k], a[i], lt[j]) >= 0) break;
				if (d2[I][K] + 1 > mx) mx = d2[I][K] + 1, mi = K;
			}
			d1[J][I] = mx;
			h1[J][I] = mi;
		}
	}
	for (i = 0; i < n; i++) for (j = 0; j < i; j++) ans = max(ans, d1[i][j]);
	if (ans <= 3) {cout << '0'; return 0;}
    cout << ans << endl;
    for (i = 0; i < n; i++) for (j = 0; j < i; j++) if (d1[i][j] == ans) {print(i, j, 1); return 0;}
    return 0;
}

Compilation message

footprint.cpp: In function 'int main()':
footprint.cpp:57:24: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<st>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |   for (j = 0, k = 0; j < lt.size(); j++) {
      |                      ~~^~~~~~~~~~~
footprint.cpp:59:13: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<st>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |    for (; k < rt.size(); k++) {
      |           ~~^~~~~~~~~~~
footprint.cpp:38:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   38 |   scanf("%lld %lld", &a[i].x, &a[i].y);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1426 ms 160548 KB Output is correct
2 Correct 1489 ms 165408 KB Output is correct
3 Correct 1439 ms 162800 KB Output is correct
4 Correct 1443 ms 165608 KB Output is correct
5 Correct 1445 ms 163860 KB Output is correct
6 Correct 1456 ms 165564 KB Output is correct
7 Correct 1446 ms 164484 KB Output is correct
8 Correct 1435 ms 165952 KB Output is correct
9 Correct 1503 ms 166644 KB Output is correct
10 Correct 1443 ms 165944 KB Output is correct
11 Correct 1467 ms 166004 KB Output is correct
12 Correct 1480 ms 166972 KB Output is correct
13 Correct 1483 ms 169836 KB Output is correct
14 Correct 1453 ms 165808 KB Output is correct
15 Correct 1434 ms 163264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 464 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 432 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 464 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 432 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 12 ms 6036 KB Output is correct
22 Correct 12 ms 6040 KB Output is correct
23 Correct 12 ms 5944 KB Output is correct
24 Correct 15 ms 6572 KB Output is correct
25 Correct 15 ms 6476 KB Output is correct
26 Correct 14 ms 6476 KB Output is correct
27 Correct 14 ms 6476 KB Output is correct
28 Correct 14 ms 6476 KB Output is correct
29 Correct 14 ms 6460 KB Output is correct
30 Correct 14 ms 6476 KB Output is correct
31 Correct 14 ms 6476 KB Output is correct
32 Correct 15 ms 6528 KB Output is correct
33 Correct 10 ms 6532 KB Output is correct
34 Correct 10 ms 6476 KB Output is correct
35 Correct 10 ms 6476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1426 ms 160548 KB Output is correct
2 Correct 1489 ms 165408 KB Output is correct
3 Correct 1439 ms 162800 KB Output is correct
4 Correct 1443 ms 165608 KB Output is correct
5 Correct 1445 ms 163860 KB Output is correct
6 Correct 1456 ms 165564 KB Output is correct
7 Correct 1446 ms 164484 KB Output is correct
8 Correct 1435 ms 165952 KB Output is correct
9 Correct 1503 ms 166644 KB Output is correct
10 Correct 1443 ms 165944 KB Output is correct
11 Correct 1467 ms 166004 KB Output is correct
12 Correct 1480 ms 166972 KB Output is correct
13 Correct 1483 ms 169836 KB Output is correct
14 Correct 1453 ms 165808 KB Output is correct
15 Correct 1434 ms 163264 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 0 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 460 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 464 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 432 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 460 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 12 ms 6036 KB Output is correct
37 Correct 12 ms 6040 KB Output is correct
38 Correct 12 ms 5944 KB Output is correct
39 Correct 15 ms 6572 KB Output is correct
40 Correct 15 ms 6476 KB Output is correct
41 Correct 14 ms 6476 KB Output is correct
42 Correct 14 ms 6476 KB Output is correct
43 Correct 14 ms 6476 KB Output is correct
44 Correct 14 ms 6460 KB Output is correct
45 Correct 14 ms 6476 KB Output is correct
46 Correct 14 ms 6476 KB Output is correct
47 Correct 15 ms 6528 KB Output is correct
48 Correct 10 ms 6532 KB Output is correct
49 Correct 10 ms 6476 KB Output is correct
50 Correct 10 ms 6476 KB Output is correct
51 Correct 1435 ms 165364 KB Output is correct
52 Correct 1440 ms 165876 KB Output is correct
53 Correct 1478 ms 169372 KB Output is correct
54 Correct 1691 ms 185596 KB Output is correct
55 Correct 1713 ms 185660 KB Output is correct
56 Correct 1712 ms 185596 KB Output is correct
57 Correct 1696 ms 185416 KB Output is correct
58 Correct 1728 ms 185468 KB Output is correct
59 Correct 1689 ms 185420 KB Output is correct
60 Correct 1646 ms 185668 KB Output is correct
61 Correct 1713 ms 185668 KB Output is correct
62 Correct 1650 ms 185624 KB Output is correct
63 Correct 1122 ms 185664 KB Output is correct
64 Correct 1109 ms 185508 KB Output is correct
65 Correct 1101 ms 185528 KB Output is correct
66 Correct 1406 ms 185280 KB Output is correct
67 Correct 1405 ms 185520 KB Output is correct
68 Correct 1392 ms 185308 KB Output is correct