답안 #505657

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
505657 2022-01-11T06:36:05 Z Koosha_mv Sparklers (JOI17_sparklers) C++14
0 / 100
1 ms 320 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=1e6+99,inf=1e10+9;

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

bool check(int s){
	int l=k-1,r=k+1,t=0,now=a[k];
	f(i,1,n){
		if(l>=0 && t+(now-min(now,a[l]+t))/2<=i*s){
			int ct=t,cn=now;
			now=(cn+min(cn,a[l]+ct))/2;
			t+=(cn-min(cn,a[l]+ct))/2;
			l--;
		}
		else if(r<n && t+(max(now,a[r]-t)-now)/2<=i*s){
			int ct=t,cn=now;
			now=(max(cn,a[r]-ct)+cn)/2;
			t+=(max(cn,a[r]-ct)-cn)/2;
			r++;
		}
		else{
			break;
		}
		///cout<<l<<" "<<r<<" "<<now<<" "<<t<<endl;
	}
	return l<0 && n-1<r;
}

main(){
	ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
	cin>>n>>k>>t; k--;
	f(i,0,n){
		cin>>a[i];
		a[i]<<=1;
	}
	//eror(check(160));
	//exit(0);
	int l=0,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:51:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   51 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 312 KB Output is correct
7 Incorrect 0 ms 320 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 312 KB Output is correct
7 Incorrect 0 ms 320 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 312 KB Output is correct
7 Incorrect 0 ms 320 KB Output isn't correct
8 Halted 0 ms 0 KB -