# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
59808 |
2018-07-23T07:03:17 Z |
강태규(#1723) |
Sparklers (JOI17_sparklers) |
C++11 |
|
73 ms |
26464 KB |
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>
using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;
int n, k, t;
int x[100001];
const int inf = 1e9 + 7;
llong a[100001];
int check(int s) {
for (int i = 1; i <= n; ++i) {
a[i] = 2ll * i * t * s - x[i];
}
if (a[1] > a[n]) return 0;
pll mx(a[k], k), mn(a[k], k);
for (int i = 1; i <= n; ++i) {
mx = max(mx, pll(a[i], i));
mn = min(mn, pll(a[i], i));
}
if (mn.second > k) return 0;
if (mx.second < k) return 0;
int pl = 0, pr = 0;
llong ml = a[k], mr = a[k];
for (int i = k - 1; i > 0; --i) {
ml = max(ml, a[i]);
if (a[i] <= a[k]) {
pl = i;
break;
}
}
for (int i = k + 1; i <= n; ++i) {
mr = min(mr, a[i]);
if (a[k] <= a[i]) {
pr = i;
break;
}
}
for (int i = k, j = k; pl || pr; ) {
if (pl && ml <= a[j]) {
i = pl;
ml = a[i];
pl = 0;
for (int t = i - 1; t > 0; --t) {
ml = max(ml, a[t]);
if (a[t] <= a[i]) {
pl = t;
break;
}
}
}
else if (pr && a[i] <= mr) {
j = pr;
mr = a[j];
pr = 0;
for (int t = j + 1; t <= n; ++t) {
mr = min(mr, a[t]);
if (a[j] <= a[t]) {
pr = t;
break;
}
}
}
else return 0;
}
pl = 0; pr = 0;
ml = a[1]; mr = a[n];
for (int i = 2; i <= mn.second; ++i) {
ml = max(ml, a[i]);
if (a[i] <= a[1]) {
pl = i;
break;
}
}
for (int i = n - 1; mx.second <= i; --i) {
mr = min(mr, a[i]);
if (a[n] <= a[i]) {
pr = i;
break;
}
}
for (int i = 1, j = n; pl && pr; ) {
if (pl && ml <= a[j]) {
i = pl;
ml = a[i];
pl = 0;
for (int t = i + 1; t <= mn.second; ++t) {
ml = max(ml, a[t]);
if (a[t] <= a[i]) {
pl = t;
break;
}
}
}
else if (pr && a[i] <= mr) {
j = pr;
mr = a[j];
pr = 0;
for (int t = j - 1; mx.second <= t; --t) {
mr = min(mr, a[t]);
if (a[j] <= a[t]) {
pr = t;
break;
}
}
}
else return 0;
}
return 1;
}
int main() {
scanf("%d%d%d", &n, &k, &t);
for (int i = 1; i <= n; ++i) {
scanf("%d", x + i);
}
if (x[n] == 0) {
printf("0\n");
return 0;
}
int s = 1, e = inf / t + 1;
while (s < e) {
int m = (s + e) / 2;
if (check(m)) e = m;
else s = m + 1;
}
printf("%d\n", s);
return 0;
}
Compilation message
sparklers.cpp: In function 'int main()':
sparklers.cpp:129:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &n, &k, &t);
~~~~~^~~~~~~~~~~~~~~~~~~~~~
sparklers.cpp:131:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", x + i);
~~~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
416 KB |
Output is correct |
4 |
Correct |
3 ms |
544 KB |
Output is correct |
5 |
Correct |
2 ms |
544 KB |
Output is correct |
6 |
Correct |
3 ms |
544 KB |
Output is correct |
7 |
Correct |
3 ms |
596 KB |
Output is correct |
8 |
Correct |
3 ms |
596 KB |
Output is correct |
9 |
Correct |
5 ms |
620 KB |
Output is correct |
10 |
Correct |
3 ms |
620 KB |
Output is correct |
11 |
Correct |
3 ms |
620 KB |
Output is correct |
12 |
Correct |
3 ms |
620 KB |
Output is correct |
13 |
Correct |
2 ms |
620 KB |
Output is correct |
14 |
Correct |
2 ms |
744 KB |
Output is correct |
15 |
Correct |
3 ms |
744 KB |
Output is correct |
16 |
Correct |
2 ms |
744 KB |
Output is correct |
17 |
Correct |
3 ms |
744 KB |
Output is correct |
18 |
Correct |
3 ms |
744 KB |
Output is correct |
19 |
Correct |
2 ms |
744 KB |
Output is correct |
20 |
Correct |
3 ms |
744 KB |
Output is correct |
21 |
Correct |
2 ms |
744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
416 KB |
Output is correct |
4 |
Correct |
3 ms |
544 KB |
Output is correct |
5 |
Correct |
2 ms |
544 KB |
Output is correct |
6 |
Correct |
3 ms |
544 KB |
Output is correct |
7 |
Correct |
3 ms |
596 KB |
Output is correct |
8 |
Correct |
3 ms |
596 KB |
Output is correct |
9 |
Correct |
5 ms |
620 KB |
Output is correct |
10 |
Correct |
3 ms |
620 KB |
Output is correct |
11 |
Correct |
3 ms |
620 KB |
Output is correct |
12 |
Correct |
3 ms |
620 KB |
Output is correct |
13 |
Correct |
2 ms |
620 KB |
Output is correct |
14 |
Correct |
2 ms |
744 KB |
Output is correct |
15 |
Correct |
3 ms |
744 KB |
Output is correct |
16 |
Correct |
2 ms |
744 KB |
Output is correct |
17 |
Correct |
3 ms |
744 KB |
Output is correct |
18 |
Correct |
3 ms |
744 KB |
Output is correct |
19 |
Correct |
2 ms |
744 KB |
Output is correct |
20 |
Correct |
3 ms |
744 KB |
Output is correct |
21 |
Correct |
2 ms |
744 KB |
Output is correct |
22 |
Correct |
3 ms |
744 KB |
Output is correct |
23 |
Correct |
3 ms |
744 KB |
Output is correct |
24 |
Correct |
3 ms |
744 KB |
Output is correct |
25 |
Correct |
3 ms |
744 KB |
Output is correct |
26 |
Correct |
3 ms |
744 KB |
Output is correct |
27 |
Correct |
3 ms |
744 KB |
Output is correct |
28 |
Correct |
3 ms |
744 KB |
Output is correct |
29 |
Correct |
4 ms |
744 KB |
Output is correct |
30 |
Correct |
3 ms |
744 KB |
Output is correct |
31 |
Correct |
3 ms |
744 KB |
Output is correct |
32 |
Correct |
4 ms |
744 KB |
Output is correct |
33 |
Correct |
3 ms |
752 KB |
Output is correct |
34 |
Correct |
3 ms |
752 KB |
Output is correct |
35 |
Correct |
5 ms |
752 KB |
Output is correct |
36 |
Correct |
4 ms |
752 KB |
Output is correct |
37 |
Correct |
4 ms |
752 KB |
Output is correct |
38 |
Correct |
4 ms |
752 KB |
Output is correct |
39 |
Correct |
3 ms |
752 KB |
Output is correct |
40 |
Correct |
2 ms |
752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
416 KB |
Output is correct |
4 |
Correct |
3 ms |
544 KB |
Output is correct |
5 |
Correct |
2 ms |
544 KB |
Output is correct |
6 |
Correct |
3 ms |
544 KB |
Output is correct |
7 |
Correct |
3 ms |
596 KB |
Output is correct |
8 |
Correct |
3 ms |
596 KB |
Output is correct |
9 |
Correct |
5 ms |
620 KB |
Output is correct |
10 |
Correct |
3 ms |
620 KB |
Output is correct |
11 |
Correct |
3 ms |
620 KB |
Output is correct |
12 |
Correct |
3 ms |
620 KB |
Output is correct |
13 |
Correct |
2 ms |
620 KB |
Output is correct |
14 |
Correct |
2 ms |
744 KB |
Output is correct |
15 |
Correct |
3 ms |
744 KB |
Output is correct |
16 |
Correct |
2 ms |
744 KB |
Output is correct |
17 |
Correct |
3 ms |
744 KB |
Output is correct |
18 |
Correct |
3 ms |
744 KB |
Output is correct |
19 |
Correct |
2 ms |
744 KB |
Output is correct |
20 |
Correct |
3 ms |
744 KB |
Output is correct |
21 |
Correct |
2 ms |
744 KB |
Output is correct |
22 |
Correct |
3 ms |
744 KB |
Output is correct |
23 |
Correct |
3 ms |
744 KB |
Output is correct |
24 |
Correct |
3 ms |
744 KB |
Output is correct |
25 |
Correct |
3 ms |
744 KB |
Output is correct |
26 |
Correct |
3 ms |
744 KB |
Output is correct |
27 |
Correct |
3 ms |
744 KB |
Output is correct |
28 |
Correct |
3 ms |
744 KB |
Output is correct |
29 |
Correct |
4 ms |
744 KB |
Output is correct |
30 |
Correct |
3 ms |
744 KB |
Output is correct |
31 |
Correct |
3 ms |
744 KB |
Output is correct |
32 |
Correct |
4 ms |
744 KB |
Output is correct |
33 |
Correct |
3 ms |
752 KB |
Output is correct |
34 |
Correct |
3 ms |
752 KB |
Output is correct |
35 |
Correct |
5 ms |
752 KB |
Output is correct |
36 |
Correct |
4 ms |
752 KB |
Output is correct |
37 |
Correct |
4 ms |
752 KB |
Output is correct |
38 |
Correct |
4 ms |
752 KB |
Output is correct |
39 |
Correct |
3 ms |
752 KB |
Output is correct |
40 |
Correct |
2 ms |
752 KB |
Output is correct |
41 |
Correct |
28 ms |
1532 KB |
Output is correct |
42 |
Correct |
4 ms |
1532 KB |
Output is correct |
43 |
Correct |
12 ms |
1532 KB |
Output is correct |
44 |
Correct |
54 ms |
3312 KB |
Output is correct |
45 |
Correct |
50 ms |
4200 KB |
Output is correct |
46 |
Correct |
52 ms |
5112 KB |
Output is correct |
47 |
Correct |
57 ms |
6120 KB |
Output is correct |
48 |
Correct |
48 ms |
7052 KB |
Output is correct |
49 |
Correct |
67 ms |
8028 KB |
Output is correct |
50 |
Correct |
45 ms |
9064 KB |
Output is correct |
51 |
Correct |
73 ms |
9984 KB |
Output is correct |
52 |
Correct |
47 ms |
10952 KB |
Output is correct |
53 |
Correct |
46 ms |
11920 KB |
Output is correct |
54 |
Correct |
48 ms |
12896 KB |
Output is correct |
55 |
Correct |
40 ms |
13848 KB |
Output is correct |
56 |
Correct |
48 ms |
14856 KB |
Output is correct |
57 |
Correct |
46 ms |
15772 KB |
Output is correct |
58 |
Correct |
41 ms |
16728 KB |
Output is correct |
59 |
Correct |
15 ms |
16728 KB |
Output is correct |
60 |
Correct |
43 ms |
17944 KB |
Output is correct |
61 |
Correct |
40 ms |
18848 KB |
Output is correct |
62 |
Correct |
40 ms |
19744 KB |
Output is correct |
63 |
Correct |
53 ms |
20708 KB |
Output is correct |
64 |
Correct |
39 ms |
21796 KB |
Output is correct |
65 |
Correct |
39 ms |
22632 KB |
Output is correct |
66 |
Correct |
40 ms |
23644 KB |
Output is correct |
67 |
Correct |
44 ms |
24520 KB |
Output is correct |
68 |
Correct |
55 ms |
25524 KB |
Output is correct |
69 |
Correct |
43 ms |
26464 KB |
Output is correct |