結果

問題 No.161 制限ジャンケン
ユーザー 14番14番
提出日時 2016-04-27 22:43:31
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 770 ms / 5,000 ms
コード長 3,769 bytes
コンパイル時間 4,264 ms
コンパイル使用メモリ 107,188 KB
実行使用メモリ 74,260 KB
最終ジャッジ日時 2023-08-20 04:50:22
合計ジャッジ時間 9,358 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 104 ms
26,664 KB
testcase_01 AC 63 ms
20,648 KB
testcase_02 AC 65 ms
22,680 KB
testcase_03 AC 65 ms
20,732 KB
testcase_04 AC 62 ms
20,828 KB
testcase_05 AC 64 ms
20,596 KB
testcase_06 AC 766 ms
74,108 KB
testcase_07 AC 64 ms
20,648 KB
testcase_08 AC 770 ms
74,260 KB
testcase_09 AC 66 ms
20,844 KB
testcase_10 AC 120 ms
27,184 KB
testcase_11 AC 113 ms
26,804 KB
testcase_12 AC 90 ms
22,684 KB
testcase_13 AC 524 ms
42,400 KB
testcase_14 AC 160 ms
29,584 KB
testcase_15 AC 270 ms
37,328 KB
testcase_16 AC 112 ms
28,792 KB
testcase_17 AC 93 ms
26,756 KB
testcase_18 AC 97 ms
24,756 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;
            }
        }
        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 100
GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG



 
";
        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