結果
問題 | No.375 立方体のN等分 (1) |
ユーザー | 14番 |
提出日時 | 2016-06-06 01:02:20 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 3,505 bytes |
コンパイル時間 | 4,389 ms |
コンパイル使用メモリ | 106,240 KB |
実行使用メモリ | 17,792 KB |
最終ジャッジ日時 | 2024-10-08 16:17:06 |
合計ジャッジ時間 | 6,173 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 31 ms
17,792 KB |
testcase_01 | AC | 30 ms
17,792 KB |
testcase_02 | RE | - |
testcase_03 | AC | 23 ms
17,408 KB |
testcase_04 | AC | 30 ms
17,664 KB |
testcase_05 | AC | 30 ms
17,536 KB |
testcase_06 | AC | 30 ms
17,792 KB |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | RE | - |
testcase_33 | RE | - |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.Collections.Generic; using System.Text; using System.Linq; class Program { public void Proc() { Reader.IsDebug = false; long num = int.Parse(Reader.ReadLine()); long max = num-1; long min = num; if (num == 1) { min = 0; } else if(min == 2) { min = 1; } else { this.soinsuList = this.SoinsuBunkai(num); min = this.GetAns(0,1, Math.Min(3, this.soinsuList.Count) - 1);; } Console.WriteLine(min + " " + max); } private List<long> soinsuList; Dictionary<long,Dictionary<long, Dictionary<int, long>>> dic = new Dictionary<long,Dictionary<long, Dictionary<int, long>>>(); private long GetAns(long target, long added, int remain) { if(!dic.ContainsKey(target)) { dic.Add(target, new Dictionary<long, Dictionary<int, long>>()); } if(!dic[target].ContainsKey(added)) { dic[target].Add(added, new Dictionary<int, long>()); } if(dic[target][added].ContainsKey(remain)) { return dic[target][added][remain]; } long ans = -1; if(remain == 0) { ans = 1; for(int i=0; i<this.soinsuList.Count; i++) { long key = 1<<i; if((target & key) == 0) { ans = ans * this.soinsuList[i]; } } ans--; } else if(target == (1<<this.soinsuList.Count) - 1) { return added - 1; } else { long tmpAns = long.MaxValue; for(int i=0; i<this.soinsuList.Count; i++) { long key = 1<<i; if((target & key) == 0) { long ret = this.GetAns(target + key, added * this.soinsuList[i], remain); if(ret > 0) { tmpAns = Math.Min(tmpAns, ret); } ret = this.GetAns(target + key, 1, remain - 1); if(ret > 0) { tmpAns = Math.Min(tmpAns, ret + (added * this.soinsuList[i] - 1)); } } } if(tmpAns != long.MaxValue) { ans = tmpAns; } } dic[target][added].Add(remain, ans); return ans; } private List<long> SoinsuBunkai(long target) { List<long> ret = new List<long>(); long num = target; for (long i =2; i<=Math.Sqrt(target); i++) { if(i > num) { break; } while (num % i == 0) { ret.Add(i); num = num / i; } } if(num > 1) { ret.Add(num); } return ret; } public class Reader { public static bool IsDebug = true; private static String PlainInput = @" 13 "; 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(); } } } static void Main() { Program prg = new Program(); prg.Proc(); } }