結果

問題 No.844 split game
ユーザー GrenacheGrenache
提出日時 2019-06-29 11:17:32
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,144 ms / 2,000 ms
コード長 2,284 bytes
コンパイル時間 4,147 ms
コンパイル使用メモリ 76,272 KB
実行使用メモリ 73,928 KB
最終ジャッジ日時 2023-09-14 23:05:42
合計ジャッジ時間 37,178 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 679 ms
64,728 KB
testcase_01 AC 638 ms
66,884 KB
testcase_02 AC 984 ms
68,800 KB
testcase_03 AC 876 ms
70,912 KB
testcase_04 AC 598 ms
62,504 KB
testcase_05 AC 1,051 ms
70,900 KB
testcase_06 AC 608 ms
63,148 KB
testcase_07 AC 536 ms
62,872 KB
testcase_08 AC 440 ms
60,612 KB
testcase_09 AC 913 ms
66,708 KB
testcase_10 AC 1,081 ms
70,932 KB
testcase_11 AC 1,060 ms
71,232 KB
testcase_12 AC 903 ms
67,204 KB
testcase_13 AC 677 ms
65,124 KB
testcase_14 AC 717 ms
66,320 KB
testcase_15 AC 1,088 ms
71,320 KB
testcase_16 AC 1,113 ms
71,364 KB
testcase_17 AC 1,144 ms
73,928 KB
testcase_18 AC 1,097 ms
71,420 KB
testcase_19 AC 1,135 ms
73,376 KB
testcase_20 AC 1,131 ms
73,864 KB
testcase_21 AC 1,123 ms
71,740 KB
testcase_22 AC 1,139 ms
73,372 KB
testcase_23 AC 272 ms
59,640 KB
testcase_24 AC 359 ms
60,356 KB
testcase_25 AC 299 ms
60,204 KB
testcase_26 AC 242 ms
59,732 KB
testcase_27 AC 337 ms
60,220 KB
testcase_28 AC 220 ms
59,456 KB
testcase_29 AC 314 ms
59,992 KB
testcase_30 AC 336 ms
60,120 KB
testcase_31 AC 333 ms
60,044 KB
testcase_32 AC 226 ms
58,968 KB
testcase_33 AC 380 ms
60,140 KB
testcase_34 AC 325 ms
60,144 KB
testcase_35 AC 389 ms
60,176 KB
testcase_36 AC 333 ms
60,184 KB
testcase_37 AC 453 ms
60,060 KB
testcase_38 AC 579 ms
60,816 KB
testcase_39 AC 835 ms
66,556 KB
testcase_40 AC 477 ms
62,884 KB
testcase_41 AC 130 ms
55,592 KB
testcase_42 AC 129 ms
55,300 KB
testcase_43 AC 130 ms
55,708 KB
testcase_44 AC 137 ms
55,428 KB
testcase_45 AC 130 ms
55,392 KB
testcase_46 AC 128 ms
55,584 KB
testcase_47 AC 132 ms
55,324 KB
testcase_48 AC 135 ms
55,492 KB
testcase_49 AC 129 ms
55,824 KB
testcase_50 AC 129 ms
55,628 KB
testcase_51 AC 129 ms
53,496 KB
testcase_52 AC 127 ms
55,700 KB
testcase_53 AC 130 ms
55,696 KB
testcase_54 AC 134 ms
55,404 KB
testcase_55 AC 141 ms
55,872 KB
testcase_56 AC 134 ms
55,660 KB
testcase_57 AC 137 ms
55,704 KB
testcase_58 AC 132 ms
55,716 KB
testcase_59 AC 142 ms
55,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;


public class Main_yukicoder844 {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int n = sc.nextInt();
		int m = sc.nextInt();
		int a = sc.nextInt();

		List<List<Pair>> edges = new ArrayList<>(n);
		for (int i = 0; i < n; i++) {
			edges.add(new ArrayList<>());
		}
		for (int i = 0; i < m; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			int p = sc.nextInt();
			
			edges.get(l - 1).add(new Pair(r, p));
		}

		long[][] dp = new long[2][n + 1];
//		Arrays.fill(dp[0], Long.MIN_VALUE);
//		Arrays.fill(dp[1], Long.MIN_VALUE);
//		dp[0][n] = dp[1][n] = 0;
		for (int i = n - 1; i > 0; i--) {
			dp[0][i] = Math.max(dp[0][i + 1], dp[1][i + 1]);
			dp[1][i] = Math.max(dp[0][i + 1] - a, dp[1][i + 1] - a);
			for (Pair e : edges.get(i)) {
				dp[1][i] = Math.max(dp[1][i], dp[1][e.a] + e.b - a);
			}
		}
		
		dp[1][0] = Math.max(dp[0][1], dp[1][1]);
		for (Pair e : edges.get(0)) {
			dp[1][0] = Math.max(dp[1][0], dp[1][e.a] + e.b);
		}

		pr.println(dp[1][0]);
	}

	static class Pair implements Comparable<Pair> {
		int a;
		int b;

		Pair(int a, int b) {
			this.a = a;
			this.b = b;
		}

		@Override
		public int compareTo(Pair o) {
			int result = Integer.compare(a, o.a);
			if (result == 0) {
				result = Integer.compare(b, o.b);
			}
			return result;
		}

		@Override
		public int hashCode() {
			final int prime = 31;
			int result = a;
			result = prime * result + b;
			return result;
		}

		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (!(obj instanceof Pair))
				return false;

			Pair o = (Pair) obj;
			return a == o.a && b == o.b;
		}

		@Override
		public String toString() {
			//			Pair [xxx, xxxx]
			StringBuilder stmp = new StringBuilder(32);
			stmp.append("Pair [");
			stmp.append(a);
			stmp.append(',');
			stmp.append(' ');
			stmp.append(b);
			stmp.append(']');

			return stmp.toString();
		}
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);
			
		solve();
			
		pr.close();
		sc.close();
	}

	static class Printer extends PrintWriter {
		Printer(OutputStream out) {
			super(out);
		}
	}
}
0