Submission #425480

# Submission time Handle Problem Language Result Execution time Memory
425480 2021-06-13T05:00:17 Z Kevin_Zhang_TW Sparklers (JOI17_sparklers) C++17
100 / 100
31 ms 2508 KB
#include<bits/stdc++.h>
#define pb emplace_back
#define AI(i) begin(i), end(i)
using namespace std;
using ll = long long;
template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() {cerr << endl;}
template<class T, class ...U> void kout (T v, U ...e) { cerr << v << ' ', kout(e...); }
template<class T> void debug(T L, T R) { while (L != R) cerr << *L << " \n"[next(L)==R], ++L; }
#else
#define DE(...) 0
#define debug(...) 0
#endif
// What I should check
// 1. overflow
// 2. corner cases
// Enjoy the problem instead of hurrying to AC
// Good luck !
const int MAX_N = 100010;
 
const ll inf = 1ll << 55;
 
int n, k, T;
int pos[MAX_N];
 
ll a[MAX_N];

bool valid(ll S) {

	for (int i = 1;i <= n;++i) {
		a[i] = 2 * S * T * i - pos[i];
	}

	int cl = k, cr = k, gl = min_element(a+1, a+1+k) - a, gr = max_element(a+k, a+1+n) - a;

	// a[l] <= a[r] for all time

	ll lv = a[cl], rv = a[cr];

	while (cl > gl || cr < gr) {
		int sl = cl, sr = cr;
		while (cl > gl && a[cl-1] <= rv)
			chmin(lv, a[--cl]);
		while (cr < gr && a[cr+1] >= lv)
			chmax(rv, a[++cr]);
		if (sl == cl && sr == cr) return false;
	}

	lv = a[1], rv = a[n];

	if (lv > rv) return false;

	cl = 1, cr = n;
	while (cl < gl || cr > gr) {
		int sl = cl, sr = cr;
		while (cl < gl && a[cl+1] <= rv)
			chmin(lv, a[++cl]);
		while (cr > gr && a[cr-1] >= lv)
			chmax(rv, a[--cr]);
		if (sl == cl && sr == cr) return false;
	}
	return true;
}
 
int32_t main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n >> k >> T;
	for (int i = 1;i <= n;++i)
		cin >> pos[i];

	//assert(n < MAX_N);
 
	ll L = 0, R = 2 * pos[n], M;
 
	while (L < R) {
		M = L + R >> 1;
		if (valid(M))
			R = M;
		else L = M + 1;
	}
 
	cout << L << '\n';
	
}

Compilation message

sparklers.cpp: In function 'int32_t main()':
sparklers.cpp:79:9: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   79 |   M = L + R >> 1;
      |       ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 312 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 324 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 332 KB Output is correct
28 Correct 2 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 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 332 KB Output is correct
35 Correct 1 ms 288 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 324 KB Output is correct
39 Correct 1 ms 324 KB Output is correct
40 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 312 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 324 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 332 KB Output is correct
28 Correct 2 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 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 332 KB Output is correct
35 Correct 1 ms 288 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 324 KB Output is correct
39 Correct 1 ms 324 KB Output is correct
40 Correct 1 ms 204 KB Output is correct
41 Correct 20 ms 1740 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 6 ms 732 KB Output is correct
44 Correct 28 ms 2416 KB Output is correct
45 Correct 28 ms 2368 KB Output is correct
46 Correct 27 ms 2404 KB Output is correct
47 Correct 27 ms 2388 KB Output is correct
48 Correct 27 ms 2380 KB Output is correct
49 Correct 28 ms 2380 KB Output is correct
50 Correct 29 ms 2340 KB Output is correct
51 Correct 29 ms 2432 KB Output is correct
52 Correct 28 ms 2508 KB Output is correct
53 Correct 28 ms 2380 KB Output is correct
54 Correct 27 ms 2348 KB Output is correct
55 Correct 28 ms 2380 KB Output is correct
56 Correct 27 ms 2416 KB Output is correct
57 Correct 29 ms 2372 KB Output is correct
58 Correct 27 ms 2416 KB Output is correct
59 Correct 8 ms 844 KB Output is correct
60 Correct 29 ms 2340 KB Output is correct
61 Correct 30 ms 2328 KB Output is correct
62 Correct 27 ms 2432 KB Output is correct
63 Correct 27 ms 2380 KB Output is correct
64 Correct 27 ms 2376 KB Output is correct
65 Correct 27 ms 2448 KB Output is correct
66 Correct 27 ms 2380 KB Output is correct
67 Correct 26 ms 2448 KB Output is correct
68 Correct 31 ms 2380 KB Output is correct
69 Correct 26 ms 2408 KB Output is correct