結果
問題 |
No.437 cwwゲーム
|
ユーザー |
![]() |
提出日時 | 2016-10-28 23:21:11 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,070 bytes |
コンパイル時間 | 2,693 ms |
コンパイル使用メモリ | 108,032 KB |
実行使用メモリ | 19,584 KB |
最終ジャッジ日時 | 2024-11-24 06:20:38 |
合計ジャッジ時間 | 5,218 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 WA * 12 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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())); Console.WriteLine(ans); } private Dictionary<long, long> dic = new Dictionary<long, long>(); private long GetAns(long num) { if(dic.ContainsKey(num)) { return dic[num]; } long ans = 0; string numstr = num.ToString(); if(numstr.Length < 3) { return 0; } for(int i=0; i<numstr.Length - 2; i++) { if(numstr[i] == '0') { continue; } char[] numList = numstr.Skip(i+1).Where(a=>numstr.Skip(i+1).Count(b=>b==a)>1 && a != numstr[i]).ToArray(); numList.ToList().ForEach(a=>{ long newNum = long.Parse(numstr[i].ToString() + a + a); List<char> tmp = numstr.ToList(); tmp.RemoveAt(numstr.IndexOf(a, i)); tmp.RemoveAt(numstr.IndexOf(a, i)); tmp.RemoveAt(i); long ret = 0; if(tmp.Count > 0) { ret = this.GetAns(long.Parse(string.Join(string.Empty, tmp))); } ans = Math.Max(ans, ret + newNum); }); } dic[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(); } }