結果

問題 No.161 制限ジャンケン
ユーザー 14番14番
提出日時 2016-04-27 22:34:43
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 3,476 bytes
コンパイル時間 928 ms
コンパイル使用メモリ 110,948 KB
実行使用メモリ 83,580 KB
最終ジャッジ日時 2024-04-15 04:36:09
合計ジャッジ時間 4,429 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
29,976 KB
testcase_01 AC 31 ms
26,204 KB
testcase_02 AC 30 ms
24,184 KB
testcase_03 AC 31 ms
22,068 KB
testcase_04 AC 31 ms
24,296 KB
testcase_05 AC 29 ms
24,304 KB
testcase_06 WA -
testcase_07 AC 30 ms
24,308 KB
testcase_08 AC 701 ms
77,196 KB
testcase_09 AC 30 ms
26,460 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 462 ms
45,568 KB
testcase_14 AC 118 ms
34,800 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 60 ms
28,384 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.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;
            }
        }
        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 = @"





7 6 5
GCPGPCPGGGPCCCGPGP



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