結果

問題 No.1199 お菓子配り-2
ユーザー fgwiebfaoishfgwiebfaoish
提出日時 2020-08-29 00:04:22
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 546 ms / 1,000 ms
コード長 3,225 bytes
コンパイル時間 3,171 ms
コンパイル使用メモリ 115,976 KB
実行使用メモリ 42,692 KB
最終ジャッジ日時 2024-04-26 14:54:56
合計ジャッジ時間 19,323 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
19,328 KB
testcase_01 AC 26 ms
19,072 KB
testcase_02 AC 25 ms
19,200 KB
testcase_03 AC 139 ms
31,872 KB
testcase_04 AC 300 ms
40,960 KB
testcase_05 AC 37 ms
20,764 KB
testcase_06 AC 44 ms
22,784 KB
testcase_07 AC 163 ms
35,840 KB
testcase_08 AC 209 ms
40,320 KB
testcase_09 AC 138 ms
33,408 KB
testcase_10 AC 61 ms
24,064 KB
testcase_11 AC 117 ms
31,104 KB
testcase_12 AC 114 ms
31,232 KB
testcase_13 AC 59 ms
25,728 KB
testcase_14 AC 56 ms
23,808 KB
testcase_15 AC 50 ms
23,296 KB
testcase_16 AC 206 ms
41,472 KB
testcase_17 AC 116 ms
29,952 KB
testcase_18 AC 208 ms
37,888 KB
testcase_19 AC 74 ms
23,680 KB
testcase_20 AC 351 ms
40,448 KB
testcase_21 AC 230 ms
39,168 KB
testcase_22 AC 129 ms
23,680 KB
testcase_23 AC 187 ms
32,128 KB
testcase_24 AC 231 ms
39,168 KB
testcase_25 AC 64 ms
25,600 KB
testcase_26 AC 257 ms
40,064 KB
testcase_27 AC 217 ms
40,832 KB
testcase_28 AC 535 ms
42,428 KB
testcase_29 AC 538 ms
42,468 KB
testcase_30 AC 527 ms
42,372 KB
testcase_31 AC 508 ms
42,256 KB
testcase_32 AC 528 ms
42,604 KB
testcase_33 AC 526 ms
42,452 KB
testcase_34 AC 524 ms
42,552 KB
testcase_35 AC 530 ms
42,272 KB
testcase_36 AC 533 ms
42,484 KB
testcase_37 AC 530 ms
42,240 KB
testcase_38 AC 525 ms
42,308 KB
testcase_39 AC 523 ms
42,676 KB
testcase_40 AC 513 ms
42,656 KB
testcase_41 AC 528 ms
42,692 KB
testcase_42 AC 514 ms
42,504 KB
testcase_43 AC 518 ms
42,424 KB
testcase_44 AC 519 ms
42,516 KB
testcase_45 AC 538 ms
42,552 KB
testcase_46 AC 546 ms
42,392 KB
testcase_47 AC 542 ms
42,516 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	const double eps=1e-11;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.Ia;
		var a=new long[s[0]];
		var dp=new long[s[0]];
		for(int i = 0;i<s[0];i++) {a[i]=sc.La.Sum();}
		Spt spt=new Spt(a,false);
		for(int i = s[0]-1;i>=0;i--) {
			dp[i]=a[i];
			for(int j = i+2;j<s[0];j++) {dp[i]=Max(dp[i],a[i]+dp[j]-spt.Get(i+1,j-1));}
		}
		Console.WriteLine("{0}",dp.Max());
	}
}
public class Spt{
	private readonly long[][] d;
	private readonly int[] l;
	private Func<long,long,long> Fu;
	public Spt(long[] a,bool bo){
		int n=a.Length,m=(int)Log(n,2)+1;
		d=new long[m][];
		d[0]=new long[n];
		l=new int[n+1];
		if(bo){Fu=(y,x)=>Max(y,x);}
		else{Fu=(y,x)=>Min(y,x);}
		for(int i=0;i<n;i++){
			d[0][i]=a[i];
			l[i+1]=l[i>>1]+1;
		}
		for(int i=1,k=1;i<m;i++,k<<=1){
			int p=n+1-(k<<1);
			d[i]=new long[p];
			for(int j=0;j<p;j++){d[i][j]=Fu(d[i-1][j],d[i-1][j+k]);}
		}
	}
	public long Get(int a,int b){
		if(a>b){(a,b)=(b,a);}
		int p=l[b-a];
		return Fu(d[p][a],d[p][b+1-(1<<p)]);
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),int.Parse);}
	public int[] Ia3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),long.Parse);}
	public long[] La3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}
0