結果

問題 No.484 収穫
ユーザー lgswdnlgswdn
提出日時 2023-10-14 09:52:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,113 bytes
コンパイル時間 1,986 ms
コンパイル使用メモリ 199,928 KB
実行使用メモリ 11,720 KB
最終ジャッジ日時 2023-10-14 09:53:05
合計ジャッジ時間 6,562 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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];
  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