結果

問題 No.1676 Coin Trade (Single)
ユーザー chocoruskchocorusk
提出日時 2021-08-01 20:50:29
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 91 ms / 2,000 ms
コード長 1,165 bytes
コンパイル時間 3,629 ms
コンパイル使用メモリ 188,356 KB
実行使用メモリ 9,968 KB
最終ジャッジ日時 2023-09-02 14:59:25
合計ジャッジ時間 6,076 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
8,100 KB
testcase_01 AC 3 ms
6,664 KB
testcase_02 AC 3 ms
6,736 KB
testcase_03 AC 70 ms
9,216 KB
testcase_04 AC 65 ms
9,024 KB
testcase_05 AC 60 ms
8,776 KB
testcase_06 AC 61 ms
8,716 KB
testcase_07 AC 53 ms
8,732 KB
testcase_08 AC 34 ms
7,012 KB
testcase_09 AC 51 ms
8,516 KB
testcase_10 AC 54 ms
8,136 KB
testcase_11 AC 72 ms
9,524 KB
testcase_12 AC 43 ms
8,472 KB
testcase_13 AC 3 ms
6,592 KB
testcase_14 AC 4 ms
7,348 KB
testcase_15 AC 3 ms
7,056 KB
testcase_16 AC 3 ms
6,032 KB
testcase_17 AC 3 ms
6,760 KB
testcase_18 AC 3 ms
7,008 KB
testcase_19 AC 3 ms
6,336 KB
testcase_20 AC 3 ms
7,512 KB
testcase_21 AC 3 ms
7,552 KB
testcase_22 AC 3 ms
6,924 KB
testcase_23 AC 3 ms
6,324 KB
testcase_24 AC 4 ms
7,084 KB
testcase_25 AC 4 ms
7,244 KB
testcase_26 AC 3 ms
7,960 KB
testcase_27 AC 4 ms
7,600 KB
testcase_28 AC 3 ms
6,620 KB
testcase_29 AC 3 ms
6,648 KB
testcase_30 AC 3 ms
6,800 KB
testcase_31 AC 3 ms
6,404 KB
testcase_32 AC 3 ms
6,620 KB
testcase_33 AC 91 ms
9,816 KB
testcase_34 AC 91 ms
9,828 KB
testcase_35 AC 91 ms
9,848 KB
testcase_36 AC 91 ms
9,852 KB
testcase_37 AC 90 ms
9,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;

int main()
{
	int n, k;
	cin>>n>>k;
	vector<int> g[100010];
	ll a[100010];
	for(int i=0; i<n; i++){
		cin>>a[i];
		int m; cin>>m;
		for(int j=0; j<m; j++){
			int b; cin>>b; b--;
			g[i].push_back(b);
		}
	}
	const ll INF=1e18;
	ll dp[2][100010];
	for(int i=0; i<2; i++) fill(dp[i], dp[i]+n, -INF);
	dp[0][0]=0, dp[1][0]=-a[0];
	ll mx0=0;
	for(int i=1; i<n; i++){
		for(auto j:g[i]){
			dp[1][i]=max(dp[1][i], dp[1][j]);
		}
		dp[0][i]=max(dp[0][i], dp[1][i]+a[i]);
		dp[1][i]=max(dp[1][i], mx0-a[i]);
		mx0=max(mx0, dp[0][i]);
	}
	cout<<mx0<<endl;
    return 0;
}
0