Submission #732807

# Submission time Handle Problem Language Result Execution time Memory
732807 2023-04-29T10:11:21 Z flappybird None (JOI16_ho_t4) C++17
100 / 100
554 ms 38152 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define MAX 201010
#define MAXS 20
#define INF 1000000000000000001
#define bb ' '
#define ln '\n'
#define Ln '\n'
pii arr[MAX];
int fdiv(int x, int y) {
	if (!y) return 0;
	if (x % y == 0) return x / y;
	if (x < 0) return x / y - 1;
	return x / y;
}
int fmod(int x, int y) {
	if (!y) return x;
	x %= y;
	x += y;
	x %= y;
	return x;
}
bool valid(vector<pii>& v, pii p) {
	int ind = lower_bound(v.begin(), v.end(), p) - v.begin();
	if (ind >= v.size()) return false;
	return v[ind] == p;
}
bool exist(set<pii>& st, pii p) {
	return st.find(p) != st.end();
}
int chkv[3][3];
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	int N, K;
	cin >> N >> K;
	int i;
	string s;
	cin >> s;
	for (i = 1; i <= N; i++) {
		arr[i] = arr[i - 1];
		if (s[i - 1] == 'N') arr[i].first++;
		if (s[i - 1] == 'S') arr[i].first--;
		if (s[i - 1] == 'E') arr[i].second++;
		if (s[i - 1] == 'W') arr[i].second--;
	}
	if (arr[N].first > 0) for (i = 1; i <= N; i++) arr[i].first *= -1;
	if (arr[N].second > 0) for (i = 1; i <= N; i++) arr[i].second *= -1;
	vector<pii> v;
	set<pii> real;
	for (i = 1; i <= N; i++) real.insert(arr[i]);
	int X, Y;
	X = -arr[N].first;
	Y = -arr[N].second;
	if (!X && !Y) K = 1;
	if (K == 1) {
		for (i = 0; i <= N; i++) {
			int a, b;
			for (a = arr[i].first - 1; a <= arr[i].first + 1; a++) for (b = arr[i].second - 1; b <= arr[i].second + 1; b++) v.emplace_back(a, b);
		}
		sort(v.begin(), v.end());
		v.erase(unique(v.begin(), v.end()), v.end());
		int ans = 0;
		real.emplace(0, 0);
		for (auto& [x, y] : v) {
			if (exist(real, pii(x, y)) && exist(real, pii(x, y + 1)) && exist(real, pii(x + 1, y)) && exist(real, pii(x + 1, y + 1))) ans++;
		}
		cout << ans << ln;
		return 0;
	}
	for (i = 1; i <= N; i++) {
		int a, b;
		for (a = arr[i].first - 1; a <= arr[i].first + 1; a++) for (b = arr[i].second - 1; b <= arr[i].second + 1; b++) v.emplace_back(a, b);
	}
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());
	map<tuple<int, int, int>, int> chk;
	map<pii, int> mp;
	for (auto& [x, y] : v) {
		auto t = make_tuple(fmod(x, X), fmod(y, Y), fdiv(x, X) - fdiv(y, Y));
		if (!X) t = make_tuple(fmod(x, X), fmod(y, Y), 0);
		if (!Y) t = make_tuple(fmod(x, X), fmod(y, Y), 0);
		int res = -1;
		int v;
		if (!Y) v = fdiv(x, X);
		else v = fdiv(y, Y);
		if (chk.find(t) != chk.end()) res = v - chk[t];
		mp[pii(x, y)] = res;
		if (exist(real, pii(x, y))) chk[t] = v;
	}
	ll ans = 0;
	for (auto& [x, y] : v) {
		int mx0, mx1;
		mx0 = mx1 = -1;
		int c = 1;
		int cnt = 0;
		int r = 0;
		for (auto xx : { x, x + 1 }) {
			for (auto yy : { y, y + 1 }) {
				if (real.find(pii(xx, yy)) != real.end()) {
					cnt++;
					if (!~mp[pii(xx, yy)]) r = 1;
					mx1 = max(mx1, mp[pii(xx, yy)]);
				}
				else {
					if (!~mp[pii(xx, yy)]) {
						c = 0;
						break;
					}
					mx0 = max(mx0, mp[pii(xx, yy)]);
				}
				if (!valid(v, pii(xx, yy))) {
					c = 0;
					break;
				}
			}
			if (!c) break;
		}
		if (!c) continue;
		if (!cnt) continue;
		if (cnt == 4) mx0 = 0;
		if (r) mx1 = K;
		if (!~mx0 && cnt < 4) continue;
		mx1 = min(K, mx1);
		ans += max(0, mx1 - mx0);
	}
	auto findmin = [&](int x, int y) {
		int mn = K;
		for (int t = 1; t <= N; t++) {
			int dx = arr[t].first - x;
			int dy = arr[t].second - y;
			if (!X && dx) continue;
			if (!Y && dy) continue;
			if ((!X || dx % X == 0) && (!Y || dy % Y == 0)) {
				int t1, t2;
				t1 = t2 = -1;
				if (dx < 0 || dy < 0) continue;
				if (X) t1 = dx / X;
				if (Y) t2 = dy / Y;
				if (!~t1) t1 = t2;
				if (!~t2) t2 = t1;
				if (t1 == t2) mn = min(mn, t1);
			}
		}
		return mn;
	};
	int j;
	if (findmin(0, 0) >= K) {
		for (i = -1; i <= 1; i++) for (j = -1; j <= 1; j++) {
			chkv[i + 1][j + 1] = findmin(i, j);
		}
		if (chkv[0][0] < K && chkv[0][1] < K && chkv[1][0] < K) ans++;
		if (chkv[1][0] < K && chkv[2][0] < K && chkv[2][1] < K) ans++;
		if (chkv[0][1] < K && chkv[0][2] < K && chkv[1][2] < K) ans++;
		if (chkv[2][2] < K && chkv[2][1] < K && chkv[1][2] < K) ans++;
	}
	cout << ans << ln;
}

