Submission #724734

# Submission time Handle Problem Language Result Execution time Memory
724734 2023-04-15T19:55:15 Z 406 Sparklers (JOI17_sparklers) C++17
100 / 100
78 ms 4404 KB
#include "bits/stdc++.h"
#define int long long
#define dq deque<int>
using namespace std;
const int N = 1.2e5;
int n, k, t, x[N];
dq L, R;
void ps(dq &v) {
	v.push_front(0);
	for (int i = 1; i < v.size(); i++) v[i] += v[i - 1];
}
array<int, 3> find(const dq &v) {
	int mn = v[0];
	for (int i = 1; i < v.size(); i++) {
		mn = min(mn, v[i]);
		if (v[i] >= v[0]) return {v[i], mn, 1};
	}
	return {0, 0, 0};
}
bool solve(array<dq, 2> v) {
	if (v[0][0] + v[1][0] < 0 || v[1].back() + v[0].back() < 0) return false;
	array<int, 3> A[2];
	A[0] = find(v[0]);
	A[1] = find(v[1]);
	while (v[0].size() > 1 || v[1].size() > 1) {
		bool flag = false;
		for (int k = 0; k < 2; k++) if (A[k][2]) {
			if (v[k ^ 1][0] + A[k][1] >= 0) {
				v[k].pop_front();
				while (v[k][0] != A[k][0]) v[k].pop_front();
				A[k] = find(v[k]);
				flag = true;
			}
		}
		if (flag) continue;
		else if (A[0][2] && A[1][2]) return false;
		if (!A[0][2] && !A[1][2]) {
			for (int k = 0; k < 2; k++) reverse(v[k].begin(), v[k].end());
			return solve(v);
		}
		return false;
	}
	return true;
}
bool check(int O) {
	int s = O * 2 * t;
	dq l = L, r = R;
	for (auto &u: l) u = s - u;
	for (auto &u: r) u = s - u;
	ps(l), ps(r);
	return solve(array<dq, 2>{l, r});
}
signed main() {
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> n >> k >> t, k--;
	for (int i = 0; i < n; i++) cin >> x[i];
	for (int i = 0; i < k; i++) L.push_back(x[i + 1] - x[i]);	
	reverse(L.begin(), L.end());
	for (int i = k + 1; i < n; i++) R.push_back(x[i] - x[i - 1]);
	int l = -1, r = 1ll<<35;
	while (r - l > 1) {
		int m = l + r >> 1;
		if (check(m)) r = m;
		else l = m;
	}
	cout << r << '\n';
	/*
	int l = 0;
	for (int i = 35; i >= 0; i--) if (!check(1ll << i | l)) l |= 1 << i;
	cout << (n != 1) * (l + 1);
	*/
}

Compilation message

sparklers.cpp: In function 'void ps(std::deque<long long int>&)':
sparklers.cpp:10:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::deque<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |  for (int i = 1; i < v.size(); i++) v[i] += v[i - 1];
      |                  ~~^~~~~~~~~~
sparklers.cpp: In function 'std::array<long long int, 3> find(const std::deque<long long int>&)':
sparklers.cpp:14:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::deque<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |  for (int i = 1; i < v.size(); i++) {
      |                  ~~^~~~~~~~~~
sparklers.cpp: In function 'int main()':
sparklers.cpp:62:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   62 |   int m = l + r >> 1;
      |           ~~^~~
# 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 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 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 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 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 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 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 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 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 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 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 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 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 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 53 ms 2436 KB Output is correct
42 Correct 2 ms 340 KB Output is correct
43 Correct 17 ms 876 KB Output is correct
44 Correct 75 ms 3616 KB Output is correct
45 Correct 67 ms 3568 KB Output is correct
46 Correct 71 ms 3584 KB Output is correct
47 Correct 67 ms 3580 KB Output is correct
48 Correct 71 ms 3884 KB Output is correct
49 Correct 78 ms 3584 KB Output is correct
50 Correct 63 ms 3580 KB Output is correct
51 Correct 71 ms 3588 KB Output is correct
52 Correct 66 ms 3576 KB Output is correct
53 Correct 72 ms 3564 KB Output is correct
54 Correct 66 ms 3540 KB Output is correct
55 Correct 66 ms 3872 KB Output is correct
56 Correct 70 ms 3588 KB Output is correct
57 Correct 64 ms 3540 KB Output is correct
58 Correct 71 ms 3660 KB Output is correct
59 Correct 72 ms 3584 KB Output is correct
60 Correct 62 ms 4404 KB Output is correct
61 Correct 67 ms 3588 KB Output is correct
62 Correct 68 ms 3568 KB Output is correct
63 Correct 66 ms 4364 KB Output is correct
64 Correct 63 ms 4312 KB Output is correct
65 Correct 65 ms 4320 KB Output is correct
66 Correct 61 ms 3584 KB Output is correct
67 Correct 66 ms 3564 KB Output is correct
68 Correct 62 ms 4340 KB Output is correct
69 Correct 64 ms 4308 KB Output is correct