結果

問題 No.437 cwwゲーム
ユーザー 14番
提出日時 2016-10-28 23:39:42
言語 C#(csc)
(csc 3.9.0)
結果
RE  
実行時間 -
コード長 2,487 bytes
コンパイル時間 1,090 ms
コンパイル使用メモリ 108,032 KB
実行使用メモリ 19,456 KB
最終ジャッジ日時 2024-11-24 06:32:01
合計ジャッジ時間 3,164 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 RE * 1
other AC * 34 RE * 7
権限があれば一括ダウンロードができます
コンパイルメッセージ
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]);
                ans = Math.Max(ans, this.GetAns(int.Parse(string.Join(string.Empty, tmp)), new int[] {}) + 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 = @"


2718281828



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