Submission #285564

# Submission time Handle Problem Language Result Execution time Memory
285564 2020-08-29T08:55:02 Z TadijaSebez Sparklers (JOI17_sparklers) C++11
100 / 100
76 ms 4508 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int N=100050;
bool check(vector<ll> a,vector<ll> b){
	if(a[0]<b[0])return 0;
	ll mx=a[0],mn=b[0];
	int i=1,j=1;
	while(1){
		if(i<a.size()&&a[i]>=mn)mx=max(mx,a[i++]);
		else if(j<b.size()&&b[j]<=mx)mn=min(mn,b[j++]);
		else break;
	}
	return i==a.size()&&j==b.size();
}
ll x[N],t;
int n,k;
bool check(ll s){
	vector<ll> a,b;
	for(int i=k;i>=1;i--)a.pb(x[i]-2*s*t*i);
	for(int i=k;i<=n;i++)b.pb(x[i]-2*s*t*i);
	if(!check(a,b))return 0;
	reverse(a.begin(),a.end());
	reverse(b.begin(),b.end());
	return check(a,b);
}
int main(){
	scanf("%i %i %lld",&n,&k,&t);
	for(int i=1;i<=n;i++)scanf("%lld",&x[i]);
	ll bot=0,top=1e9,mid,ans;
	while(top>=bot){
		mid=top+bot>>1;
		if(check(mid))ans=mid,top=mid-1;
		else bot=mid+1;
	}
	printf("%lld\n",ans);
	return 0;
}

Compilation message

sparklers.cpp: In function 'bool check(std::vector<long long int>, std::vector<long long int>)':
sparklers.cpp:11:7: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |   if(i<a.size()&&a[i]>=mn)mx=max(mx,a[i++]);
      |      ~^~~~~~~~~
sparklers.cpp:12:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |   else if(j<b.size()&&b[j]<=mx)mn=min(mn,b[j++]);
      |           ~^~~~~~~~~
sparklers.cpp:15:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |  return i==a.size()&&j==b.size();
      |         ~^~~~~~~~~~
sparklers.cpp:15:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |  return i==a.size()&&j==b.size();
      |                      ~^~~~~~~~~~
sparklers.cpp: In function 'int main()':
sparklers.cpp:33:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   33 |   mid=top+bot>>1;
      |       ~~~^~~~
sparklers.cpp:29:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   29 |  scanf("%i %i %lld",&n,&k,&t);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
sparklers.cpp:30:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   30 |  for(int i=1;i<=n;i++)scanf("%lld",&x[i]);
      |                       ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 256 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 1 ms 256 KB Output is correct
21 Correct 1 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 256 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 1 ms 256 KB Output is correct
21 Correct 1 ms 256 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 1 ms 384 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 256 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 1 ms 256 KB Output is correct
21 Correct 1 ms 256 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 1 ms 384 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 41 ms 2936 KB Output is correct
42 Correct 2 ms 384 KB Output is correct
43 Correct 11 ms 1048 KB Output is correct
44 Correct 71 ms 4012 KB Output is correct
45 Correct 62 ms 3964 KB Output is correct
46 Correct 64 ms 4000 KB Output is correct
47 Correct 65 ms 3988 KB Output is correct
48 Correct 59 ms 3832 KB Output is correct
49 Correct 65 ms 3972 KB Output is correct
50 Correct 62 ms 3900 KB Output is correct
51 Correct 66 ms 4068 KB Output is correct
52 Correct 68 ms 4500 KB Output is correct
53 Correct 65 ms 4072 KB Output is correct
54 Correct 69 ms 4380 KB Output is correct
55 Correct 61 ms 3988 KB Output is correct
56 Correct 64 ms 4056 KB Output is correct
57 Correct 61 ms 3924 KB Output is correct
58 Correct 61 ms 3836 KB Output is correct
59 Correct 55 ms 3124 KB Output is correct
60 Correct 68 ms 4448 KB Output is correct
61 Correct 69 ms 4476 KB Output is correct
62 Correct 67 ms 4064 KB Output is correct
63 Correct 68 ms 4440 KB Output is correct
64 Correct 62 ms 4092 KB Output is correct
65 Correct 60 ms 3828 KB Output is correct
66 Correct 61 ms 3884 KB Output is correct
67 Correct 59 ms 3856 KB Output is correct
68 Correct 68 ms 4508 KB Output is correct
69 Correct 76 ms 4448 KB Output is correct