Submission #739860

# Submission time Handle Problem Language Result Execution time Memory
739860 2023-05-11T12:36:11 Z blue Sparklers (JOI17_sparklers) C++17
100 / 100
48 ms 2944 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvll = vector<vll>;
using vvi = vector<vi>;

#define sz(x) int(x.size())

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll N, K, T;
	cin >> N >> K >> T;

	vll X(1+N);
	for(int i = 1; i <= N; i++)
	{
		cin >> X[i];
	}



	ll lo = 0, hi = ((((1'000'000'000'000'000'000LL / 2LL + 1) / N) + 1) / T) + 1; 

	// ll lo = 1, hi = 1'000'000'000'000'000'000LL/N;

	// ll lo = 0, hi = 5;
// 

	while(lo != hi)
	{
		// cerr << "\n\n\n\n\n searching " << lo << ' ' << hi << '\n';
		ll mid = (lo + hi)/2;

		// cerr << "mid = " << mid << "\n";

		vll Y(1+N);
		for(ll i = 1; i <= N; i++)
		{
			Y[i] = 2LL * T * mid * i - X[i];
		}

		if(Y[1] > Y[N])
		{
			lo = mid + 1;
			continue;
		}



		int il = K, ir = K;

		// for(int i = 1; i <= N; i++)
		// 	cerr << Y[i] << ' ';
		// cerr << '\n';

		for(int t = 0; 1; t++)
		{
			if(t % 2 == 0)
			{
				int ln = il;

				for(int i = il-1; i >= 1; i--)
				{
					if(Y[i] <= Y[ln])
						ln = i;
					if(Y[i] > Y[ir])
						break;
				}

				if(ln == il && t >= 2)
					break;
				else
					il = ln;
			}
			else
			{
				int rn = ir;

				for(int i = ir+1; i <= N; i++)
				{
					if(Y[i] >= Y[rn])
						rn = i;
					if(Y[i] < Y[il])
						break;
				}

				if(rn == ir && t >= 2)
					break;
				else
					ir = rn;
			}
		}



		int ul = 1, ur = N;

		for(int t = 0; 1; t++)
		{
			if(t % 2 == 0)
			{
				int ln = ul;

				for(int i = ul+1; i <= K; i++)
				{
					if(Y[i] <= Y[ln])
						ln = i;
					if(Y[i] > Y[ur])
						break;
				}

				if(ln == ul && t >= 2)
					break;
				else
					ul = ln;
			}
			else
			{
				int rn = ur;

				for(int i = ur-1; i >= K; i--)
				{
					if(Y[i] >= Y[rn])
						rn = i;
					if(Y[i] < Y[ul])
						break;
				}

				if(rn == ur && t >= 2)
					break;
				else
					ur = rn;
			}
		}

		if(il <= ul && ur <= ir)
			hi = mid;
		else
			lo = mid+1;
	}

	cout << hi << '\n';
}
# 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 0 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 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 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 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 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 0 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 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 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 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 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 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 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 0 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 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 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 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 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 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 28 ms 2008 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 9 ms 916 KB Output is correct
44 Correct 36 ms 2764 KB Output is correct
45 Correct 48 ms 2764 KB Output is correct
46 Correct 42 ms 2764 KB Output is correct
47 Correct 43 ms 2768 KB Output is correct
48 Correct 42 ms 2764 KB Output is correct
49 Correct 44 ms 2848 KB Output is correct
50 Correct 46 ms 2900 KB Output is correct
51 Correct 40 ms 2764 KB Output is correct
52 Correct 48 ms 2860 KB Output is correct
53 Correct 38 ms 2772 KB Output is correct
54 Correct 48 ms 2772 KB Output is correct
55 Correct 47 ms 2892 KB Output is correct
56 Correct 39 ms 2772 KB Output is correct
57 Correct 48 ms 2836 KB Output is correct
58 Correct 43 ms 2772 KB Output is correct
59 Correct 42 ms 2004 KB Output is correct
60 Correct 42 ms 2768 KB Output is correct
61 Correct 45 ms 2772 KB Output is correct
62 Correct 39 ms 2772 KB Output is correct
63 Correct 43 ms 2772 KB Output is correct
64 Correct 41 ms 2772 KB Output is correct
65 Correct 40 ms 2776 KB Output is correct
66 Correct 43 ms 2768 KB Output is correct
67 Correct 38 ms 2772 KB Output is correct
68 Correct 45 ms 2772 KB Output is correct
69 Correct 45 ms 2944 KB Output is correct