Submission #732797

# Submission time Handle Problem Language Result Execution time Memory
732797 2023-04-29T10:03:59 Z flappybird None (JOI16_ho_t4) C++17
15 / 100
137 ms 14272 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) {
			ans += K;
			continue;
		}
		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 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 4 ms 1088 KB Output is correct
28 Correct 15 ms 2760 KB Output is correct
29 Correct 48 ms 5692 KB Output is correct
30 Correct 57 ms 10032 KB Output is correct
31 Correct 137 ms 13496 KB Output is correct
32 Correct 81 ms 10516 KB Output is correct
33 Correct 87 ms 10680 KB Output is correct
34 Correct 94 ms 10840 KB Output is correct
35 Correct 76 ms 10688 KB Output is correct
36 Correct 80 ms 10560 KB Output is correct
37 Correct 77 ms 10572 KB Output is correct
38 Correct 85 ms 10568 KB Output is correct
39 Correct 81 ms 10580 KB Output is correct
40 Correct 77 ms 10436 KB Output is correct
41 Correct 76 ms 10388 KB Output is correct
42 Correct 76 ms 10304 KB Output is correct
43 Correct 80 ms 10752 KB Output is correct
44 Correct 86 ms 10620 KB Output is correct
45 Correct 79 ms 10432 KB Output is correct
46 Correct 107 ms 11892 KB Output is correct
47 Correct 104 ms 11968 KB Output is correct
48 Correct 120 ms 14216 KB Output is correct
49 Correct 88 ms 14272 KB Output is correct
50 Correct 84 ms 14180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Incorrect 0 ms 212 KB Output isn't correct
31 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 4 ms 1088 KB Output is correct
28 Correct 15 ms 2760 KB Output is correct
29 Correct 48 ms 5692 KB Output is correct
30 Correct 57 ms 10032 KB Output is correct
31 Correct 137 ms 13496 KB Output is correct
32 Correct 81 ms 10516 KB Output is correct
33 Correct 87 ms 10680 KB Output is correct
34 Correct 94 ms 10840 KB Output is correct
35 Correct 76 ms 10688 KB Output is correct
36 Correct 80 ms 10560 KB Output is correct
37 Correct 77 ms 10572 KB Output is correct
38 Correct 85 ms 10568 KB Output is correct
39 Correct 81 ms 10580 KB Output is correct
40 Correct 77 ms 10436 KB Output is correct
41 Correct 76 ms 10388 KB Output is correct
42 Correct 76 ms 10304 KB Output is correct
43 Correct 80 ms 10752 KB Output is correct
44 Correct 86 ms 10620 KB Output is correct
45 Correct 79 ms 10432 KB Output is correct
46 Correct 107 ms 11892 KB Output is correct
47 Correct 104 ms 11968 KB Output is correct
48 Correct 120 ms 14216 KB Output is correct
49 Correct 88 ms 14272 KB Output is correct
50 Correct 84 ms 14180 KB Output is correct
51 Correct 0 ms 340 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 0 ms 340 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Incorrect 0 ms 212 KB Output isn't correct
56 Halted 0 ms 0 KB -