結果

問題 No.844 split game
ユーザー tkmst201tkmst201
提出日時 2021-02-19 11:21:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 1,197 bytes
コンパイル時間 2,494 ms
コンパイル使用メモリ 207,868 KB
実行使用メモリ 13,104 KB
最終ジャッジ日時 2023-10-14 00:27:48
合計ジャッジ時間 8,198 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
6,676 KB
testcase_01 AC 26 ms
11,048 KB
testcase_02 AC 43 ms
7,652 KB
testcase_03 AC 38 ms
10,636 KB
testcase_04 AC 19 ms
6,340 KB
testcase_05 AC 50 ms
10,932 KB
testcase_06 AC 17 ms
6,504 KB
testcase_07 AC 20 ms
9,668 KB
testcase_08 AC 10 ms
5,552 KB
testcase_09 AC 31 ms
5,352 KB
testcase_10 AC 53 ms
9,848 KB
testcase_11 AC 58 ms
12,404 KB
testcase_12 AC 30 ms
5,020 KB
testcase_13 AC 20 ms
4,696 KB
testcase_14 AC 27 ms
8,976 KB
testcase_15 AC 60 ms
13,104 KB
testcase_16 AC 60 ms
12,768 KB
testcase_17 AC 60 ms
13,080 KB
testcase_18 AC 59 ms
12,940 KB
testcase_19 AC 57 ms
12,796 KB
testcase_20 AC 62 ms
12,784 KB
testcase_21 AC 61 ms
12,880 KB
testcase_22 AC 60 ms
12,936 KB
testcase_23 AC 3 ms
4,352 KB
testcase_24 AC 5 ms
4,348 KB
testcase_25 AC 3 ms
4,348 KB
testcase_26 AC 3 ms
4,352 KB
testcase_27 AC 4 ms
4,352 KB
testcase_28 AC 3 ms
4,348 KB
testcase_29 AC 6 ms
4,352 KB
testcase_30 AC 6 ms
4,352 KB
testcase_31 AC 4 ms
4,348 KB
testcase_32 AC 3 ms
4,352 KB
testcase_33 AC 5 ms
4,352 KB
testcase_34 AC 3 ms
4,348 KB
testcase_35 AC 5 ms
4,348 KB
testcase_36 AC 4 ms
4,352 KB
testcase_37 AC 7 ms
4,352 KB
testcase_38 AC 13 ms
4,352 KB
testcase_39 AC 28 ms
5,540 KB
testcase_40 AC 15 ms
7,984 KB
testcase_41 AC 1 ms
4,352 KB
testcase_42 AC 1 ms
4,348 KB
testcase_43 AC 2 ms
4,352 KB
testcase_44 AC 1 ms
4,352 KB
testcase_45 AC 2 ms
4,352 KB
testcase_46 AC 2 ms
4,348 KB
testcase_47 AC 1 ms
4,352 KB
testcase_48 AC 2 ms
4,348 KB
testcase_49 AC 2 ms
4,352 KB
testcase_50 AC 2 ms
4,356 KB
testcase_51 AC 2 ms
4,352 KB
testcase_52 AC 2 ms
4,352 KB
testcase_53 AC 2 ms
4,352 KB
testcase_54 AC 1 ms
4,348 KB
testcase_55 AC 2 ms
4,352 KB
testcase_56 AC 2 ms
4,352 KB
testcase_57 AC 1 ms
4,352 KB
testcase_58 AC 2 ms
4,352 KB
testcase_59 AC 2 ms
4,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = false;
//---------------------------------//

int main() {
	int N, M, A;
	cin >> N >> M >> A;
	vector ev(N + 1, vector<pii>());
	REP(i, M) {
		int l, r, p;
		scanf("%d %d %d", &l, &r, &p);
		ev[l - 1].emplace_back(r, p);
	}
	vector dp(N + 1, vector<ll>(2, -longINF)); // [i][j] := マス i までで (j: マス i,i-1 に黒線があるかどうか) の得点最大値
	dp[0][1] = 0;
	REP(i, N) {
		chmax(dp[i + 1][0], max(dp[i][0], dp[i][1]));
		for (auto [r, p] : ev[i]) {
			chmax(dp[r][1], dp[i][0] - A + (r == N ? 0 : -A) + p);
			chmax(dp[r][1], dp[i][1] + (r == N ? 0 : -A) + p);
		}
	}
	cout << max(dp[N][0], dp[N][1]) << endl;
}
0