結果

問題 No.484 収穫
ユーザー lgswdnlgswdn
提出日時 2023-10-14 09:53:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,305 ms / 3,000 ms
コード長 2,129 bytes
コンパイル時間 2,401 ms
コンパイル使用メモリ 199,596 KB
実行使用メモリ 128,832 KB
最終ジャッジ日時 2023-10-14 09:54:09
合計ジャッジ時間 17,914 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,588 KB
testcase_01 AC 2 ms
5,612 KB
testcase_02 AC 2 ms
5,548 KB
testcase_03 AC 2 ms
5,784 KB
testcase_04 AC 2 ms
5,560 KB
testcase_05 AC 2 ms
5,644 KB
testcase_06 AC 2 ms
7,904 KB
testcase_07 AC 2 ms
7,796 KB
testcase_08 AC 3 ms
7,696 KB
testcase_09 AC 10 ms
18,308 KB
testcase_10 AC 11 ms
18,424 KB
testcase_11 AC 10 ms
18,320 KB
testcase_12 AC 1,190 ms
128,664 KB
testcase_13 AC 1,253 ms
128,608 KB
testcase_14 AC 1,201 ms
128,728 KB
testcase_15 AC 1,230 ms
128,680 KB
testcase_16 AC 1,222 ms
128,832 KB
testcase_17 AC 1,305 ms
128,600 KB
testcase_18 AC 1,280 ms
128,624 KB
testcase_19 AC 1,197 ms
128,664 KB
testcase_20 AC 1,194 ms
128,612 KB
testcase_21 AC 1,171 ms
128,688 KB
testcase_22 AC 1,188 ms
128,740 KB
testcase_23 AC 1,162 ms
128,612 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//vanitas vanitatum et omnia
#include<bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define mp make_pair
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 i128; 
template<typename T,typename U>
T ceil(T x, U y) {return (x>0?(x+y-1)/y:x/y);}
template<typename T,typename U>
T floor(T x, U y) {return (x>0?x/y:(x-y+1)/y);}
template<class T,class S>
bool chmax(T &a,const S b) {return (a<b?a=b,1:0);}      
template<class T,class S>
bool chmin(T &a,const S b) {return (a>b?a=b,1:0);}
int popcnt(int x) {return __builtin_popcount(x);}
int popcnt(ll x)  {return __builtin_popcountll(x);}
int topbit(int x) {return (x==0?-1:31-__builtin_clz(x));}
int topbit(ll x)  {return (x==0?-1:63-__builtin_clzll(x));}
int lowbit(int x) {return (x==0?-1:__builtin_ctz(x));}
int lowbit(ll x)  {return (x==0?-1:__builtin_ctzll(x));}

#define int long long
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
typedef pair<int,int> pii; 
typedef vector<int> vi;  
typedef vector<pii> vp; 
typedef tuple<int,int,int> tiii;
int read() {
  int x=0,w=1; char c=getchar(); 
  while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
  while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();}
  return x*w;
}

const int N=2005,inf=0x3f3f3f3f3f3f3f3f;
int n,a[N],f[N][N][2],vst[N][N][2],mx,p;

int dp(int l,int r,int x) {
  if(vst[l][r][x]) return f[l][r][x]; vst[l][r][x]=1;
  if(l==r) {return f[l][r][x]=p;}
  f[l][r][x]=-inf;
  if(x==0) {
    int s=dp(l+1,r,0);
    if(a[l]<=s-1) chmax(f[l][r][x],s-1);
    s=dp(l,r-1,1);
    if(a[r]<=s-1) chmax(f[l][r][x],s-(r-l+1));
  } else {
    int s=dp(l,r-1,1);
    if(a[r]<=s-1) chmax(f[l][r][x],s-1);
    s=dp(l+1,r,0);
    if(a[l]<=s-1) chmax(f[l][r][x],s-(r-l+1));
  } return f[l][r][x];
}

signed main() {
  n=read();
  rep(i,1,n) a[i]=read(), chmax(mx,a[i]);
  int l=mx,r=mx+2*n,ans=-1;
  while(l<=r) {
    p=l+r>>1;
    rep(i,1,n) rep(j,1,n) rep(k,0,1) vst[i][j][k]=0;
    int s=max(dp(1,n,0),dp(1,n,1));
    if(s>=0) ans=p, r=p-1;
    else l=p+1;
  }
  printf("%lld\n",ans);
  return 0;
}
0