Submission #1226279

#TimeUsernameProblemLanguageResultExecution timeMemory
1226279_rain_Sparklers (JOI17_sparklers)C++20
50 / 100
34 ms1420 KiB
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

const int N=(int)1000;
const long double eps=1e-17;
	int x[N+2];
	int n,t,k;

	bool add(int l,int r,int length,LL s){
		return (long double)(x[r]-x[l])/(double)2/(double)s<=(long double)length*t;
	}

bool f[N+2][N+2];

bool possible(LL s){
	
	for(int i=2;i<=n;++i){
		if (x[i]!=x[i-1] && s==0) return false;
	}
	if (s==0) return true;
	memset(f,0,sizeof f);
	f[k][k]=true;
	for(int length=1;length<=n;++length){
		for(int i=1;i<=n;++i){
			int j=i+length-1;
			if (j>n) break;
			if (f[i][j]){
				if (i-1>=1 && add(i-1,j,j-i+1,s)) f[i-1][j]=true;
				if (j+1<=n && add(i,j+1,j-i+1,s)) f[i][j+1]=true;
			}
		}
	}
	
	return f[1][n];
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0) ; cout.tie(0);
	#define task "main"
	if (fopen(task".inp","r")){
		freopen(task".inp","r",stdin);
		freopen(task".out","w",stdout);
	}
	
	cin>>n>>k>>t;
	for(int i=1;i<=n;++i) cin>>x[i];
	
	int low=0,high=(int)1e9,ans=-1;
	while (low<=high){
		int mid=(low+high)/2;
		if (possible(mid)){
			ans=mid;
			high=mid-1;
		}
		else low=mid+1;
	}

	cout<<ans;
	
	return 0;
}

Compilation message (stderr)

sparklers.cpp: In function 'int main()':
sparklers.cpp:43:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |                 freopen(task".inp","r",stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
sparklers.cpp:44:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |                 freopen(task".out","w",stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...