Submission #206145

# Submission time Handle Problem Language Result Execution time Memory
206145 2020-03-02T12:19:01 Z arnold518 Sparklers (JOI17_sparklers) C++14
50 / 100
100 ms 8568 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1000;

int N, K;
ll T, A[MAXN+10], B[MAXN+10];

int dp[MAXN+10][MAXN+10];

int f(int l, int r)
{
	if(l==1 && r==N-1) return 1;
	int &ret=dp[l][r];
	if(ret!=-1) return ret;

	ret=0;
	if(l!=1 && B[r]-B[l-2]>=0 && f(l-1, r)==1) ret=1;
	if(r!=N-1 && B[r+1]-B[l-1]>=0 && f(l, r+1)==1) ret=1;
	return ret;
}

bool solve(ll v)
{
	int i, j;

	for(i=1; i<N; i++) B[i]=v*T-(A[i+1]-A[i])/2;
	memset(dp, -1, sizeof(dp));

	for(i=1; i<N; i++) B[i]+=B[i-1];
	return f(K, K-1);
}

int main()
{
	int i, j;

	scanf("%d%d%lld", &N, &K, &T), T*=2;
	for(i=1; i<=N; i++) scanf("%lld", &A[i]), A[i]*=2;

	ll lo=-1, hi=1e10;
	while(lo+1<hi)
	{
		ll mid=lo+hi>>1;
		if(solve(mid)) hi=mid;
		else lo=mid;
	}
	printf("%lld\n", hi);
}

Compilation message

sparklers.cpp: In function 'bool solve(ll)':
sparklers.cpp:29:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j;
         ^
sparklers.cpp: In function 'int main()':
sparklers.cpp:48:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   ll mid=lo+hi>>1;
          ~~^~~
sparklers.cpp:40:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j;
         ^
sparklers.cpp:42:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%lld", &N, &K, &T), T*=2;
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
sparklers.cpp:43:42: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(i=1; i<=N; i++) scanf("%lld", &A[i]), A[i]*=2;
                      ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 12 ms 4348 KB Output is correct
2 Correct 11 ms 4344 KB Output is correct
3 Correct 11 ms 4344 KB Output is correct
4 Correct 11 ms 4344 KB Output is correct
5 Correct 11 ms 4344 KB Output is correct
6 Correct 11 ms 4344 KB Output is correct
7 Correct 11 ms 4344 KB Output is correct
8 Correct 11 ms 4344 KB Output is correct
9 Correct 11 ms 4344 KB Output is correct
10 Correct 11 ms 4344 KB Output is correct
11 Correct 11 ms 4344 KB Output is correct
12 Correct 12 ms 4344 KB Output is correct
13 Correct 12 ms 4344 KB Output is correct
14 Correct 12 ms 4344 KB Output is correct
15 Correct 12 ms 4344 KB Output is correct
16 Correct 12 ms 4344 KB Output is correct
17 Correct 12 ms 4348 KB Output is correct
18 Correct 11 ms 4344 KB Output is correct
19 Correct 11 ms 4340 KB Output is correct
20 Correct 11 ms 4344 KB Output is correct
21 Correct 12 ms 4344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 4348 KB Output is correct
2 Correct 11 ms 4344 KB Output is correct
3 Correct 11 ms 4344 KB Output is correct
4 Correct 11 ms 4344 KB Output is correct
5 Correct 11 ms 4344 KB Output is correct
6 Correct 11 ms 4344 KB Output is correct
7 Correct 11 ms 4344 KB Output is correct
8 Correct 11 ms 4344 KB Output is correct
9 Correct 11 ms 4344 KB Output is correct
10 Correct 11 ms 4344 KB Output is correct
11 Correct 11 ms 4344 KB Output is correct
12 Correct 12 ms 4344 KB Output is correct
13 Correct 12 ms 4344 KB Output is correct
14 Correct 12 ms 4344 KB Output is correct
15 Correct 12 ms 4344 KB Output is correct
16 Correct 12 ms 4344 KB Output is correct
17 Correct 12 ms 4348 KB Output is correct
18 Correct 11 ms 4344 KB Output is correct
19 Correct 11 ms 4340 KB Output is correct
20 Correct 11 ms 4344 KB Output is correct
21 Correct 12 ms 4344 KB Output is correct
22 Correct 45 ms 4344 KB Output is correct
23 Correct 33 ms 4344 KB Output is correct
24 Correct 23 ms 4344 KB Output is correct
25 Correct 15 ms 4344 KB Output is correct
26 Correct 43 ms 4344 KB Output is correct
27 Correct 50 ms 4344 KB Output is correct
28 Correct 72 ms 4424 KB Output is correct
29 Correct 75 ms 4344 KB Output is correct
30 Correct 56 ms 4344 KB Output is correct
31 Correct 62 ms 4344 KB Output is correct
32 Correct 82 ms 4344 KB Output is correct
33 Correct 77 ms 4344 KB Output is correct
34 Correct 45 ms 4396 KB Output is correct
35 Correct 76 ms 4472 KB Output is correct
36 Correct 34 ms 4344 KB Output is correct
37 Correct 32 ms 4344 KB Output is correct
38 Correct 64 ms 4344 KB Output is correct
39 Correct 27 ms 4344 KB Output is correct
40 Correct 100 ms 4344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 4348 KB Output is correct
2 Correct 11 ms 4344 KB Output is correct
3 Correct 11 ms 4344 KB Output is correct
4 Correct 11 ms 4344 KB Output is correct
5 Correct 11 ms 4344 KB Output is correct
6 Correct 11 ms 4344 KB Output is correct
7 Correct 11 ms 4344 KB Output is correct
8 Correct 11 ms 4344 KB Output is correct
9 Correct 11 ms 4344 KB Output is correct
10 Correct 11 ms 4344 KB Output is correct
11 Correct 11 ms 4344 KB Output is correct
12 Correct 12 ms 4344 KB Output is correct
13 Correct 12 ms 4344 KB Output is correct
14 Correct 12 ms 4344 KB Output is correct
15 Correct 12 ms 4344 KB Output is correct
16 Correct 12 ms 4344 KB Output is correct
17 Correct 12 ms 4348 KB Output is correct
18 Correct 11 ms 4344 KB Output is correct
19 Correct 11 ms 4340 KB Output is correct
20 Correct 11 ms 4344 KB Output is correct
21 Correct 12 ms 4344 KB Output is correct
22 Correct 45 ms 4344 KB Output is correct
23 Correct 33 ms 4344 KB Output is correct
24 Correct 23 ms 4344 KB Output is correct
25 Correct 15 ms 4344 KB Output is correct
26 Correct 43 ms 4344 KB Output is correct
27 Correct 50 ms 4344 KB Output is correct
28 Correct 72 ms 4424 KB Output is correct
29 Correct 75 ms 4344 KB Output is correct
30 Correct 56 ms 4344 KB Output is correct
31 Correct 62 ms 4344 KB Output is correct
32 Correct 82 ms 4344 KB Output is correct
33 Correct 77 ms 4344 KB Output is correct
34 Correct 45 ms 4396 KB Output is correct
35 Correct 76 ms 4472 KB Output is correct
36 Correct 34 ms 4344 KB Output is correct
37 Correct 32 ms 4344 KB Output is correct
38 Correct 64 ms 4344 KB Output is correct
39 Correct 27 ms 4344 KB Output is correct
40 Correct 100 ms 4344 KB Output is correct
41 Runtime error 13 ms 8568 KB Execution killed with signal 11 (could be triggered by violating memory limits)
42 Halted 0 ms 0 KB -