結果

問題 No.484 収穫
ユーザー rapurasurapurasu
提出日時 2017-02-12 23:24:00
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,411 bytes
コンパイル時間 1,959 ms
コンパイル使用メモリ 148,592 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-28 14:57:29
合計ジャッジ時間 2,047 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 WA -
testcase_07 AC 1 ms
4,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 3 ms
4,384 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 3 ms
4,380 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 3 ms
4,376 KB
testcase_22 AC 4 ms
4,380 KB
testcase_23 AC 4 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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);
}
0