結果

問題 No.437 cwwゲーム
ユーザー 14番14番
提出日時 2016-10-28 23:42:35
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 2,598 bytes
コンパイル時間 778 ms
コンパイル使用メモリ 107,776 KB
実行使用メモリ 19,584 KB
最終ジャッジ日時 2024-04-20 13:01:46
合計ジャッジ時間 2,852 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
19,072 KB
testcase_01 AC 22 ms
18,432 KB
testcase_02 AC 26 ms
19,200 KB
testcase_03 AC 24 ms
18,432 KB
testcase_04 AC 25 ms
18,944 KB
testcase_05 AC 24 ms
18,816 KB
testcase_06 AC 26 ms
19,200 KB
testcase_07 AC 28 ms
19,456 KB
testcase_08 AC 26 ms
18,944 KB
testcase_09 AC 27 ms
19,584 KB
testcase_10 AC 27 ms
19,200 KB
testcase_11 AC 23 ms
18,688 KB
testcase_12 AC 25 ms
18,688 KB
testcase_13 AC 27 ms
18,816 KB
testcase_14 AC 25 ms
18,688 KB
testcase_15 AC 27 ms
19,328 KB
testcase_16 AC 27 ms
19,200 KB
testcase_17 AC 26 ms
18,816 KB
testcase_18 AC 26 ms
18,944 KB
testcase_19 AC 25 ms
18,560 KB
testcase_20 AC 25 ms
18,688 KB
testcase_21 AC 25 ms
18,560 KB
testcase_22 AC 25 ms
18,944 KB
testcase_23 AC 25 ms
18,816 KB
testcase_24 AC 25 ms
18,688 KB
testcase_25 AC 26 ms
19,072 KB
testcase_26 AC 26 ms
18,944 KB
testcase_27 AC 24 ms
18,816 KB
testcase_28 AC 26 ms
18,688 KB
testcase_29 AC 23 ms
18,560 KB
testcase_30 AC 21 ms
18,560 KB
testcase_31 AC 24 ms
18,688 KB
testcase_32 AC 22 ms
18,432 KB
testcase_33 AC 26 ms
18,944 KB
testcase_34 AC 26 ms
19,072 KB
testcase_35 AC 26 ms
18,816 KB
testcase_36 AC 21 ms
18,432 KB
testcase_37 AC 20 ms
18,560 KB
testcase_38 AC 24 ms
18,816 KB
testcase_39 AC 22 ms
18,688 KB
testcase_40 AC 26 ms
18,944 KB
testcase_41 AC 27 ms
18,944 KB
testcase_42 AC 25 ms
18,816 KB
testcase_43 AC 26 ms
18,944 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.Linq;
using System.Collections.Generic;

public class Program
{
    public void Proc() {
        Reader.IsDebug = false;
        long ans = GetAns(long.Parse(Reader.ReadLine()), new int[]{});
        Console.WriteLine(ans);
    }

    private Dictionary<long, long> dic = new Dictionary<long, long>();
    

    private long GetAns(long num, int[] idx) {
        if(idx.Length == 0 && dic.ContainsKey(num)) {
            return dic[num];
        }

        long ans = 0;

        string numstr = num.ToString();
        if(numstr.Length + idx.Length < 3) {
            return 0;
        }

        int start = 0;
        if(idx.Length > 0) {
            start = idx.Last() + 1;
        }
        for(int i=start; i<numstr.Length; i++) {
            if(idx.Length == 0) {
                if(numstr[i] == '0') {
                    continue;
                }
                long ret = this.GetAns(num, new int[]{i});
                ans = Math.Max(ans, ret);
            } else if(idx.Length == 1) {
                if(numstr[i] == numstr[idx[0]]) {
                    continue;
                }
                long ret = this.GetAns(num, new int[]{idx[0], i});
                ans = Math.Max(ans, ret);
            } else {
                if(numstr[i] != numstr[idx.Last()]) {
                    continue;
                }
                int addNum = int.Parse(numstr[idx[0]].ToString() + numstr[idx[1]] + numstr[i]);
                List<char> tmp = numstr.ToList();
                tmp.RemoveAt(i);
                tmp.RemoveAt(idx[1]);
                tmp.RemoveAt(idx[0]);
                long ret = 0;
                if(tmp.Count > 0) {
                    ret = this.GetAns(int.Parse(string.Join(string.Empty, tmp)), new int[] {});
                }
                ans = Math.Max(ans, ret + addNum);
            }
        }
        if(idx.Length == 0) {
            dic.Add(num, ans);
        }
        return ans;
    }

    public class Reader {
        public static bool IsDebug = true;
        private static System.IO.StringReader SReader;
        private static string InitText = @"


133144



";
        public static string ReadLine() {
            if(IsDebug) {
                if(SReader == null) {
                    SReader = new System.IO.StringReader(InitText.Trim());
                }
                return SReader.ReadLine();
            } else {
                return Console.ReadLine();
            }
        }
    }
    public static void Main(string[] args)
    {
        Program prg = new Program();
        prg.Proc();
    }
}
0