結果

問題 No.409 ダイエット
ユーザー 0w10w1
提出日時 2017-04-25 21:17:24
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,427 bytes
コンパイル時間 1,673 ms
コンパイル使用メモリ 170,768 KB
実行使用メモリ 10,488 KB
最終ジャッジ日時 2023-10-11 10:05:08
合計ジャッジ時間 6,248 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,620 KB
testcase_01 AC 2 ms
5,524 KB
testcase_02 AC 2 ms
5,492 KB
testcase_03 AC 2 ms
5,488 KB
testcase_04 AC 2 ms
5,424 KB
testcase_05 AC 2 ms
5,436 KB
testcase_06 AC 3 ms
5,432 KB
testcase_07 AC 2 ms
5,432 KB
testcase_08 AC 2 ms
5,624 KB
testcase_09 AC 2 ms
5,436 KB
testcase_10 AC 2 ms
5,700 KB
testcase_11 AC 2 ms
5,420 KB
testcase_12 AC 2 ms
5,472 KB
testcase_13 AC 2 ms
5,488 KB
testcase_14 AC 2 ms
5,440 KB
testcase_15 AC 2 ms
5,424 KB
testcase_16 AC 2 ms
5,420 KB
testcase_17 AC 2 ms
5,748 KB
testcase_18 AC 2 ms
5,488 KB
testcase_19 AC 2 ms
5,420 KB
testcase_20 AC 2 ms
5,488 KB
testcase_21 AC 2 ms
5,464 KB
testcase_22 AC 2 ms
5,424 KB
testcase_23 AC 2 ms
5,528 KB
testcase_24 AC 2 ms
5,476 KB
testcase_25 AC 2 ms
5,488 KB
testcase_26 AC 2 ms
5,428 KB
testcase_27 AC 2 ms
5,432 KB
testcase_28 AC 2 ms
5,468 KB
testcase_29 AC 2 ms
5,420 KB
testcase_30 AC 2 ms
5,428 KB
testcase_31 AC 2 ms
5,484 KB
testcase_32 AC 2 ms
5,552 KB
testcase_33 AC 2 ms
5,432 KB
testcase_34 AC 2 ms
5,428 KB
testcase_35 AC 3 ms
5,456 KB
testcase_36 AC 2 ms
5,744 KB
testcase_37 AC 2 ms
5,460 KB
testcase_38 AC 2 ms
5,516 KB
testcase_39 AC 2 ms
5,468 KB
testcase_40 AC 2 ms
5,480 KB
testcase_41 AC 2 ms
5,540 KB
testcase_42 AC 2 ms
5,528 KB
testcase_43 AC 3 ms
5,788 KB
testcase_44 AC 2 ms
5,520 KB
testcase_45 AC 3 ms
5,480 KB
testcase_46 AC 2 ms
5,468 KB
testcase_47 AC 2 ms
5,672 KB
testcase_48 AC 2 ms
5,468 KB
testcase_49 AC 2 ms
5,668 KB
testcase_50 AC 2 ms
5,464 KB
testcase_51 AC 3 ms
5,560 KB
testcase_52 AC 3 ms
5,604 KB
testcase_53 AC 3 ms
5,484 KB
testcase_54 AC 2 ms
5,596 KB
testcase_55 AC 21 ms
9,508 KB
testcase_56 AC 23 ms
6,172 KB
testcase_57 AC 39 ms
10,348 KB
testcase_58 AC 18 ms
7,336 KB
testcase_59 AC 27 ms
9,516 KB
testcase_60 AC 16 ms
7,140 KB
testcase_61 AC 35 ms
10,068 KB
testcase_62 AC 36 ms
10,392 KB
testcase_63 AC 35 ms
10,028 KB
testcase_64 AC 21 ms
9,500 KB
testcase_65 AC 39 ms
10,248 KB
testcase_66 AC 39 ms
10,488 KB
testcase_67 AC 31 ms
9,756 KB
testcase_68 AC 28 ms
9,516 KB
testcase_69 AC 35 ms
10,060 KB
testcase_70 AC 40 ms
9,988 KB
testcase_71 AC 23 ms
7,448 KB
testcase_72 WA -
testcase_73 AC 47 ms
10,176 KB
testcase_74 WA -
testcase_75 AC 45 ms
10,124 KB
testcase_76 AC 32 ms
9,856 KB
testcase_77 AC 23 ms
7,388 KB
testcase_78 AC 25 ms
9,500 KB
testcase_79 AC 20 ms
7,496 KB
testcase_80 WA -
testcase_81 AC 45 ms
10,100 KB
testcase_82 AC 33 ms
9,572 KB
testcase_83 WA -
testcase_84 AC 31 ms
9,572 KB
testcase_85 AC 6 ms
5,844 KB
testcase_86 AC 31 ms
9,552 KB
testcase_87 WA -
testcase_88 AC 18 ms
7,172 KB
testcase_89 AC 37 ms
9,732 KB
testcase_90 AC 17 ms
6,872 KB
testcase_91 AC 38 ms
9,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define double long double
const int MAXN = int( 3e5 );
#define int long long

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[ dq.size() - 2 ], dq[ dq.size() - 1 ], newl ) ) {
      dq.pop_back();
    }
    dq.emplace_back( newl );
  }
  double ans = 1e30;
  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 ) );
  }
  cout << ( long long ) ans << endl;
  return 0;
}
0