結果

問題 No.2929 Miracle Branch
ユーザー k82bk82b
提出日時 2024-10-12 16:37:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,343 bytes
コンパイル時間 926 ms
コンパイル使用メモリ 84,588 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-12 16:38:05
合計ジャッジ時間 10,187 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 WA -
testcase_03 AC 5 ms
5,248 KB
testcase_04 AC 5 ms
5,248 KB
testcase_05 AC 4 ms
5,248 KB
testcase_06 AC 5 ms
5,248 KB
testcase_07 AC 5 ms
5,248 KB
testcase_08 AC 5 ms
5,248 KB
testcase_09 AC 4 ms
5,248 KB
testcase_10 AC 4 ms
5,248 KB
testcase_11 AC 4 ms
5,248 KB
testcase_12 AC 3 ms
5,248 KB
testcase_13 AC 5 ms
5,248 KB
testcase_14 AC 5 ms
5,248 KB
testcase_15 AC 5 ms
5,248 KB
testcase_16 AC 4 ms
5,248 KB
testcase_17 AC 3 ms
5,248 KB
testcase_18 AC 4 ms
5,248 KB
testcase_19 AC 8 ms
5,248 KB
testcase_20 AC 8 ms
5,248 KB
testcase_21 AC 15 ms
5,248 KB
testcase_22 AC 2 ms
5,248 KB
testcase_23 AC 24 ms
5,248 KB
testcase_24 AC 84 ms
5,248 KB
testcase_25 AC 14 ms
5,248 KB
testcase_26 AC 4 ms
5,248 KB
testcase_27 AC 6 ms
5,248 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 3 ms
5,248 KB
testcase_34 AC 263 ms
5,332 KB
testcase_35 AC 292 ms
5,248 KB
testcase_36 AC 4 ms
5,248 KB
testcase_37 AC 270 ms
5,248 KB
testcase_38 AC 268 ms
5,248 KB
testcase_39 AC 272 ms
5,248 KB
testcase_40 AC 271 ms
5,336 KB
testcase_41 AC 264 ms
5,248 KB
testcase_42 AC 267 ms
5,248 KB
testcase_43 WA -
testcase_44 WA -
testcase_45 AC 2 ms
5,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
using Int = long long;
int main() {
	int N = 200000;
	Int X;
	std::cin >> X;
	std::vector<Int> A;
	for (Int i = 2; i * i <= X && i <= N; ++i) while (X % i == 0) {
		X /= i;
		A.push_back(i);
	}
	if (X > 1) A.push_back(X);
	reverse(A.begin(), A.end());
	int M = A.size();
	for (int i = 0; i < M; ++i) {
		if (A[i] > N) {
			return 0;
		}
	}
	int n = N + 1;
	std::vector<int> u, v;
	std::vector<char> c;
	for (int i = 1; i <= 100; ++i) {
		std::vector<Int> B(i, 1);
		for (int j = 0; j < M; ++j) {
			int id = min_element(B.begin(), B.end()) - B.begin();
			B[id] *= A[j];
		}
		Int x = std::accumulate(B.begin(), B.end(), 0LL) + i;
		if (x < n) {
			n = x;
			u.clear();
			v.clear();
			c.clear();
			int j = i + 1;
			for (int k = 0; k < i - 1; ++k) {
				u.push_back(k + 1);
				v.push_back(k + 2);
			}
			for (int k = 0; k < i; ++k) {
				for (int l = 0; l < B[k]; ++l) {
					u.push_back(k + 1);
					v.push_back(j++);
				}
				c.push_back('b');
			}
			while (int(c.size()) < n) {
				c.push_back('g');
			}
		}
	}
	if (n < N) {
		std::cout << n << std::endl;
		for (int i = 0; i < n - 1; ++i) std::cout << u[i] << ' ' << v[i] << std::endl;
		for (int i = 0; i < n; ++i) std::cout << c[i] << " \n"[i == n - 1];
	} else {
		std::cout << -1 << std::endl;
	}
}
0