結果

問題 No.2929 Miracle Branch
ユーザー achapi
提出日時 2024-10-12 16:15:20
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,152 bytes
コンパイル時間 2,291 ms
コンパイル使用メモリ 202,336 KB
最終ジャッジ日時 2025-02-24 18:29:11
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other TLE * 1 -- * 42
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long N_MAX = 200000;
int main(){
	long long X;
	cin >> X;
	if (X == 1){
		cout << "2\n1 2\nb g" << endl;
		return 0;
	}
	vector<pair<int, vector<int>>> P;
	vector<int> A;
	long long sum = 0;
	auto dfs = [&](auto dfs){
		if (X == 1){
			if (sum + (int) A.size() <= N_MAX){
				P.push_back(make_pair(sum, A));
			}
			return;
		}
		for (int i = 2; i <= N_MAX; i++){
			if (X % i == 0){
				X /= i;
				A.push_back(i);
				sum += i;
				dfs(dfs);
				X *= i;
				sum -= i;
				A.pop_back();
			}
		}
	};
	dfs(dfs);
	if (!P.empty()){
		auto [_, S] = *min_element(P.begin(), P.end());
		cout << accumulate(S.begin(), S.end(), 0) + S.size() << endl;
		for (int i = 0; i < (int) S.size() - 1; i++){
			cout << i + 1 << ' ' << i + 2 << endl;
		}
		int cnt = S.size();
		for (int i = 0; i < (int) S.size(); i++){
			for (int j = 0; j < S[i]; j++){
				cnt++;
				cout << i + 1 << ' ' << cnt << endl;
			}
		}
		for (int i = 0; i < S.size(); i++){
			cout << "b ";
		}
		for (int i = 0; i < accumulate(S.begin(), S.end(), 0); i++){
			cout << "g ";
		}
		cout << endl;
	} else {
		cout << -1 << endl;
	}
}
0