답안 #60003

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
60003 2018-07-23T12:02:16 Z ainta(#1720) Sparklers (JOI17_sparklers) C++11
100 / 100
69 ms 6564 KB
#include<cstdio>
#include<algorithm>
#define N_ 101000
using namespace std;
int n, st, n1, n2, D[N_];
long long T, INF = 1e9, X[N_];
long long A[N_], B[N_], AA[N_], BB[N_];
struct point {
	int pv;
	long long Mn, Mx;
}w[N_];
bool Do() {
	int i, cnt = 0;
	n1--, n2--;
	long long Mx = -4e18, Mn = 4e18;
	for (i = 0; i <= n2; i++) {
		Mn = min(Mn, B[i]);
		if (Mx <= B[i]) {
			Mx = B[i];
			w[cnt++] = { i,Mn,Mx };
			Mn = B[i];
		}
	}
	for (i = 0; i < cnt; i++) {
		if (w[i].Mn + A[0] < 0)break;
	}
	D[0] = i - 1;
	if (D[0] == -1)return false;
	for (i = 1; i <= n1; i++) {
		if (w[D[i - 1]].Mx + A[i] < 0)return false;
		int pv = D[i - 1];
		while (pv < cnt - 1 && w[pv + 1].Mn + A[i] >= 0)pv++;
		D[i] = pv;
	}
	return w[D[n1]].pv == n2;
}
bool Pos(long long KK) {
	long long L = T*KK;
	if (L >= 1e9)return true;
	int i, j;
	for (i = st; i >= 1; i--) {
		AA[i] = X[i] + L * 2 * (st - i);
	}
	for (i = st; i <= n; i++) {
		BB[i] = -(X[i] - L * 2 * (i - st));
	}
	int pv1 = st, pv2 = st;

	for (i = st; i >= 1; i--) if (AA[pv1] < AA[i])pv1 = i;
	for (i = st; i <= n; i++) if (BB[pv2] < BB[i])pv2 = i;
	n1 = 0, n2 = 0;
	for (i = st; i >= pv1; i--)  A[n1++] = AA[i];
	for (i = st; i <= pv2; i++)  B[n2++] = BB[i];
	if (!Do())return false;

	n1 = 0, n2 = 0;
	for (i = 1; i <= pv1; i++)  A[n1++] = AA[i];
	for (i = n; i >= pv2; i--)  B[n2++] = BB[i];
	if (!Do())return false;
	return true;

}
int main() {
	int i;
	scanf("%d%d%lld", &n, &st, &T);
	for (i = 1; i <= n; i++) {
		scanf("%lld", &X[i]);
	}
	long long b = 0, e = 1e9, mid, res;
	while (b <= e) {
		mid = (b + e) / 2;
		if (Pos(mid)) {
			res = mid;
			e = mid - 1;
		}
		else b = mid + 1;
	}
	printf("%d\n", res);
}

Compilation message

sparklers.cpp: In function 'bool Pos(long long int)':
sparklers.cpp:40:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j;
         ^
sparklers.cpp: In function 'int main()':
sparklers.cpp:78:20: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
  printf("%d\n", res);
                    ^
sparklers.cpp:65:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%lld", &n, &st, &T);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
sparklers.cpp:67:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", &X[i]);
   ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 3 ms 484 KB Output is correct
5 Correct 2 ms 560 KB Output is correct
6 Correct 3 ms 560 KB Output is correct
7 Correct 3 ms 560 KB Output is correct
8 Correct 2 ms 592 KB Output is correct
9 Correct 3 ms 592 KB Output is correct
10 Correct 3 ms 592 KB Output is correct
11 Correct 2 ms 592 KB Output is correct
12 Correct 2 ms 612 KB Output is correct
13 Correct 3 ms 612 KB Output is correct
14 Correct 2 ms 612 KB Output is correct
15 Correct 3 ms 612 KB Output is correct
16 Correct 3 ms 612 KB Output is correct
17 Correct 2 ms 612 KB Output is correct
18 Correct 3 ms 612 KB Output is correct
19 Correct 2 ms 732 KB Output is correct
20 Correct 2 ms 732 KB Output is correct
21 Correct 2 ms 732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 3 ms 484 KB Output is correct
5 Correct 2 ms 560 KB Output is correct
6 Correct 3 ms 560 KB Output is correct
7 Correct 3 ms 560 KB Output is correct
8 Correct 2 ms 592 KB Output is correct
9 Correct 3 ms 592 KB Output is correct
10 Correct 3 ms 592 KB Output is correct
11 Correct 2 ms 592 KB Output is correct
12 Correct 2 ms 612 KB Output is correct
13 Correct 3 ms 612 KB Output is correct
14 Correct 2 ms 612 KB Output is correct
15 Correct 3 ms 612 KB Output is correct
16 Correct 3 ms 612 KB Output is correct
17 Correct 2 ms 612 KB Output is correct
18 Correct 3 ms 612 KB Output is correct
19 Correct 2 ms 732 KB Output is correct
20 Correct 2 ms 732 KB Output is correct
21 Correct 2 ms 732 KB Output is correct
22 Correct 3 ms 732 KB Output is correct
23 Correct 3 ms 732 KB Output is correct
24 Correct 3 ms 732 KB Output is correct
25 Correct 3 ms 732 KB Output is correct
26 Correct 3 ms 732 KB Output is correct
27 Correct 3 ms 732 KB Output is correct
28 Correct 3 ms 732 KB Output is correct
29 Correct 3 ms 732 KB Output is correct
30 Correct 2 ms 732 KB Output is correct
31 Correct 3 ms 732 KB Output is correct
32 Correct 3 ms 732 KB Output is correct
33 Correct 3 ms 732 KB Output is correct
34 Correct 3 ms 732 KB Output is correct
35 Correct 4 ms 732 KB Output is correct
36 Correct 4 ms 732 KB Output is correct
37 Correct 4 ms 732 KB Output is correct
38 Correct 3 ms 740 KB Output is correct
39 Correct 4 ms 740 KB Output is correct
40 Correct 2 ms 740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 3 ms 484 KB Output is correct
5 Correct 2 ms 560 KB Output is correct
6 Correct 3 ms 560 KB Output is correct
7 Correct 3 ms 560 KB Output is correct
8 Correct 2 ms 592 KB Output is correct
9 Correct 3 ms 592 KB Output is correct
10 Correct 3 ms 592 KB Output is correct
11 Correct 2 ms 592 KB Output is correct
12 Correct 2 ms 612 KB Output is correct
13 Correct 3 ms 612 KB Output is correct
14 Correct 2 ms 612 KB Output is correct
15 Correct 3 ms 612 KB Output is correct
16 Correct 3 ms 612 KB Output is correct
17 Correct 2 ms 612 KB Output is correct
18 Correct 3 ms 612 KB Output is correct
19 Correct 2 ms 732 KB Output is correct
20 Correct 2 ms 732 KB Output is correct
21 Correct 2 ms 732 KB Output is correct
22 Correct 3 ms 732 KB Output is correct
23 Correct 3 ms 732 KB Output is correct
24 Correct 3 ms 732 KB Output is correct
25 Correct 3 ms 732 KB Output is correct
26 Correct 3 ms 732 KB Output is correct
27 Correct 3 ms 732 KB Output is correct
28 Correct 3 ms 732 KB Output is correct
29 Correct 3 ms 732 KB Output is correct
30 Correct 2 ms 732 KB Output is correct
31 Correct 3 ms 732 KB Output is correct
32 Correct 3 ms 732 KB Output is correct
33 Correct 3 ms 732 KB Output is correct
34 Correct 3 ms 732 KB Output is correct
35 Correct 4 ms 732 KB Output is correct
36 Correct 4 ms 732 KB Output is correct
37 Correct 4 ms 732 KB Output is correct
38 Correct 3 ms 740 KB Output is correct
39 Correct 4 ms 740 KB Output is correct
40 Correct 2 ms 740 KB Output is correct
41 Correct 35 ms 3308 KB Output is correct
42 Correct 5 ms 3308 KB Output is correct
43 Correct 15 ms 3308 KB Output is correct
44 Correct 67 ms 6220 KB Output is correct
45 Correct 52 ms 6220 KB Output is correct
46 Correct 69 ms 6220 KB Output is correct
47 Correct 57 ms 6220 KB Output is correct
48 Correct 55 ms 6220 KB Output is correct
49 Correct 53 ms 6564 KB Output is correct
50 Correct 52 ms 6564 KB Output is correct
51 Correct 58 ms 6564 KB Output is correct
52 Correct 64 ms 6564 KB Output is correct
53 Correct 67 ms 6564 KB Output is correct
54 Correct 47 ms 6564 KB Output is correct
55 Correct 63 ms 6564 KB Output is correct
56 Correct 58 ms 6564 KB Output is correct
57 Correct 44 ms 6564 KB Output is correct
58 Correct 52 ms 6564 KB Output is correct
59 Correct 44 ms 6564 KB Output is correct
60 Correct 48 ms 6564 KB Output is correct
61 Correct 45 ms 6564 KB Output is correct
62 Correct 59 ms 6564 KB Output is correct
63 Correct 46 ms 6564 KB Output is correct
64 Correct 67 ms 6564 KB Output is correct
65 Correct 49 ms 6564 KB Output is correct
66 Correct 47 ms 6564 KB Output is correct
67 Correct 47 ms 6564 KB Output is correct
68 Correct 47 ms 6564 KB Output is correct
69 Correct 45 ms 6564 KB Output is correct