Submission #506171

# Submission time Handle Problem Language Result Execution time Memory
506171 2022-01-11T20:00:48 Z Koosha_mv Sparklers (JOI17_sparklers) C++14
100 / 100
111 ms 6620 KB
#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<(x.F)<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
#define int ll

const int N=2e5+9,inf=1e10+9;

int n,k,t,a[N];

vector<int> g(vector<int> v,int x){
	vector<int> res;
	int pos=0;
	f(i,0,v.size()){
		if(v[i]>v[pos]){
			pos=i;
		}
	}
	if(x==0){
		f(i,0,pos+1){
			res.pb(v[i]);
		}
	}
	else{
		f_(i,v.size()-1,pos){
			res.pb(v[i]);
		}
	}
	return res;
}
bool solve(vector<int> v0,vector<int> v1){
	int p0=0,p1=0,mn0=inf,mn1=inf;
	if(v0[p0]+v1[p1]<0) return 0;
//	dbgv(v0);
//	dbgv(v1);
	f(i,1,v0.size()){
		minm(mn0,v0[i]);
		if(v0[i]>=v0[0]){
			break;
		}
	}
	f(i,1,v1.size()){
		minm(mn1,v1[i]);
		if(v1[i]>=v1[0]){
			break;
		}
	}
//	cout<<mn0<<" "<<mn1<<endl;
	while(p0+1<v0.size() || p1+1<v1.size()){
//		cout<<p0<<" "<<p1<<endl;
		if(p0+1<v0.size() && mn0+v1[p1]>=0){
			f(j,p0+1,v0.size()){
				if(v0[j]>=v0[p0]){
					p0=j;
					break;
				}
			}
			mn0=inf;
			f(j,p0+1,v0.size()){
				minm(mn0,v0[j]);
				if(v0[j]>=v0[p0]){
					break;
				}
			}
		}
		else if(p1+1<v1.size() && mn1+v0[p0]>=0){
			f(j,p1+1,v1.size()){
				if(v1[j]>=v1[p1]){
					p1=j;
					break;
				}
			}
			mn1=inf;
			f(j,p1+1,v1.size()){
				minm(mn1,v1[j]);
				if(v1[j]>=v1[p1]){
					break;
				}
			}
		}
		else{
			return 0;
		}
	}
	return 1;
}
bool check(int s){
	vector<int> v0,v1;
	v0.pb(0);
	v1.pb(0);
	f_(i,k-1,0){
		v0.pb(-(a[k]-a[i]-s*(k-i)));
	}
	f(i,k+1,n){
		v1.pb(-(a[i]-a[k]-s*(i-k)));
	}
//	dbgv(v0);
//	dbgv(v1);
	return solve(g(v0,0),g(v1,0)) && solve(g(v0,1),g(v1,1));
}

main(){
	ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
	cin>>n>>k>>t; k--;
	f(i,0,n){
		cin>>a[i];
	}
	//eror(check(150));
	//exit(0);
	int l=-1,r=inf;
	while(l+1<r){
		int mid=(l+r)>>1;
		if(check(2ll*t*mid)) r=mid;
		else l=mid;
	}
	cout<<r;
}

Compilation message

