結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー tonegawatonegawa
提出日時 2020-08-11 01:40:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,555 bytes
コンパイル時間 1,299 ms
コンパイル使用メモリ 109,888 KB
実行使用メモリ 814,592 KB
最終ジャッジ日時 2024-04-17 10:40:35
合計ジャッジ時間 4,075 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 53 ms
34,304 KB
testcase_10 AC 31 ms
20,736 KB
testcase_11 AC 30 ms
21,760 KB
testcase_12 AC 461 ms
272,640 KB
testcase_13 MLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main(int, const char**)':
main.cpp:30:12: warning: overflow in conversion from 'long int' to 'll' {aka 'int'} changes value from '10000000000' to '1410065408' [-Woverflow]
   30 |   ll INF = 10000000000;
      |            ^~~~~~~~~~~

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d>>(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n, k;std::cin >> n >> k;
  vvl d = VV(n, 2, 0, ll);
  re(i, n) std::cin >> d[i][0] >> d[i][1];
  sort(all(d));
  reverse(all(d));
  ll INF = 10000000000;

  //買う->無料交互になるべき
  // dp[i][j][k] := i枚見てj円使ってモードk(0/1)の時の価値最大
  vvvl dp = VVV(n+1, k+1, 2, -INF);
  dp[0][0][0] = 0;
  for(int i=0;i<n;i++){
    vll now = d[i];
    for(int j=0;j<=k;j++){
      //有料モードで購入する
      if(j+now[0]<=k) dp[i+1][j+now[0]][1] = max(dp[i+1][j+now[0]][1], dp[i][j][0]+now[1]);
      //有料モードでパス
      dp[i+1][j][0] = max(dp[i+1][j][0], dp[i][j][0]);
      //無料モードで購入
      dp[i+1][j][0] = max(dp[i+1][j][0], dp[i][j][1]+now[1]);
      //無料モードでパス
      dp[i+1][j][1] = max(dp[i+1][j][1], dp[i][j][1]);
    }
  }
  ll ans = -INF;
  for(int i=0;i<=k;i++){
    ans = max({ans, dp[n][i][0], dp[n][i][1]});
  }
  std::cout << ans << '\n';
  return 0;
}
0