結果

問題 No.1676 Coin Trade (Single)
ユーザー stoqstoq
提出日時 2021-08-05 17:52:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 92 ms / 2,000 ms
コード長 645 bytes
コンパイル時間 1,967 ms
コンパイル使用メモリ 205,408 KB
実行使用メモリ 9,136 KB
最終ジャッジ日時 2023-09-02 15:04:46
合計ジャッジ時間 5,763 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 69 ms
7,236 KB
testcase_04 AC 61 ms
6,672 KB
testcase_05 AC 57 ms
6,256 KB
testcase_06 AC 58 ms
6,144 KB
testcase_07 AC 50 ms
5,516 KB
testcase_08 AC 31 ms
4,380 KB
testcase_09 AC 48 ms
5,388 KB
testcase_10 AC 51 ms
5,652 KB
testcase_11 AC 68 ms
7,560 KB
testcase_12 AC 39 ms
4,560 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 91 ms
9,088 KB
testcase_34 AC 92 ms
9,088 KB
testcase_35 AC 90 ms
9,136 KB
testcase_36 AC 86 ms
9,020 KB
testcase_37 AC 90 ms
9,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < int(n); i++)

inline bool chmax(ll &a, ll b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> a(n);
  vector<int> m(n);
  vector<vector<int>> b(n);
  rep(i, n) {
    cin >> a[i] >> m[i];
    b[i].resize(m[i]);
    rep(j, m[i]) cin >> b[i][j], b[i][j]--;
  }
  vector<ll> dp(n, 0);
  for (int i = 1; i < n; i++) {
    chmax(dp[i], dp[i - 1]);
    for (auto j : b[i]) chmax(dp[i], dp[j] + a[i] - a[j]);
  }
  cout << dp[n - 1] << "\n";
}
0