結果

問題 No.324 落ちてた閉路グラフ
ユーザー kuuso1
提出日時 2015-12-17 23:54:51
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 417 ms / 5,000 ms
コード長 2,798 bytes
コンパイル時間 2,679 ms
コンパイル使用メモリ 115,844 KB
実行使用メモリ 90,752 KB
最終ジャッジ日時 2024-11-15 19:34:22
合計ジャッジ時間 5,756 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 34
権限があれば一括ダウンロードができます
コンパイルメッセージ
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(){
if(M==0){
Console.WriteLine(0);return;
}
int[][][] dp=new int[2][][];
for(int i=0;i<2;i++){
dp[i]=new int[N+1][];
for(int j=0;j<=N;j++){
dp[i][j]=new int[M+1];
for(int k=0;k<=M;k++)dp[i][j][k]=-Inf;
}
}
//1
dp[1][0][1]=0;
for(int i=0;i<N-1;i++){
for(int j=0;j<=Math.Min(M,i+1);j++){
dp[0][i+1][j]=Math.Max(dp[0][i+1][j],dp[0][i][j]);
if(j<M)dp[1][i+1][j+1]=Math.Max(dp[1][i+1][j+1],dp[0][i][j]);
dp[0][i+1][j]=Math.Max(dp[0][i+1][j],dp[1][i][j]);
if(j<M)dp[1][i+1][j+1]=Math.Max(dp[1][i+1][j+1],dp[1][i][j]+A[i]);
}
}
for(int j=0;j<=M;j++){
dp[0][N][j]=Math.Max(dp[0][N][j],dp[0][N-1][j]);
dp[1][N][j]=Math.Max(dp[1][N][j],dp[1][N-1][j]+A[N-1]);
}
int ans1=Math.Max(dp[0][N][M],dp[1][N][M]);
//1
for(int i=0;i<2;i++){
for(int j=0;j<=N;j++){
for(int k=0;k<=M;k++)dp[i][j][k]=-Inf;
}
}
dp[0][0][0]=0;
for(int i=0;i<N-1;i++){
for(int j=0;j<=Math.Min(M,i+1);j++){
dp[0][i+1][j]=Math.Max(dp[0][i+1][j],dp[0][i][j]);
if(j<M)dp[1][i+1][j+1]=Math.Max(dp[1][i+1][j+1],dp[0][i][j]);
dp[0][i+1][j]=Math.Max(dp[0][i+1][j],dp[1][i][j]);
if(j<M)dp[1][i+1][j+1]=Math.Max(dp[1][i+1][j+1],dp[1][i][j]+A[i]);
}
}
for(int j=0;j<=M;j++){
dp[0][N][j]=Math.Max(dp[0][N][j],dp[0][N-1][j]);
dp[1][N][j]=Math.Max(dp[1][N][j],dp[1][N-1][j]);
}
int ans0=Math.Max(dp[0][N][M],dp[1][N][M]);
Console.WriteLine(Math.Max(ans0,ans1));
}
int N,M;
int[] A;
static int Inf=(int)1e9;
public Sol(){
var d=ria();
N=d[0];M=d[1];
A=ria();
}
void dbg(int[][][] dp){
for(int m=M;m>=0;m--){
for(int n=0;n<=N;n++){
Console.Write("{0} ",dp[n][m][0]==-Inf?"X":dp[n][m][0].ToString());
}
Console.WriteLine();
for(int n=0;n<=N;n++){
Console.Write("{0} ",dp[n][m][1]==-Inf?"X":dp[n][m][1].ToString());
}
Console.WriteLine();
Console.WriteLine();
}Console.WriteLine();
}
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(){return Console.ReadLine().Split(' ');}
static int[] ria(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>int.Parse(e));}
static long[] rla(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>long.Parse(e));}
static double[] rda(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>double.Parse(e));}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0