結果
問題 | No.161 制限ジャンケン |
ユーザー |
![]() |
提出日時 | 2016-04-27 22:43:31 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 718 ms / 5,000 ms |
コード長 | 3,769 bytes |
コンパイル時間 | 1,002 ms |
コンパイル使用メモリ | 113,516 KB |
実行使用メモリ | 71,424 KB |
最終ジャッジ日時 | 2024-11-30 04:52:32 |
合計ジャッジ時間 | 4,591 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;using System.Collections.Generic;using System.Text;using System.Linq;class Program{public void Proc(){Reader.IsDebug = false;int[] inpt = Reader.GetInt();string str = Reader.ReadLine();int ans = this.GetAns(0, str, inpt[0], inpt[1], inpt[2]);Console.WriteLine(ans);}private Dictionary<int, Dictionary<int, Dictionary<int, int>>> dic = new Dictionary<int,Dictionary<int, Dictionary<int, int>>>();private int GetAns(int idx, string str, int g, int c, int p) {if(!dic.ContainsKey(g)) {dic.Add(g, new Dictionary<int,Dictionary<int, int>>());}if(!dic[g].ContainsKey(c)) {dic[g].Add(c, new Dictionary<int, int>());}if(dic[g][c].ContainsKey(p)) {return dic[g][c][p];}int ans = 0;if(idx == str.Length - 1) {Te t = Te.G;if(c > 0) {t = Te.C;} else if(p > 0) {t = Te.P;}ans = this.GetPoint(t, str[idx]);} else {char aite = str[idx];if(g > 0) {ans = Math.Max(ans, this.GetAns(idx + 1, str, g-1, c, p) + this.GetPoint(Te.G, aite));}if(c > 0) {ans = Math.Max(ans, this.GetAns(idx+1, str, g, c-1, p) + this.GetPoint(Te.C, aite));}if(p > 0) {ans = Math.Max(ans, this.GetAns(idx+1, str, g, c, p-1) + this.GetPoint(Te.P, aite));}}this.dic[g][c].Add(p, ans);return ans;}private int GetPoint(Te te, char aite) {if(aite == 'G') {if(te == Te.G) {return 1;} else if(te == Te.P) {return 3;}}else if(aite == 'C') {if(te == Te.C) {return 1;} else if(te == Te.G) {return 3;}} else{if(te ==Te.P ) {return 1;} else if(te == Te.C) {return 3;}}return 0;}public enum Te {G,C,P}public class Reader{public static bool IsDebug = true;private static String PlainInput = @"100 100 100GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG";private static System.IO.StringReader Sr = null;public static string ReadLine(){if (IsDebug){if (Sr == null){Sr = new System.IO.StringReader(PlainInput.Trim());}return Sr.ReadLine();}else{return Console.ReadLine();}}public static int[] GetInt(char delimiter = ' ', bool trim = false){string inptStr = ReadLine();if (trim){inptStr = inptStr.Trim();}string[] inpt = inptStr.Split(delimiter);int[] ret = new int[inpt.Length];for (int i = 0; i < inpt.Length; i++){ret[i] = int.Parse(inpt[i]);}return ret;}}static void Main(){Program prg = new Program();prg.Proc();}}