結果
| 問題 |
No.484 収穫
|
| コンテスト | |
| ユーザー |
rapurasu
|
| 提出日時 | 2017-02-12 23:24:00 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,411 bytes |
| コンパイル時間 | 1,424 ms |
| コンパイル使用メモリ | 164,460 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-12-29 17:05:32 |
| 合計ジャッジ時間 | 2,316 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 WA * 5 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;
LL A[2001];
multimap<LL,int>m;
bool check(LL x){
multimap<LL,int>::iterator it;
it=m.begin();
int left=it->second;
int right=it->second;
if(-(it->first)>x)return false;
LL res=x+it->first;
//cout<<res<<endl;
LL p_time=-(it->first);
while(1){
it++;
if(it==m.end())break;
int nxt=it->second;
int ntime=-(it->first);
res+=p_time-ntime;
//cout<<res<<endl;
p_time=ntime;
if(left<=nxt&&nxt<=right)continue;
if(nxt<left){
res-=(left-nxt);
left=nxt;
if(res<0)return false;
}else{
res-=(nxt-right);
right=nxt;
if(res<0)return false;
}
}
return true;
}
/*
bool check(LL x){
bool ans=false;
bool check[2001];
//終了位置をiとする
REP(i,N){
if(x<A[i])continue;
//右→左
REP(j,N){
check[j]=false;
}
check[i]=true;
REP(j,i){
if(A[j]<=x-i+j)check[j]=true;
}
for(int j=i+1;j<N;j++){
if(A[j]<=x-i-j)check[j]=true;
}
bool c=true;
REP(j,N){
if(check[j]==false){
c=false;
break;
}
}
if(c){
ans=true;
break;
}
//左→右
REP(j,N){
check[j]=false;
}
check[i]=true;
REP(j,i){
if(A[j]<=x-(N-1-i)-(N-1)+j)check[j]=true;
}
for(int j=i+1;j<N;j++){
if(A[j]<=x-(j-i))check[j]=true;
}
c=true;
REP(j,N){
if(check[j]==false){
c=false;
break;
}
}
if(c){
ans=true;
break;
}
}
return ans;
}
*/
LL binary_search(){
LL ub=-1;
LL lb=10000000000001;
while((lb-ub)!=1){
LL mid=(ub+lb)/2;
if(check(mid)){
lb=mid;
}else{
ub=mid;
}
//cout<<mid<<endl;
}
return lb;
}
int main(){
cin>>N;
REP(i,N){
cin>>A[i];
//m[-A[i]]=i;
m.insert(make_pair(-A[i],i));
}
//cout<<check(1000000)<<endl;
cout<<binary_search()<<endl;
return(0);
}
rapurasu