結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 143 ms
12,824 KB
testcase_01 AC 143 ms
12,696 KB
testcase_02 AC 145 ms
12,696 KB
testcase_03 AC 151 ms
13,208 KB
testcase_04 AC 150 ms
12,736 KB
testcase_05 AC 142 ms
12,824 KB
testcase_06 AC 144 ms
12,828 KB
testcase_07 AC 141 ms
12,824 KB
testcase_08 AC 151 ms
12,692 KB
testcase_09 AC 142 ms
12,772 KB
testcase_10 AC 178 ms
21,588 KB
testcase_11 AC 152 ms
12,604 KB
testcase_12 AC 143 ms
12,696 KB
testcase_13 AC 143 ms
12,820 KB
testcase_14 AC 149 ms
12,736 KB
testcase_15 AC 150 ms
12,948 KB
testcase_16 AC 2,281 ms
461,980 KB
testcase_17 AC 156 ms
12,824 KB
testcase_18 AC 152 ms
12,828 KB
testcase_19 AC 165 ms
16,664 KB
testcase_20 AC 151 ms
12,828 KB
testcase_21 AC 2,450 ms
497,940 KB
testcase_22 AC 143 ms
12,824 KB
testcase_23 MLE -
testcase_24 AC 1,937 ms
391,960 KB
testcase_25 AC 138 ms
12,824 KB
testcase_26 AC 2,157 ms
428,188 KB
testcase_27 AC 156 ms
12,824 KB
testcase_28 AC 143 ms
12,700 KB
testcase_29 AC 151 ms
12,828 KB
testcase_30 AC 141 ms
12,824 KB
testcase_31 AC 147 ms
12,700 KB
testcase_32 AC 146 ms
12,828 KB
testcase_33 AC 147 ms
12,820 KB
testcase_34 AC 149 ms
12,828 KB
testcase_35 AC 149 ms
12,952 KB
testcase_36 AC 148 ms
12,828 KB
testcase_37 AC 148 ms
12,696 KB
testcase_38 AC 149 ms
12,824 KB
testcase_39 AC 141 ms
12,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cmath>
#include<algorithm>
#include<map>
#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,map<long long,bool>>>> 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][sn]=true;
		memo[a][c][b][sn]=true;
		memo[b][a][c][sn]=true;
		memo[b][c][a][sn]=true;
		memo[c][b][a][sn]=true;
		memo[c][a][b][sn]=true;
	}
    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