Submission #206144

# Submission time Handle Problem Language Result Execution time Memory
206144 2020-03-02T12:16:35 Z arnold518 Sparklers (JOI17_sparklers) C++14
30 / 100
2000 ms 4348 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 11 ms 4344 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 12 ms 4344 KB Output is correct
7 Correct 11 ms 4344 KB Output is correct
8 Correct 33 ms 4344 KB Output is correct
9 Correct 11 ms 4344 KB Output is correct
10 Correct 13 ms 4344 KB Output is correct
11 Correct 36 ms 4344 KB Output is correct
12 Correct 46 ms 4344 KB Output is correct
13 Correct 11 ms 4344 KB Output is correct
14 Correct 11 ms 4344 KB Output is correct
15 Correct 15 ms 4344 KB Output is correct
16 Correct 26 ms 4344 KB Output is correct
17 Correct 16 ms 4344 KB Output is correct
18 Correct 23 ms 4344 KB Output is correct
19 Correct 14 ms 4348 KB Output is correct
20 Correct 12 ms 4344 KB Output is correct
21 Correct 11 ms 4344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 4344 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 12 ms 4344 KB Output is correct
7 Correct 11 ms 4344 KB Output is correct
8 Correct 33 ms 4344 KB Output is correct
9 Correct 11 ms 4344 KB Output is correct
10 Correct 13 ms 4344 KB Output is correct
11 Correct 36 ms 4344 KB Output is correct
12 Correct 46 ms 4344 KB Output is correct
13 Correct 11 ms 4344 KB Output is correct
14 Correct 11 ms 4344 KB Output is correct
15 Correct 15 ms 4344 KB Output is correct
16 Correct 26 ms 4344 KB Output is correct
17 Correct 16 ms 4344 KB Output is correct
18 Correct 23 ms 4344 KB Output is correct
19 Correct 14 ms 4348 KB Output is correct
20 Correct 12 ms 4344 KB Output is correct
21 Correct 11 ms 4344 KB Output is correct
22 Execution timed out 2068 ms 4344 KB Time limit exceeded
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 4344 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 12 ms 4344 KB Output is correct
7 Correct 11 ms 4344 KB Output is correct
8 Correct 33 ms 4344 KB Output is correct
9 Correct 11 ms 4344 KB Output is correct
10 Correct 13 ms 4344 KB Output is correct
11 Correct 36 ms 4344 KB Output is correct
12 Correct 46 ms 4344 KB Output is correct
13 Correct 11 ms 4344 KB Output is correct
14 Correct 11 ms 4344 KB Output is correct
15 Correct 15 ms 4344 KB Output is correct
16 Correct 26 ms 4344 KB Output is correct
17 Correct 16 ms 4344 KB Output is correct
18 Correct 23 ms 4344 KB Output is correct
19 Correct 14 ms 4348 KB Output is correct
20 Correct 12 ms 4344 KB Output is correct
21 Correct 11 ms 4344 KB Output is correct
22 Execution timed out 2068 ms 4344 KB Time limit exceeded
23 Halted 0 ms 0 KB -