Compilation message

2016_ho_t4.cpp: In function 'bool valid(std::vector<std::pair<int, int> >&, pii)':
2016_ho_t4.cpp:32:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |  if (ind >= v.size()) return false;
      |      ~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 336 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 336 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 5 ms 1096 KB Output is correct
28 Correct 14 ms 2760 KB Output is correct
29 Correct 43 ms 5700 KB Output is correct
30 Correct 57 ms 10052 KB Output is correct
31 Correct 126 ms 13508 KB Output is correct
32 Correct 75 ms 10556 KB Output is correct
33 Correct 73 ms 10732 KB Output is correct
34 Correct 87 ms 10816 KB Output is correct
35 Correct 81 ms 10736 KB Output is correct
36 Correct 80 ms 10632 KB Output is correct
37 Correct 80 ms 10692 KB Output is correct
38 Correct 77 ms 10680 KB Output is correct
39 Correct 89 ms 10680 KB Output is correct
40 Correct 76 ms 10568 KB Output is correct
41 Correct 76 ms 10568 KB Output is correct
42 Correct 84 ms 10340 KB Output is correct
43 Correct 81 ms 10884 KB Output is correct
44 Correct 77 ms 10696 KB Output is correct
45 Correct 77 ms 10540 KB Output is correct
46 Correct 110 ms 11932 KB Output is correct
47 Correct 98 ms 11956 KB Output is correct
48 Correct 115 ms 14244 KB Output is correct
49 Correct 83 ms 14256 KB Output is correct
50 Correct 86 ms 14264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 336 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 428 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 336 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 0 ms 336 KB Output is correct
42 Correct 1 ms 336 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 332 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 336 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 5 ms 1096 KB Output is correct
28 Correct 14 ms 2760 KB Output is correct
29 Correct 43 ms 5700 KB Output is correct
30 Correct 57 ms 10052 KB Output is correct
31 Correct 126 ms 13508 KB Output is correct
32 Correct 75 ms 10556 KB Output is correct
33 Correct 73 ms 10732 KB Output is correct
34 Correct 87 ms 10816 KB Output is correct
35 Correct 81 ms 10736 KB Output is correct
36 Correct 80 ms 10632 KB Output is correct
37 Correct 80 ms 10692 KB Output is correct
38 Correct 77 ms 10680 KB Output is correct
39 Correct 89 ms 10680 KB Output is correct
40 Correct 76 ms 10568 KB Output is correct
41 Correct 76 ms 10568 KB Output is correct
42 Correct 84 ms 10340 KB Output is correct
43 Correct 81 ms 10884 KB Output is correct
44 Correct 77 ms 10696 KB Output is correct
45 Correct 77 ms 10540 KB Output is correct
46 Correct 110 ms 11932 KB Output is correct
47 Correct 98 ms 11956 KB Output is correct
48 Correct 115 ms 14244 KB Output is correct
49 Correct 83 ms 14256 KB Output is correct
50 Correct 86 ms 14264 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 1 ms 332 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Correct 1 ms 332 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 1 ms 428 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 1 ms 340 KB Output is correct
62 Correct 1 ms 336 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 1 ms 336 KB Output is correct
65 Correct 1 ms 340 KB Output is correct
66 Correct 0 ms 336 KB Output is correct
67 Correct 1 ms 336 KB Output is correct
68 Correct 1 ms 340 KB Output is correct
69 Correct 1 ms 332 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 1 ms 340 KB Output is correct
73 Correct 1 ms 340 KB Output is correct
74 Correct 1 ms 340 KB Output is correct
75 Correct 1 ms 468 KB Output is correct
76 Correct 10 ms 1612 KB Output is correct
77 Correct 8 ms 1620 KB Output is correct
78 Correct 73 ms 7800 KB Output is correct
79 Correct 144 ms 18728 KB Output is correct
80 Correct 89 ms 10336 KB Output is correct
81 Correct 81 ms 10796 KB Output is correct
82 Correct 106 ms 12404 KB Output is correct
83 Correct 92 ms 10608 KB Output is correct
84 Correct 109 ms 12800 KB Output is correct
85 Correct 104 ms 12872 KB Output is correct
86 Correct 554 ms 38152 KB Output is correct
87 Correct 116 ms 13916 KB Output is correct
88 Correct 104 ms 12120 KB Output is correct
89 Correct 120 ms 12624 KB Output is correct
90 Correct 84 ms 10816 KB Output is correct
91 Correct 109 ms 13200 KB Output is correct
92 Correct 110 ms 13236 KB Output is correct
93 Correct 109 ms 13656 KB Output is correct
94 Correct 115 ms 11456 KB Output is correct
95 Correct 103 ms 11988 KB Output is correct
96 Correct 307 ms 24672 KB Output is correct
97 Correct 296 ms 26276 KB Output is correct
98 Correct 369 ms 28604 KB Output is correct
99 Correct 278 ms 38052 KB Output is correct
100 Correct 490 ms 34876 KB Output is correct