結果

問題 No.376 立方体のN等分 (2)
ユーザー kongarishisyamokongarishisyamo
提出日時 2016-06-07 16:42:28
言語 C++11
(gcc 11.4.0)
結果
MLE  
実行時間 -
コード長 1,629 bytes
コンパイル時間 1,241 ms
コンパイル使用メモリ 104,140 KB
実行使用メモリ 543,768 KB
最終ジャッジ日時 2024-04-17 05:45:40
合計ジャッジ時間 19,007 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 140 ms
12,904 KB
testcase_01 AC 140 ms
12,828 KB
testcase_02 AC 143 ms
12,952 KB
testcase_03 AC 150 ms
12,824 KB
testcase_04 AC 149 ms
12,820 KB
testcase_05 AC 142 ms
12,720 KB
testcase_06 AC 140 ms
12,828 KB
testcase_07 AC 140 ms
12,696 KB
testcase_08 AC 149 ms
12,828 KB
testcase_09 AC 142 ms
12,696 KB
testcase_10 AC 177 ms
20,764 KB
testcase_11 AC 151 ms
12,820 KB
testcase_12 AC 140 ms
12,692 KB
testcase_13 AC 147 ms
12,820 KB
testcase_14 AC 150 ms
12,824 KB
testcase_15 AC 150 ms
12,828 KB
testcase_16 AC 2,224 ms
424,860 KB
testcase_17 AC 151 ms
12,820 KB
testcase_18 AC 147 ms
12,696 KB
testcase_19 AC 158 ms
15,772 KB
testcase_20 AC 148 ms
12,820 KB
testcase_21 AC 2,327 ms
457,500 KB
testcase_22 AC 139 ms
12,696 KB
testcase_23 MLE -
testcase_24 AC 1,828 ms
360,600 KB
testcase_25 AC 139 ms
12,824 KB
testcase_26 AC 2,030 ms
394,652 KB
testcase_27 AC 144 ms
12,824 KB
testcase_28 AC 139 ms
12,692 KB
testcase_29 AC 147 ms
12,692 KB
testcase_30 AC 140 ms
12,824 KB
testcase_31 AC 149 ms
12,820 KB
testcase_32 AC 146 ms
12,956 KB
testcase_33 AC 146 ms
12,696 KB
testcase_34 AC 149 ms
12,820 KB
testcase_35 AC 147 ms
12,736 KB
testcase_36 AC 148 ms
12,696 KB
testcase_37 AC 151 ms
12,828 KB
testcase_38 AC 147 ms
12,828 KB
testcase_39 AC 142 ms
12,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<vector>

using namespace std;

#define MAX 10000001

long long N;
vector<long long> insuu;
long long insuun=0;
long long pc=0;
long long ansmin;
long long cou=0;
map<long long,map<long long,map<long long,set<long long>>>> memo;

void search2(long long a,long long b,long long c,int sn,int pl){
    if(memo.find(a)!=memo.end()&&memo[a].find(b)!=memo[a].end()&&memo[a][b].find(c)!=memo[a][b].end()&&memo[a][b][c].find(sn)!=memo[a][b][c].end()){
		return;
	}
	else{
		memo[a][b][c].insert(sn);
		memo[a][c][b].insert(sn);
		memo[b][a][c].insert(sn);
		memo[b][c][a].insert(sn);
		memo[c][b][a].insert(sn);
		memo[c][a][b].insert(sn);
	}
    if(a+b+c>=ansmin) return;
    if(sn==-1||sn==insuun){
        ansmin=min(ansmin,a+b+c);
        return;
    }
    search2(a*insuu[sn],b,c,sn+pl,pl);
    search2(a,b*insuu[sn],c,sn+pl,pl);
    search2(a,b,c*insuu[sn],sn+pl,pl);
}


int main(){

	vector<bool> arr;
	vector<long long> pn;

	cin>>N;

	long long ansmax=N-1;

	for(long long i=0;i<=MAX;i++){
		arr.push_back(true);
	}

	arr[0]=false;
	arr[1]=false;

	for(long long i=2;i<=MAX;i++){
		if(arr[i]){
			pn.push_back(i);
			pc++;
			for(long long j=i*2;j<=MAX;j+=i){
				arr[j]=false;
			}
		}
	}

	while(!arr.empty()) arr.pop_back();

	for(long long i=0;i<pc;i++){
		while(N%pn[i]==0){
			N/=pn[i];
			insuu.push_back(pn[i]);
			insuun++;
		}
		if(N==1) break;
	}

	while(!pn.empty()) pn.pop_back();
	if(N!=1) insuu.push_back(N),insuun++;

    ansmin=ansmax+3;

	search2(1,1,1,insuun-1,-1);

	ansmin-=3;

	cout<<ansmin<<" "<<ansmax<<endl;
}

0