結果

問題 No.375 立方体のN等分 (1)
ユーザー 14番14番
提出日時 2016-06-06 07:49:44
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 3,525 bytes
コンパイル時間 1,029 ms
コンパイル使用メモリ 114,260 KB
実行使用メモリ 388,488 KB
最終ジャッジ日時 2024-04-17 05:09:59
合計ジャッジ時間 8,454 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
24,244 KB
testcase_01 AC 32 ms
23,852 KB
testcase_02 AC 92 ms
37,232 KB
testcase_03 AC 24 ms
25,588 KB
testcase_04 AC 28 ms
21,940 KB
testcase_05 AC 29 ms
23,860 KB
testcase_06 AC 29 ms
23,732 KB
testcase_07 AC 29 ms
24,108 KB
testcase_08 AC 131 ms
45,260 KB
testcase_09 AC 31 ms
25,780 KB
testcase_10 AC 31 ms
24,364 KB
testcase_11 AC 33 ms
24,128 KB
testcase_12 AC 35 ms
23,592 KB
testcase_13 AC 34 ms
25,908 KB
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Collections.Generic;
using System.Text;
using System.Linq;

class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        long num = long.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);
            this.dic = new Dictionary<long, Dictionary<int, long>>[(1<<soinsuList.Count) + 1];
            min = this.GetAns(0,1, Math.Min(3, this.soinsuList.Count) - 1);;
        }
        Console.WriteLine(min + " " + max);

    }
    
    private List<long> soinsuList;
    
    Dictionary<long, Dictionary<int, long>>[] dic;

    private long GetAns(int target, long added, int remain) {
        if(dic[target] == null) {
            dic[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++) {
                int 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 = @"


4163034477





";
        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();
    }
}
0