結果

問題 No.844 split game
ユーザー torisasami4torisasami4
提出日時 2019-06-28 22:06:28
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 117 ms / 2,000 ms
コード長 3,591 bytes
コンパイル時間 1,762 ms
コンパイル使用メモリ 77,768 KB
実行使用メモリ 14,488 KB
最終ジャッジ日時 2023-09-14 22:01:56
合計ジャッジ時間 5,433 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
10,080 KB
testcase_01 AC 36 ms
12,132 KB
testcase_02 AC 90 ms
11,876 KB
testcase_03 AC 66 ms
12,576 KB
testcase_04 AC 36 ms
9,952 KB
testcase_05 AC 103 ms
13,084 KB
testcase_06 AC 34 ms
9,920 KB
testcase_07 AC 28 ms
11,588 KB
testcase_08 AC 19 ms
9,024 KB
testcase_09 AC 77 ms
10,076 KB
testcase_10 AC 110 ms
12,824 KB
testcase_11 AC 106 ms
13,916 KB
testcase_12 AC 74 ms
10,044 KB
testcase_13 AC 48 ms
9,392 KB
testcase_14 AC 47 ms
11,280 KB
testcase_15 AC 117 ms
14,044 KB
testcase_16 AC 116 ms
14,072 KB
testcase_17 AC 116 ms
14,104 KB
testcase_18 AC 116 ms
14,100 KB
testcase_19 AC 115 ms
14,072 KB
testcase_20 AC 115 ms
14,160 KB
testcase_21 AC 115 ms
14,488 KB
testcase_22 AC 117 ms
14,228 KB
testcase_23 AC 8 ms
8,032 KB
testcase_24 AC 12 ms
8,356 KB
testcase_25 AC 8 ms
7,480 KB
testcase_26 AC 6 ms
8,000 KB
testcase_27 AC 10 ms
8,060 KB
testcase_28 AC 5 ms
8,032 KB
testcase_29 AC 10 ms
8,236 KB
testcase_30 AC 11 ms
8,300 KB
testcase_31 AC 10 ms
8,160 KB
testcase_32 AC 6 ms
7,860 KB
testcase_33 AC 12 ms
8,068 KB
testcase_34 AC 9 ms
8,220 KB
testcase_35 AC 14 ms
8,268 KB
testcase_36 AC 10 ms
8,112 KB
testcase_37 AC 20 ms
8,324 KB
testcase_38 AC 34 ms
9,184 KB
testcase_39 AC 69 ms
10,568 KB
testcase_40 AC 24 ms
10,304 KB
testcase_41 AC 5 ms
7,416 KB
testcase_42 AC 5 ms
7,584 KB
testcase_43 AC 4 ms
7,680 KB
testcase_44 AC 5 ms
7,716 KB
testcase_45 AC 5 ms
7,692 KB
testcase_46 AC 5 ms
7,752 KB
testcase_47 AC 5 ms
7,644 KB
testcase_48 AC 5 ms
7,772 KB
testcase_49 AC 4 ms
7,524 KB
testcase_50 AC 5 ms
7,592 KB
testcase_51 AC 4 ms
7,636 KB
testcase_52 AC 4 ms
7,464 KB
testcase_53 AC 5 ms
7,640 KB
testcase_54 AC 4 ms
7,412 KB
testcase_55 AC 4 ms
7,688 KB
testcase_56 AC 4 ms
7,640 KB
testcase_57 AC 4 ms
7,520 KB
testcase_58 AC 5 ms
7,700 KB
testcase_59 AC 5 ms
7,420 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<list>
#include<set>
#include<string>
using namespace std;
int gcd(int a, int b) {
	int c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}
	return b;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};
typedef long long ll;

ll M = 1000000007;

vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)

ll mpow(ll x, ll n) {
	ll ans = 1;
	while (n != 0) {
		if (n & 1) ans = ans * x % M;
		x = x * x % M;
		n = n >> 1;
	}
	return ans;
}
ll comb(ll a, ll b) {
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	ll tmp = ifac[a - b] * ifac[b] % M;
	return tmp * fac[a] % M;
}
// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a) {
	long long b = M, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= M;
	if (u < 0) u += M;
	return u;
}
vector<vector<ll>> mul(vector<vector<ll>> a, vector<vector<ll>> b, int n) {
	int i, j, k, t;
	vector<vector<ll>> c(n);
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			t = 0;
			for (k = 0; k < n; k++)
				t = (t + a[i][k] * b[k][j] % M) % M;
			c[i].push_back(t);
		}
	}
	return c;
}

template< typename Monoid >
struct SegmentTree {

	int sz;
	vector< Monoid > seg;

	const Monoid M1;

	SegmentTree(int n, const Monoid &M1) : M1(M1) {
		sz = 1;
		while (sz < n) sz <<= 1;
		seg.assign(2 * sz, M1);
	}

	void set(int k, const Monoid &x) {
		seg[k + sz] = x;
	}

	void build() {
		for (int k = sz - 1; k > 0; k--) {
			seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
		}
	}

	void update(int k, const Monoid &x) {
		k += sz;
		seg[k] = x;
		while (k >>= 1) {
			seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
		}
	}

	Monoid query(int a, int b) {
		Monoid L = M1, R = M1;
		for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
			if (a & 1) L = f(L, seg[a++]);
			if (b & 1) R = f(seg[--b], R);
		}
		return f(L, R);
	}

	Monoid value(const int &k) const {
		return seg[k + sz];
	}

	Monoid f(Monoid a, Monoid b) {
		return a + b;
	}
};

int main() {
	ll n, m, a, dp[111111][2], l, r, p, i;
	cin >> n >> m >> a;
	vector<vector<pair<ll, ll>>> v(n + 3);
	for (i = 0; i < m; i++) {
		cin >> l >> r >> p;
		v[r].push_back(make_pair(l, p));
	}
	dp[0][0] = 0;
	dp[0][1] = 0;
	for (i = 1; i <= n; i++) {
		if (i < n) {
			dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
			dp[i][1] = dp[i][0] - a;
			for (auto &e : v[i]) {
				dp[i][1] = max(dp[i][1], e.second - a + dp[e.first - 1][1]);
			}
		}
		else {
			dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
			dp[i][1] = dp[i][0];
			for (auto &e : v[i]) {
				dp[i][1] = max(dp[i][1], e.second+ dp[e.first - 1][1]);
			}
		}
	}
	cout << max(dp[n][0], dp[n][1]) << endl;
}
0