結果

問題 No.484 収穫
ユーザー n_vipn_vip
提出日時 2017-02-10 23:26:18
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 3,045 bytes
コンパイル時間 1,004 ms
コンパイル使用メモリ 103,524 KB
実行使用メモリ 21,320 KB
最終ジャッジ日時 2023-08-28 09:04:19
合計ジャッジ時間 10,481 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
20,940 KB
testcase_01 AC 69 ms
21,076 KB
testcase_02 AC 24 ms
21,172 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 70 ms
20,944 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 75 ms
21,028 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 76 ms
21,032 KB
testcase_12 AC 250 ms
20,952 KB
testcase_13 AC 316 ms
21,248 KB
testcase_14 AC 425 ms
21,020 KB
testcase_15 AC 356 ms
20,944 KB
testcase_16 AC 419 ms
20,944 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 317 ms
21,000 KB
testcase_23 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
#define out(args...){vector<string> a_r_g_s=s_p_l_i_t(#args, ','); e_r_r(a_r_g_s.begin(), args); }
vector<string> s_p_l_i_t(const string& s, char c) { vector<string> v; stringstream ss(s); string x; while(getline(ss,x,c)) v.emplace_back(x); return move(v);}
void e_r_r(vector<string>::iterator it) {}
template<typename T, typename... Args> void e_r_r(vector<string>::iterator it, T a, Args... args){ if(*it==" 1"||*it=="1") cerr<<endl; else cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; e_r_r(++it, args...);}
const ll MOD=1e9+7;
const ll INF=1e9+5000;

int dp[2123][2123];

int solve(const vector<int> &v){
  if(*min_element(all(v))<0) return 0;
  fill(dp[0],dp[2123],INF);
  int n=v.size();
  rep(i,n) dp[i][i]=0;
  rep(d,n)rep(i,n-d){
    if(dp[i][i+d]<INF){
      if(v[i+d]<dp[i][i+d]) continue;
      if(i) MN(dp[i+d][i-1], dp[i][i+d]+d);
      if(i+d+1<n) MN(dp[i][i+d+1], dp[i][i+d]+1);
    }
    if(dp[i+d][i]<INF){
      if(v[i]<dp[i+d][i]) continue;
      if(i) MN(dp[i+d][i-1], dp[i+d][i]+1);
      if(i+d+1<n) MN(dp[i+d][i-1], dp[i][i+d]+d);
    }
  }
  //out(v); rep(i,4){rep(j,4) cout<<dp[i][j]<<",";cout<<endl;}
  return v[n-1]>=dp[0][n-1] || v[0]>=dp[n-1][0];
}

int main(){
  // solve({2,1,1});
  // return 0;
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  int n;
  cin>>n;
  vector<int> a(n);
  rep(i,n) cin>>a[i];
  int mx=*max_element(all(a));
  int l=0,r=INF;
  while(r-l>1){
    int m=(l+r)/2;
    vector<int> v(n);
    rep(i,n) v[i]=m-a[i];
    //out(m,1);
    if(solve(v)) r=m;
    else l=m;
  }
  cout<<r<<endl;
  return 0;
}
0