結果

問題 No.291 黒い文字列
ユーザー kuuso1kuuso1
提出日時 2015-10-17 11:21:05
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 1,030 ms / 2,000 ms
コード長 2,771 bytes
コンパイル時間 2,777 ms
コンパイル使用メモリ 110,664 KB
実行使用メモリ 44,252 KB
最終ジャッジ日時 2023-09-29 15:59:35
合計ジャッジ時間 16,703 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
27,272 KB
testcase_01 AC 89 ms
26,716 KB
testcase_02 AC 152 ms
34,212 KB
testcase_03 AC 120 ms
28,336 KB
testcase_04 AC 89 ms
26,492 KB
testcase_05 AC 120 ms
28,332 KB
testcase_06 AC 161 ms
30,724 KB
testcase_07 AC 101 ms
26,164 KB
testcase_08 AC 108 ms
24,756 KB
testcase_09 AC 81 ms
25,816 KB
testcase_10 AC 278 ms
40,004 KB
testcase_11 AC 210 ms
41,832 KB
testcase_12 AC 210 ms
41,820 KB
testcase_13 AC 86 ms
24,712 KB
testcase_14 AC 149 ms
32,316 KB
testcase_15 AC 118 ms
30,512 KB
testcase_16 AC 717 ms
42,000 KB
testcase_17 AC 737 ms
42,160 KB
testcase_18 AC 722 ms
44,220 KB
testcase_19 AC 812 ms
42,032 KB
testcase_20 AC 852 ms
44,128 KB
testcase_21 AC 695 ms
42,068 KB
testcase_22 AC 865 ms
44,164 KB
testcase_23 AC 1,030 ms
44,252 KB
testcase_24 AC 788 ms
42,060 KB
testcase_25 AC 701 ms
42,020 KB
testcase_26 AC 697 ms
42,036 KB
testcase_27 AC 689 ms
42,092 KB
testcase_28 AC 691 ms
44,028 KB
testcase_29 AC 693 ms
42,108 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;
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(){
		
		int N=S.Length;
		int[,,,] dp=new int[21,21,21,21];
		for(int i=0;i<21;i++){
			for(int j=0;j<21;j++){
				for(int k=0;k<21;k++){
					for(int l=0;l<21;l++){
						dp[i,j,k,l]=-1;
					}
				}
			}
		}
		dp[0,0,0,0]=0;
		for(int c=0;c<N;c++){
			int[,,,] dnxt=new int[21,21,21,21];
			for(int i=0;i<21;i++){
				for(int j=0;j<21;j++){
					for(int k=0;k<21;k++){
						for(int l=0;l<21;l++){
							dnxt[i,j,k,l]=dp[i,j,k,l];
						}
					}
				}
			}
			for(int i=0;i<21;i++){
				for(int j=0;j<21;j++){
					for(int k=0;k<21;k++){
						for(int l=0;l<21;l++){
							if(dp[i,j,k,l]==-1)continue;
							switch(S[c]){
								case 'K':if(i+1<21)dnxt[i+1,j,k,l]=Math.Max(dnxt[i+1,j,k,l],dp[i,j,k,l]);break;
								case 'U':if(j+1<21&&i-1>=0)dnxt[i-1,j+1,k,l]=Math.Max(dnxt[i-1,j+1,k,l],dp[i,j,k,l]);break;
								case 'R':if(k+1<21&&j-1>=0)dnxt[i,j-1,k+1,l]=Math.Max(dnxt[i,j-1,k+1,l],dp[i,j,k,l]);break;
								case 'O':if(l+1<21&&k-1>=0)dnxt[i,j,k-1,l+1]=Math.Max(dnxt[i,j,k-1,l+1],dp[i,j,k,l]);break;
								case 'I':if(l-1>=0)dnxt[i,j,k,l-1]=Math.Max(dnxt[i,j,k,l-1],dp[i,j,k,l]+1);break;
								case '?':
									if(i+1<21)dnxt[i+1,j,k,l]=Math.Max(dnxt[i+1,j,k,l],dp[i,j,k,l]);
									if(j+1<21&&i-1>=0)dnxt[i-1,j+1,k,l]=Math.Max(dnxt[i-1,j+1,k,l],dp[i,j,k,l]);
									if(k+1<21&&j-1>=0)dnxt[i,j-1,k+1,l]=Math.Max(dnxt[i,j-1,k+1,l],dp[i,j,k,l]);
									if(l+1<21&&k-1>=0)dnxt[i,j,k-1,l+1]=Math.Max(dnxt[i,j,k-1,l+1],dp[i,j,k,l]);
									if(l-1>=0)dnxt[i,j,k,l-1]=Math.Max(dnxt[i,j,k,l-1],dp[i,j,k,l]+1);
									break;
								default:dnxt[i,j,k,l]=dp[i,j,k,l];
									break;
							}
						}
					}
				}
			}
			dp=dnxt;
		}
		
		int max=0;
		foreach(var k in dp)max=Math.Max(max,k);
		Console.WriteLine(max);
		
		
	}
	String S;
	public Sol(){
		S=rs();
	}

	struct ATMTN{
		public int K,U,R,O,I;
		public ATMTN(int k,int u,int r,int o,int i){
			K=k;U=u;R=r;O=o;I=i;
		}
		public ATMTN(ATMTN a){
			K=a.K;U=a.U;R=a.R;O=a.O;I=a.I;
		}
	}


	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));}
}
0