結果

問題 No.2929 Miracle Branch
ユーザー kwm_tkwm_t
提出日時 2024-10-12 16:18:45
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,784 bytes
コンパイル時間 5,876 ms
コンパイル使用メモリ 325,240 KB
実行使用メモリ 8,064 KB
最終ジャッジ日時 2024-10-12 16:19:08
合計ジャッジ時間 19,104 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
5,248 KB
testcase_01 AC 7 ms
6,816 KB
testcase_02 AC 7 ms
5,248 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 9 ms
5,248 KB
testcase_19 AC 10 ms
5,248 KB
testcase_20 WA -
testcase_21 AC 18 ms
5,248 KB
testcase_22 WA -
testcase_23 AC 29 ms
5,248 KB
testcase_24 AC 88 ms
5,248 KB
testcase_25 AC 15 ms
5,248 KB
testcase_26 WA -
testcase_27 AC 7 ms
5,248 KB
testcase_28 AC 6 ms
5,248 KB
testcase_29 AC 6 ms
5,248 KB
testcase_30 AC 6 ms
5,248 KB
testcase_31 AC 6 ms
5,248 KB
testcase_32 AC 6 ms
5,248 KB
testcase_33 AC 6 ms
5,248 KB
testcase_34 AC 286 ms
5,248 KB
testcase_35 AC 282 ms
5,248 KB
testcase_36 AC 6 ms
5,248 KB
testcase_37 AC 290 ms
5,248 KB
testcase_38 AC 275 ms
5,248 KB
testcase_39 AC 277 ms
5,248 KB
testcase_40 AC 276 ms
5,248 KB
testcase_41 AC 275 ms
5,248 KB
testcase_42 AC 287 ms
5,248 KB
testcase_43 AC 271 ms
5,248 KB
testcase_44 AC 275 ms
5,248 KB
testcase_45 AC 6 ms
5,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
using mint = modint998244353;
const int mod = 998244353;
//const int INF = 1e9;
const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r) - 1;i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	long long x; cin >> x;
	vector<long long>cand;
	rep2(i, 1, 200001) {
		if (0 == x % i)cand.push_back(i);
	}
	map<long long, long long>mp;// {p*q,min{p+q}};
	map<long long, pair<long long, long long>>mp2;
	rep(i, cand.size())rep(j, cand.size()) {
		long long x = cand[i] * cand[j];
		long long y = cand[i] + cand[j];
		if (mp.count(x)) {
			if (chmin(mp[x], y))mp2[x] = { cand[i],cand[j] };
		}
		else {
			mp[x] = y;
			mp2[x] = { cand[i],cand[j] };
		}

	}
	vector<long long>mn(3, LINF);
	mn[0] = x + 1;
	if (mp.count(x))mn[1] = 2 + mp[x];
	int tmp = 0;
	rep2(i, 1, 200001) {
		if (0 != x % i)continue;
		if (!mp.count(x / i))continue;
		if (chmin(mn[2], 3 + i + mp[x / i]))tmp = i;
	}
	long long mnn = LINF;
	rep(i, 3)chmin(mnn, mn[i]);
	if (mnn > 200000) {
		cout << -1 << endl;
		return 0;
	}
	cout << mnn << endl;
	if (mnn == mn[0]) {
		rep(i, mnn - 1)cout << 1 << " " << i + 2 << endl;
		vector<char>c(mnn, 'g');
		c[0] = 'b';
		rep(i, mnn)cout << c[i] << " ";
		cout << endl;
	}
	else if (mnn == mn[1]) {
		long long p = mp2[x].first;
		long long q = mp2[x].second;
		rep(i, p)cout << i + 1 << " " << p + q + 1 << endl;
		rep(i, q)cout << i + 1 + p << " " << p + q + 2 << endl;
		cout << p + q + 1 << " " << p + q + 2 << endl;
		vector<char>c(mnn, 'g');
		c[mnn - 2] = 'b';
		c[mnn - 1] = 'b';
		rep(i, mnn)cout << c[i] << " ";
		cout << endl;
	}
	else {
		long long p = tmp;
		long long q = mp2[x / tmp].first;
		long long r = mp2[x / tmp].second;
		rep(i, p)cout << i + 1 << " " << p + q + r + 1 << endl;
		rep(i, q)cout << i + 1 + p << " " << p + q + r + 2 << endl;
		rep(i, r)cout << i + 1 + p + q << " " << p + q + r + 3 << endl;
		cout << p + q + r + 1 << " " << p + q + r + 2 << endl;
		cout << p + q + r + 2 << " " << p + q + r + 3 << endl;
		vector<char>c(mnn, 'g');
		c[mnn - 3] = 'b';
		c[mnn - 2] = 'b';
		c[mnn - 1] = 'b';
		rep(i, mnn)cout << c[i] << " ";
		cout << endl;
	}
	return 0;
}
0