sparklers.cpp: In function 'std::vector<long long int> g(std::vector<long long int>, long long int)':
sparklers.cpp:8:31: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #define f(i,a,b) for(int i=a;i<b;i++)
......
   31 |  f(i,0,v.size()){
      |    ~~~~~~~~~~~~                
sparklers.cpp:31:2: note: in expansion of macro 'f'
   31 |  f(i,0,v.size()){
      |  ^
sparklers.cpp: In function 'bool solve(std::vector<long long int>, std::vector<long long int>)':
sparklers.cpp:8:31: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #define f(i,a,b) for(int i=a;i<b;i++)
......
   53 |  f(i,1,v0.size()){
      |    ~~~~~~~~~~~~~               
sparklers.cpp:53:2: note: in expansion of macro 'f'
   53 |  f(i,1,v0.size()){
      |  ^
sparklers.cpp:8:31: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #define f(i,a,b) for(int i=a;i<b;i++)
......
   59 |  f(i,1,v1.size()){
      |    ~~~~~~~~~~~~~               
sparklers.cpp:59:2: note: in expansion of macro 'f'
   59 |  f(i,1,v1.size()){
      |  ^
sparklers.cpp:66:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |  while(p0+1<v0.size() || p1+1<v1.size()){
      |        ~~~~^~~~~~~~~~
sparklers.cpp:66:30: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |  while(p0+1<v0.size() || p1+1<v1.size()){
      |                          ~~~~^~~~~~~~~~
sparklers.cpp:68:10: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |   if(p0+1<v0.size() && mn0+v1[p1]>=0){
      |      ~~~~^~~~~~~~~~
sparklers.cpp:8:31: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #define f(i,a,b) for(int i=a;i<b;i++)
......
   69 |    f(j,p0+1,v0.size()){
      |      ~~~~~~~~~~~~~~~~          
sparklers.cpp:69:4: note: in expansion of macro 'f'
   69 |    f(j,p0+1,v0.size()){
      |    ^
sparklers.cpp:8:31: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #define f(i,a,b) for(int i=a;i<b;i++)
......
   76 |    f(j,p0+1,v0.size()){
      |      ~~~~~~~~~~~~~~~~          
sparklers.cpp:76:4: note: in expansion of macro 'f'
   76 |    f(j,p0+1,v0.size()){
      |    ^
sparklers.cpp:83:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |   else if(p1+1<v1.size() && mn1+v0[p0]>=0){
      |           ~~~~^~~~~~~~~~
sparklers.cpp:8:31: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #define f(i,a,b) for(int i=a;i<b;i++)
......
   84 |    f(j,p1+1,v1.size()){
      |      ~~~~~~~~~~~~~~~~          
sparklers.cpp:84:4: note: in expansion of macro 'f'
   84 |    f(j,p1+1,v1.size()){
      |    ^
sparklers.cpp:8:31: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #define f(i,a,b) for(int i=a;i<b;i++)
......
   91 |    f(j,p1+1,v1.size()){
      |      ~~~~~~~~~~~~~~~~          
sparklers.cpp:91:4: note: in expansion of macro 'f'
   91 |    f(j,p1+1,v1.size()){
      |    ^
sparklers.cpp: At global scope:
sparklers.cpp:119:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  119 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 316 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 0 ms 320 KB Output is correct
7 Correct 0 ms 316 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 316 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 316 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 0 ms 320 KB Output is correct
7 Correct 0 ms 316 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 316 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 352 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 2 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 1 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 316 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 0 ms 320 KB Output is correct
7 Correct 0 ms 316 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 316 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 352 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 2 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 1 ms 320 KB Output is correct
41 Correct 68 ms 3812 KB Output is correct
42 Correct 2 ms 460 KB Output is correct
43 Correct 17 ms 1500 KB Output is correct
44 Correct 93 ms 6240 KB Output is correct
45 Correct 82 ms 5752 KB Output is correct
46 Correct 81 ms 6076 KB Output is correct
47 Correct 97 ms 5936 KB Output is correct
48 Correct 86 ms 5760 KB Output is correct
49 Correct 85 ms 6284 KB Output is correct
50 Correct 83 ms 5744 KB Output is correct
51 Correct 100 ms 5920 KB Output is correct
52 Correct 98 ms 6608 KB Output is correct
53 Correct 84 ms 5432 KB Output is correct
54 Correct 88 ms 5820 KB Output is correct
55 Correct 85 ms 5904 KB Output is correct
56 Correct 90 ms 6164 KB Output is correct
57 Correct 91 ms 6564 KB Output is correct
58 Correct 99 ms 5836 KB Output is correct
59 Correct 80 ms 5028 KB Output is correct
60 Correct 92 ms 6620 KB Output is correct
61 Correct 102 ms 6404 KB Output is correct
62 Correct 99 ms 6044 KB Output is correct
63 Correct 93 ms 6436 KB Output is correct
64 Correct 91 ms 5780 KB Output is correct
65 Correct 92 ms 5952 KB Output is correct
66 Correct 82 ms 5800 KB Output is correct
67 Correct 76 ms 6000 KB Output is correct
68 Correct 111 ms 6572 KB Output is correct
69 Correct 101 ms 6596 KB Output is correct