結果

問題 No.161 制限ジャンケン
ユーザー 14番14番
提出日時 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
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
23,680 KB
testcase_01 AC 29 ms
18,176 KB
testcase_02 AC 28 ms
18,048 KB
testcase_03 AC 29 ms
18,048 KB
testcase_04 AC 26 ms
18,048 KB
testcase_05 AC 27 ms
18,048 KB
testcase_06 AC 718 ms
71,424 KB
testcase_07 AC 27 ms
17,920 KB
testcase_08 AC 716 ms
71,296 KB
testcase_09 AC 27 ms
18,304 KB
testcase_10 AC 82 ms
24,064 KB
testcase_11 AC 76 ms
23,680 KB
testcase_12 AC 52 ms
20,608 KB
testcase_13 AC 489 ms
39,552 KB
testcase_14 AC 122 ms
26,368 KB
testcase_15 AC 233 ms
34,432 KB
testcase_16 AC 75 ms
23,552 KB
testcase_17 AC 58 ms
23,680 KB
testcase_18 AC 62 ms
21,248 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