結果

問題 No.409 ダイエット
ユーザー 0w10w1
提出日時 2017-04-25 20:56:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,492 bytes
コンパイル時間 1,628 ms
コンパイル使用メモリ 172,420 KB
実行使用メモリ 6,788 KB
最終ジャッジ日時 2023-10-11 10:01:07
合計ジャッジ時間 6,095 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 ms
4,352 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 WA -
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 1 ms
4,352 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 1 ms
4,352 KB
testcase_16 AC 1 ms
4,352 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 1 ms
4,352 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,352 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,352 KB
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,352 KB
testcase_27 AC 1 ms
4,352 KB
testcase_28 AC 1 ms
4,352 KB
testcase_29 AC 1 ms
4,348 KB
testcase_30 AC 2 ms
4,352 KB
testcase_31 AC 1 ms
4,352 KB
testcase_32 AC 1 ms
4,348 KB
testcase_33 AC 1 ms
4,352 KB
testcase_34 AC 2 ms
4,348 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 2 ms
4,348 KB
testcase_39 AC 2 ms
4,348 KB
testcase_40 WA -
testcase_41 AC 2 ms
4,352 KB
testcase_42 AC 2 ms
4,352 KB
testcase_43 AC 2 ms
4,348 KB
testcase_44 AC 2 ms
4,352 KB
testcase_45 AC 2 ms
4,348 KB
testcase_46 WA -
testcase_47 AC 2 ms
4,352 KB
testcase_48 AC 2 ms
4,352 KB
testcase_49 AC 2 ms
4,348 KB
testcase_50 AC 2 ms
4,352 KB
testcase_51 AC 2 ms
4,480 KB
testcase_52 AC 2 ms
4,352 KB
testcase_53 WA -
testcase_54 WA -
testcase_55 AC 17 ms
5,080 KB
testcase_56 AC 22 ms
4,608 KB
testcase_57 AC 33 ms
6,788 KB
testcase_58 AC 15 ms
4,812 KB
testcase_59 WA -
testcase_60 AC 13 ms
4,712 KB
testcase_61 AC 30 ms
6,444 KB
testcase_62 AC 30 ms
6,572 KB
testcase_63 WA -
testcase_64 WA -
testcase_65 WA -
testcase_66 AC 33 ms
6,772 KB
testcase_67 AC 25 ms
5,952 KB
testcase_68 WA -
testcase_69 WA -
testcase_70 WA -
testcase_71 WA -
testcase_72 WA -
testcase_73 WA -
testcase_74 WA -
testcase_75 WA -
testcase_76 WA -
testcase_77 WA -
testcase_78 WA -
testcase_79 WA -
testcase_80 WA -
testcase_81 WA -
testcase_82 WA -
testcase_83 WA -
testcase_84 WA -
testcase_85 WA -
testcase_86 WA -
testcase_87 WA -
testcase_88 WA -
testcase_89 WA -
testcase_90 WA -
testcase_91 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

const int MAXN = int( 3e5 );

int N, A, B, W;
int D[ MAXN ];
double dp[ MAXN + 1 ];

struct Line {
  double s, c; // slope, constant
  Line( double _s, double _c ) {
    s = _s;
    c = _c;
  }
  double operator() ( double x ) {
    return s * x + c;
  }
};

bool check( Line l1, Line l2, Line l3 ) {
  double x12 = ( l2.c - l1.c ) / ( l1.s - l2.s );
  return l3( x12 ) <= l1( x12 );
}

signed main() {
  ios::sync_with_stdio( 0 );
  cin >> N >> A >> B >> W;
  for( int i = 0; i < N; ++i ) {
    cin >> D[ i ];
  }
  if( B == 0 ) {
    cout << 1LL * W - 1LL * A * N << endl;
    exit( 0 );
  }
  deque< Line > dq;
  dq.emplace_back( Line( 0.0, ( dp[ 0 ] = 1.0 * W ) + A ) );
  for( int i = 1; i <= N; ++i ) {
    while( dq.size() >= 2 and dq[ 0 ]( i ) >= dq[ 1 ]( i ) ) {
      dq.pop_front();
    }
    dp[ i ] = dq[ 0 ]( i ) + ( 1.0 * i * i - i ) * B / 2 - 1.0 * i * A + D[ i - 1 ];
    Line newl( -1.0 * B * i, dp[ i ] + ( 1.0 * i * i + i ) * B / 2 + 1.0 * ( i + 1 ) * A );
    while( dq.size() >= 2 and check( dq[ 0 ], dq[ 1 ], newl ) ) {
      dq.pop_back();
    }
    dq.emplace_back( newl );
  }
  double ans = 1e12;
  for( int i = 0; i <= N; ++i ) {
    ans = min( ans, dp[ i ] + 1.0 * B * ( N - i ) * ( N - i + 1 ) / 2 - 1.0 * A * ( N - i ) );
  }
  long long v = int( ans );
  if( fabs( v - ans ) > fabs( v + 1 - ans ) ) {
    ++v;
  } else if( fabs( v - ans ) > fabs( v - 1 - ans ) ) {
    --v;
  }
  cout << v << endl;
  return 0;
}
0