結果

問題 No.437 cwwゲーム
ユーザー 14番14番
提出日時 2016-10-28 23:42:35
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 2,598 bytes
コンパイル時間 2,185 ms
コンパイル使用メモリ 106,940 KB
実行使用メモリ 23,644 KB
最終ジャッジ日時 2023-08-02 12:56:00
合計ジャッジ時間 6,411 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
21,584 KB
testcase_01 AC 55 ms
21,456 KB
testcase_02 AC 64 ms
21,520 KB
testcase_03 AC 62 ms
21,592 KB
testcase_04 AC 64 ms
21,648 KB
testcase_05 AC 63 ms
21,536 KB
testcase_06 AC 64 ms
21,740 KB
testcase_07 AC 65 ms
19,484 KB
testcase_08 AC 65 ms
21,648 KB
testcase_09 AC 65 ms
23,564 KB
testcase_10 AC 64 ms
21,688 KB
testcase_11 AC 57 ms
23,460 KB
testcase_12 AC 62 ms
21,516 KB
testcase_13 AC 63 ms
21,524 KB
testcase_14 AC 63 ms
23,580 KB
testcase_15 AC 64 ms
21,644 KB
testcase_16 AC 63 ms
21,600 KB
testcase_17 AC 64 ms
23,644 KB
testcase_18 AC 63 ms
21,472 KB
testcase_19 AC 65 ms
23,612 KB
testcase_20 AC 62 ms
19,640 KB
testcase_21 AC 64 ms
23,560 KB
testcase_22 AC 63 ms
23,592 KB
testcase_23 AC 63 ms
21,664 KB
testcase_24 AC 63 ms
21,528 KB
testcase_25 AC 63 ms
21,592 KB
testcase_26 AC 63 ms
21,468 KB
testcase_27 AC 56 ms
21,484 KB
testcase_28 AC 63 ms
23,572 KB
testcase_29 AC 57 ms
21,544 KB
testcase_30 AC 56 ms
21,392 KB
testcase_31 AC 58 ms
23,472 KB
testcase_32 AC 55 ms
23,500 KB
testcase_33 AC 63 ms
19,604 KB
testcase_34 AC 63 ms
21,520 KB
testcase_35 AC 65 ms
21,832 KB
testcase_36 AC 56 ms
21,532 KB
testcase_37 AC 58 ms
23,500 KB
testcase_38 AC 64 ms
23,636 KB
testcase_39 AC 56 ms
21,412 KB
testcase_40 AC 63 ms
21,604 KB
testcase_41 AC 65 ms
21,652 KB
testcase_42 AC 63 ms
19,628 KB
testcase_43 AC 64 ms
21,708 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