結果

問題 No.291 黒い文字列
ユーザー kuuso1kuuso1
提出日時 2015-10-17 11:29:59
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 512 ms / 2,000 ms
コード長 3,284 bytes
コンパイル時間 3,952 ms
コンパイル使用メモリ 106,872 KB
実行使用メモリ 45,684 KB
最終ジャッジ日時 2023-09-29 16:01:18
合計ジャッジ時間 11,838 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
29,020 KB
testcase_01 AC 72 ms
26,012 KB
testcase_02 AC 107 ms
26,496 KB
testcase_03 AC 91 ms
29,648 KB
testcase_04 AC 72 ms
26,116 KB
testcase_05 AC 90 ms
27,796 KB
testcase_06 AC 102 ms
30,560 KB
testcase_07 AC 80 ms
27,140 KB
testcase_08 AC 82 ms
29,096 KB
testcase_09 AC 69 ms
28,056 KB
testcase_10 AC 178 ms
32,024 KB
testcase_11 AC 140 ms
32,468 KB
testcase_12 AC 141 ms
30,496 KB
testcase_13 AC 72 ms
25,988 KB
testcase_14 AC 108 ms
30,508 KB
testcase_15 AC 90 ms
29,588 KB
testcase_16 AC 418 ms
39,668 KB
testcase_17 AC 423 ms
39,676 KB
testcase_18 AC 422 ms
41,816 KB
testcase_19 AC 446 ms
41,564 KB
testcase_20 AC 455 ms
41,708 KB
testcase_21 AC 410 ms
41,676 KB
testcase_22 AC 460 ms
43,760 KB
testcase_23 AC 512 ms
45,684 KB
testcase_24 AC 446 ms
43,684 KB
testcase_25 AC 420 ms
41,612 KB
testcase_26 AC 416 ms
41,632 KB
testcase_27 AC 461 ms
43,768 KB
testcase_28 AC 415 ms
43,692 KB
testcase_29 AC 408 ms
41,712 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][][][];
		for(int i=0;i<21;i++){
			dp[i]=new int[21][][];
			for(int j=0;j<21;j++){
				dp[i][j]=new int[21][];
				for(int k=0;k<21;k++){
					dp[i][j][k]=new int[21];
					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][][][];
			for(int i=0;i<21;i++){
				dnxt[i]=new int[21][][];
				for(int j=0;j<21;j++){
					dnxt[i][j]=new int[21][];
					for(int k=0;k<21;k++){
						dnxt[i][j][k]=new int[21];
						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;
							}
						}
					}
				}
			}
			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]=dnxt[i][j][k][l];
						}
					}
				}
			}
		}
		
		int max=0;
		foreach(var a in dp)foreach(var b in a)foreach(var c in b)foreach(var x in c)max=Math.Max(max,x);
		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