結果

問題 No.1029 JJOOII 3
ユーザー fgwiebfaoishfgwiebfaoish
提出日時 2020-05-23 19:29:48
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 467 ms / 2,000 ms
コード長 4,651 bytes
コンパイル時間 1,237 ms
コンパイル使用メモリ 109,312 KB
実行使用メモリ 24,960 KB
最終ジャッジ日時 2024-04-17 06:54:25
合計ジャッジ時間 8,772 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
19,200 KB
testcase_01 AC 28 ms
19,072 KB
testcase_02 AC 28 ms
19,072 KB
testcase_03 AC 42 ms
19,396 KB
testcase_04 AC 59 ms
20,224 KB
testcase_05 AC 202 ms
24,448 KB
testcase_06 AC 178 ms
24,064 KB
testcase_07 AC 185 ms
24,064 KB
testcase_08 AC 212 ms
24,320 KB
testcase_09 AC 183 ms
23,808 KB
testcase_10 AC 189 ms
24,064 KB
testcase_11 AC 224 ms
24,704 KB
testcase_12 AC 152 ms
23,296 KB
testcase_13 AC 209 ms
24,448 KB
testcase_14 AC 215 ms
24,704 KB
testcase_15 AC 138 ms
23,424 KB
testcase_16 AC 95 ms
20,224 KB
testcase_17 AC 218 ms
24,448 KB
testcase_18 AC 210 ms
24,832 KB
testcase_19 AC 28 ms
19,200 KB
testcase_20 AC 59 ms
20,864 KB
testcase_21 AC 57 ms
20,480 KB
testcase_22 AC 62 ms
20,608 KB
testcase_23 AC 56 ms
20,608 KB
testcase_24 AC 59 ms
20,736 KB
testcase_25 AC 63 ms
20,864 KB
testcase_26 AC 79 ms
22,144 KB
testcase_27 AC 93 ms
22,272 KB
testcase_28 AC 158 ms
23,296 KB
testcase_29 AC 141 ms
23,168 KB
testcase_30 AC 173 ms
23,168 KB
testcase_31 AC 158 ms
23,296 KB
testcase_32 AC 458 ms
24,704 KB
testcase_33 AC 464 ms
24,832 KB
testcase_34 AC 463 ms
24,960 KB
testcase_35 AC 467 ms
24,960 KB
testcase_36 AC 458 ms
24,832 KB
testcase_37 AC 29 ms
19,200 KB
testcase_38 AC 30 ms
19,200 KB
testcase_39 AC 29 ms
18,816 KB
testcase_40 AC 28 ms
18,816 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 t=new Tuple<string,int,int,int,int>[s[0]];
		for(int i = 0;i<s[0];i++) {
			var e=sc.Sa;
			var h=new int[3];
			for(int j = 0;j<e[0].Length;j++) {
				if(e[0][j]=='J'){h[0]++;}
				else if(e[0][j]=='O'){h[1]++;}
				else{h[2]++;}
			}
			t[i]=Tuple.Create(e[0],h[0],h[1],h[2],int.Parse(e[1]));
		}
		long inf=(long)1e18;
		int m=s[1]+83;
		var dp1=Enumerable.Repeat(inf,m).ToArray();
		var dp2=Enumerable.Repeat(inf,m).ToArray();
		var dp3=Enumerable.Repeat(inf,m).ToArray();
		dp1[0]=dp2[0]=dp3[0]=0;
		for(int i = 0;i<s[0];i++) {
			if(t[i].Item2==0){continue;}
			for(int j = t[i].Item2;j<m;j++) {dp1[j]=Min(dp1[j],dp1[j-t[i].Item2]+t[i].Item5);}
		}
		for(int i = 0;i<s[0];i++) {
			if(t[i].Item3==0){continue;}
			for(int j = t[i].Item3;j<m;j++) {dp2[j]=Min(dp2[j],dp2[j-t[i].Item3]+t[i].Item5);}
		}
		for(int i = 0;i<s[0];i++) {
			if(t[i].Item4==0){continue;}
			for(int j = t[i].Item4;j<m;j++) {dp3[j]=Min(dp3[j],dp3[j-t[i].Item4]+t[i].Item5);}
		}
		for(int i = m-2;i>0;i--) {
			dp1[i]=Min(dp1[i],dp1[i+1]);
			dp2[i]=Min(dp2[i],dp2[i+1]);
			dp3[i]=Min(dp3[i],dp3[i+1]);
		}
		long ans=dp1[s[1]]+dp2[s[1]]+dp3[s[1]];
		for(int i = 0;i<s[0];i++) {
			var g=t[i].Item1;
			var h=new int[3];
			for(int k = 0;k<g.Length;k++) {
				if(g[k]=='J'){h[0]++;}
				else if(g[k]=='O'){h[1]++;}
				else{h[2]++;}
				if(g[k]!='J'){continue;}
				for(int j = 0;j<s[0];j++) {
					var f=t[j].Item1;
					var d=new int[3];
					for(int l = 0;l<f.Length;l++) {
						if(f[l]=='J'){d[0]++;}
						else if(f[l]=='O'){d[1]++;}
						else{d[2]++;}
						ans=Min(ans,dp1[Max(0,s[1]-h[0])]+dp2[Max(0,s[1]-t[i].Item3+h[1]-d[1])]+dp3[Max(0,s[1]-t[j].Item4+d[2])]+t[i].Item5+t[j].Item5);
					}
				}
				if(t[i].Item3-h[1]>=s[1]){
					var d=new int[3];
					for(int j = g.Length-1;j>k;j--) {
						if(g[j]=='J'){d[0]++;}
						else if(g[j]=='O'){d[1]++;}
						else{d[2]++;}
						if(t[i].Item3-h[1]-d[1]>=s[1]){ans=Min(ans,dp1[Max(0,s[1]-h[0])]+dp3[Max(0,s[1]-d[2])]+t[i].Item5);}
						else{break;}
					}
				}
			}
		}
		Console.WriteLine("{0}",ans>=inf?-1:ans);
	}
}

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(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),double.Parse);}
	public double[] Da3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).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