結果

問題 No.2434 RAKUTAN de RAKUTAN
ユーザー Astral__Astral__
提出日時 2023-08-12 12:07:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,653 bytes
コンパイル時間 1,980 ms
コンパイル使用メモリ 208,536 KB
実行使用メモリ 814,376 KB
最終ジャッジ日時 2024-04-30 11:15:06
合計ジャッジ時間 3,899 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

int main() {
  int N, H, X;
  cin >> N >> H >> X;
  int G, B;
  cin >> G;
  vector<int> old(N+1, 0);//変換前のマス。0なら授業、1なら得単、-1なら落単
  vector<int> g(G+1);
  for(int i = 1; i <= G; i++) {
    cin >> g[i];
    old[g[i]] = 1;
  }
  cin >> B;
  vector<int> b(B+1);
  for(int i = 1; i <= B; i++) {
    cin >> b[i];
    old[b[i]] = -1;
  }
  
  H = min(H, B); //リープする回数はせいぜいB回

  vector<int> count(N+1, 0);//iマス目の周辺に落単マスがあるならばcount[i]は1以上
  for(int i = 1; i <= N; i++) {
    if(old[i] == -1) {
      int l = max(0, i-X);
      int r = min(N, i+X);
      for(int j = l; j <= r; j++) {
        count[j]++;
      }
    }
  }

  vector<int> nw(1, 0);//変換後のマスの情報
  for(int i = 1; i <= N; i++) {
    if(count.at(i) != 0) {
      nw.push_back(old[i]);
    }
    else {
      int sum = 0;
      sum += old[i];
      while(i + 1 <= N && count[i+1] == 0) {
        i++;
        sum += old.at(i);
      }
      nw.push_back(sum);
    }
  }

  int N1 = nw.size() - 1;//変換後のマス目数
  vector<vector<int>> dp(N1+1, vector<int>(H+1, -100100100));
  dp.at(0).at(H) = 0;

  for(int i = 1; i <= N1; i++) {
    for(int j = 0; j <= H; j++) {
       if(j != H && i >= X) {
        dp[i][j] = max(dp[i][j], dp[i-X][j+1] + nw[i]);
       }
       dp[i][j] = max(dp[i][j], dp[i-1][j] + nw[i]);
    }
  }

  int ans = -100100100;//単位の数はマイナスを取りうることに注意してください。
  for (int j = 0; j <= H; j++) {
    ans = max(ans, dp[N1][j]);
  }

  cout << ans << endl;
}

0