답안 #113804

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
113804 2019-05-28T13:04:17 Z aminra Sparklers (JOI17_sparklers) C++14
100 / 100
193 ms 6524 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MOD = (int)1e9 + 7;
const int MAXN = (int)1e5 + 3;
const int infint = (int)1e9 + 3;
const ll inf = (ll)2e18;
int n, k, t;
int X[MAXN];
 
bool make(vector < ld > x, vector < ld > y)
{
	if (x[0] < y[0])
		return 0;
  	int ok = 1;
  	pair<int, int> L, R;
  	L = {0, 0};
  	R = {0, 0};
  	while (ok)
  	{
    	ok = 0;
    	while (L.first + 1 < x.size() && x[L.first + 1] >= y[R.second])
		{
      		ok = 1;
      		if (x[++L.first] > x[L.second])
			  	L.second = L.first;
    	}
		while (R.first + 1 < y.size() && y[R.first + 1] <= x[L.second])
		{
      		ok = 1;
      		if (y[++R.first] < y[R.second])
				R.second = R.first;
    	}
  	}
  	return L.first + 1 == x.size() && R.first + 1 == y.size();
}
 
bool check(int s)
{
	vector <ld> x, y;
	for (ll i = k; i >= 0; i--)
    	x.push_back(X[i] - (ld)2 * s * t * i);
  	for (ll i = k; i < n; i++)
    	y.push_back(X[i] - (ld)2 * s * t * i);
  	if (!make(x, y)) 
		return 0;
  	reverse(x.begin(), x.end());
  	reverse(y.begin(), y.end());
  	if (!make(x, y))
		return 0;
	return 1;
}
 
int main() 
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> n >> k >> t;
	k--;
	for (ll i = 0; i < n; i++)
    cin >> X[i];
  	int L = 0, R = infint;
  	while (L < R)
  	{
		ll mid = (L + R) >> 1;
    	if (check(mid))
      		R = mid;
    	else
      		L = mid + 1;
    }
	cout << L;
}

Compilation message

sparklers.cpp: In function 'bool make(std::vector<long double>, std::vector<long double>)':
sparklers.cpp:23:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
      while (L.first + 1 < x.size() && x[L.first + 1] >= y[R.second])
             ~~~~~~~~~~~~^~~~~~~~~~
sparklers.cpp:29:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while (R.first + 1 < y.size() && y[R.first + 1] <= x[L.second])
          ~~~~~~~~~~~~^~~~~~~~~~
sparklers.cpp:36:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    return L.first + 1 == x.size() && R.first + 1 == y.size();
           ~~~~~~~~~~~~^~~~~~~~~~~
sparklers.cpp:36:50: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    return L.first + 1 == x.size() && R.first + 1 == y.size();
                                      ~~~~~~~~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 4 ms 512 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 4 ms 512 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 3 ms 384 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 3 ms 384 KB Output is correct
27 Correct 26 ms 384 KB Output is correct
28 Correct 3 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 3 ms 384 KB Output is correct
31 Correct 3 ms 384 KB Output is correct
32 Correct 3 ms 384 KB Output is correct
33 Correct 3 ms 384 KB Output is correct
34 Correct 3 ms 384 KB Output is correct
35 Correct 3 ms 384 KB Output is correct
36 Correct 3 ms 384 KB Output is correct
37 Correct 4 ms 384 KB Output is correct
38 Correct 3 ms 384 KB Output is correct
39 Correct 3 ms 384 KB Output is correct
40 Correct 3 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 4 ms 512 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 3 ms 384 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 3 ms 384 KB Output is correct
27 Correct 26 ms 384 KB Output is correct
28 Correct 3 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 3 ms 384 KB Output is correct
31 Correct 3 ms 384 KB Output is correct
32 Correct 3 ms 384 KB Output is correct
33 Correct 3 ms 384 KB Output is correct
34 Correct 3 ms 384 KB Output is correct
35 Correct 3 ms 384 KB Output is correct
36 Correct 3 ms 384 KB Output is correct
37 Correct 4 ms 384 KB Output is correct
38 Correct 3 ms 384 KB Output is correct
39 Correct 3 ms 384 KB Output is correct
40 Correct 3 ms 384 KB Output is correct
41 Correct 90 ms 3956 KB Output is correct
42 Correct 5 ms 568 KB Output is correct
43 Correct 25 ms 1344 KB Output is correct
44 Correct 132 ms 5456 KB Output is correct
45 Correct 138 ms 5376 KB Output is correct
46 Correct 139 ms 5528 KB Output is correct
47 Correct 149 ms 5464 KB Output is correct
48 Correct 130 ms 5044 KB Output is correct
49 Correct 130 ms 5452 KB Output is correct
50 Correct 130 ms 5176 KB Output is correct
51 Correct 146 ms 5636 KB Output is correct
52 Correct 166 ms 6248 KB Output is correct
53 Correct 152 ms 5636 KB Output is correct
54 Correct 165 ms 6360 KB Output is correct
55 Correct 134 ms 5396 KB Output is correct
56 Correct 140 ms 5568 KB Output is correct
57 Correct 134 ms 5308 KB Output is correct
58 Correct 133 ms 5052 KB Output is correct
59 Correct 146 ms 4552 KB Output is correct
60 Correct 165 ms 6492 KB Output is correct
61 Correct 157 ms 6020 KB Output is correct
62 Correct 133 ms 5592 KB Output is correct
63 Correct 155 ms 6120 KB Output is correct
64 Correct 139 ms 5436 KB Output is correct
65 Correct 139 ms 5064 KB Output is correct
66 Correct 141 ms 5212 KB Output is correct
67 Correct 131 ms 4984 KB Output is correct
68 Correct 193 ms 6524 KB Output is correct
69 Correct 149 ms 6388 KB Output is correct