結果

問題 No.1676 Coin Trade (Single)
ユーザー tko919tko919
提出日時 2021-09-11 01:39:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 100 ms / 2,000 ms
コード長 880 bytes
コンパイル時間 2,995 ms
コンパイル使用メモリ 204,772 KB
実行使用メモリ 8,308 KB
最終ジャッジ日時 2023-09-03 18:26:05
合計ジャッジ時間 6,801 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 76 ms
6,740 KB
testcase_04 AC 70 ms
6,408 KB
testcase_05 AC 64 ms
5,900 KB
testcase_06 AC 66 ms
6,072 KB
testcase_07 AC 56 ms
5,552 KB
testcase_08 AC 35 ms
4,384 KB
testcase_09 AC 54 ms
5,092 KB
testcase_10 AC 57 ms
5,412 KB
testcase_11 AC 78 ms
7,056 KB
testcase_12 AC 45 ms
4,748 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 99 ms
8,252 KB
testcase_34 AC 98 ms
8,308 KB
testcase_35 AC 99 ms
8,264 KB
testcase_36 AC 99 ms
8,304 KB
testcase_37 AC 100 ms
8,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
using ll=long long int;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}



int main(){
   int n,k;
   cin>>n>>k;
   vector g(n,vector<int>());
   vector<int> a(n);
   rep(i,0,n){
      int m;
      cin>>a[i]>>m;
      rep(j,0,m){
         int p;
         cin>>p;
         g[p-1].push_back(i);
      }
   }

   vector<ll> dp(n,-INF);
   dp[0]=0;
   rep(i,0,n){
      if(i!=n-1)chmax(dp[i+1],dp[i]);
      for(auto& to:g[i])chmax(dp[to],dp[i]+max(0,a[to]-a[i]));
   }
   cout<<dp[n-1]<<'\n';
   return 0;
}
0