結果

問題 No.844 split game
ユーザー kuuso1
提出日時 2019-06-28 22:28:21
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 193 ms / 2,000 ms
コード長 1,969 bytes
コンパイル時間 1,421 ms
コンパイル使用メモリ 107,776 KB
実行使用メモリ 32,128 KB
最終ジャッジ日時 2024-07-02 04:55:13
合計ジャッジ時間 7,302 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 56
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		long Inf = (long) 1e18;
		long[][] dp = new long[2][];
		for(int i=0;i<2;i++) {
			dp[i] = new long[N + 1];
			for(int j=0;j<=N;j++) dp[i][j] = -Inf;
		}
		List<int>[] E = new List<int>[N + 1];
		for(int i=0;i<N+1;i++) E[i] = new List<int>();
		for(int i=0;i<M;i++){
			E[L[i]].Add(i);
		}
		
		dp[1][0] = 0;
		for(int i=0;i<N;i++){
			for(int j=0;j<2;j++){
				if(dp[j][i] == -Inf) continue;
				foreach(var e in E[i]){
					long lose = A;
					if(R[e] + 1 == N) lose -= A;
					if(j == 0) lose += A;
					dp[1][R[e] + 1] = Math.Max(dp[1][R[e] + 1], dp[j][i] + P[e] - lose);
				}
				dp[0][i + 1] = Math.Max(dp[0][i + 1], dp[j][i]);
				dp[1][i + 1] = Math.Max(dp[1][i + 1], dp[j][i] - (i + 1 == N ? 0 : A));
			}
//for(int k=0;k<2;k++) Console.WriteLine("{0};{1}",k,String.Join(" ",dp[k]));
		}
		
		Console.WriteLine(Math.Max(dp[0][N], dp[1][N]));
		
	}
	int N,M;
	long A;
	int[] L,R;
	long[] P;
	public Sol(){
		var d = ria();
		N = d[0]; M = d[1]; A = d[2];
		L = new int[M];
		R = new int[M];
		P = new long[M];
		for(int i=0;i<M;i++){
			d = ria();
			L[i] = d[0] - 1; R[i] = d[1] - 1; P[i] = d[2];
		}
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}
0