結果

問題 No.409 ダイエット
ユーザー 0w10w1
提出日時 2017-04-25 21:11:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,542 bytes
コンパイル時間 1,640 ms
コンパイル使用メモリ 171,136 KB
実行使用メモリ 9,168 KB
最終ジャッジ日時 2023-10-11 10:02:50
合計ジャッジ時間 6,261 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,352 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 1 ms
4,352 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,352 KB
testcase_14 AC 1 ms
4,352 KB
testcase_15 AC 1 ms
4,352 KB
testcase_16 AC 1 ms
4,352 KB
testcase_17 AC 1 ms
4,352 KB
testcase_18 AC 1 ms
4,352 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 1 ms
4,352 KB
testcase_21 AC 1 ms
4,352 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,356 KB
testcase_24 AC 2 ms
4,352 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,356 KB
testcase_27 AC 2 ms
4,352 KB
testcase_28 AC 2 ms
4,352 KB
testcase_29 AC 2 ms
4,352 KB
testcase_30 AC 2 ms
4,352 KB
testcase_31 AC 2 ms
4,352 KB
testcase_32 AC 1 ms
4,352 KB
testcase_33 AC 2 ms
4,352 KB
testcase_34 AC 1 ms
4,356 KB
testcase_35 AC 2 ms
4,352 KB
testcase_36 AC 2 ms
4,352 KB
testcase_37 AC 2 ms
4,356 KB
testcase_38 AC 2 ms
4,352 KB
testcase_39 AC 2 ms
4,348 KB
testcase_40 AC 2 ms
4,352 KB
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,356 KB
testcase_45 AC 2 ms
4,352 KB
testcase_46 AC 2 ms
4,348 KB
testcase_47 AC 2 ms
4,348 KB
testcase_48 AC 2 ms
4,352 KB
testcase_49 AC 2 ms
4,352 KB
testcase_50 AC 2 ms
4,348 KB
testcase_51 AC 3 ms
4,352 KB
testcase_52 AC 2 ms
4,352 KB
testcase_53 AC 2 ms
4,352 KB
testcase_54 AC 2 ms
4,352 KB
testcase_55 AC 20 ms
8,216 KB
testcase_56 AC 22 ms
4,520 KB
testcase_57 AC 39 ms
9,068 KB
testcase_58 AC 17 ms
5,896 KB
testcase_59 AC 26 ms
8,220 KB
testcase_60 AC 16 ms
5,664 KB
testcase_61 AC 34 ms
8,744 KB
testcase_62 AC 35 ms
8,744 KB
testcase_63 AC 35 ms
8,720 KB
testcase_64 AC 20 ms
8,120 KB
testcase_65 AC 38 ms
8,540 KB
testcase_66 AC 38 ms
9,068 KB
testcase_67 AC 29 ms
8,300 KB
testcase_68 AC 26 ms
8,160 KB
testcase_69 AC 34 ms
8,492 KB
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 AC 30 ms
8,172 KB
testcase_85 AC 5 ms
4,352 KB
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;
#define double long double
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[ dq.size() - 2 ], dq[ dq.size() - 1 ], newl ) ) {
      dq.pop_back();
    }
    dq.emplace_back( newl );
  }
  double ans = 1e16;
  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