結果

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long N_MAX = 200000;
int main(){
	long long X;
	cin >> X;
	vector<tuple<int, int, int, int, int>> P;
	if (X <= N_MAX){
		P.push_back(make_tuple(X + 1, 0, X, -1, -1));
	}
	for (int i = 1; i <= N_MAX; i++){
		if (X % i == 0 and X / i + i + 2 <= N_MAX){
			P.push_back(make_tuple(X / i + i + 2, 1, i, X / i, -1));
		}
	}
	for (int i = 1; i <= N_MAX; i++){
		if (X % i != 0){
			continue;
		}
		for (int j = 1; j * i <= N_MAX; j++){
			if (X / i % j == 0 and X / i / j + i + j + 3 <= N_MAX){
				P.push_back(make_tuple(X / i / j + i + j + 2, 2, i, j, X / i / j));
			}
		}
	}
	if (!P.empty()){
		auto [_, f, i, j, k] = *min_element(P.begin(), P.end());
		if (f == 0){
			cout << i + 1 << endl;
			for (int l = 0; l < i; l++){
				cout << 1 << ' ' << 2 + l << endl;
			}
			cout << "b";
			for (int l = 0; l < i; l++){
				cout << ' ' << 'g';
			}
			cout << endl;
		}
		if (f == 1){
			cout << i + j + 2 << endl;
			cout << 1 << ' ' << 2 << endl;
			for (int l = 0; l < i; l++){
				cout << 1 << ' ' << 3 + l << endl;
			}
			for (int l = 0; l < j; l++){
				cout << 2 << ' ' << 3 + i + l << endl;
			}
			cout << "b b";
			for (int l = 0; l < i + j; l++){
				cout << ' ' << 'g';
			}
			cout << endl;
		}
		if (f == 2){
			cout << i + j + k + 2 << endl;
			cout << 1 << ' ' << 2 << endl;
			cout << 2 << ' ' << 3 << endl;
			for (int l = 0; l < i; l++){
				cout << 1 << ' ' << 4 + l << endl;
			}
			for (int l = 0; l < j; l++){
				cout << 2 << ' ' << 4 + i + l << endl;
			}
			for (int l = 0; l < k; l++){
				cout << 3 << ' ' << 4 + i + j + l << endl;
			}
			cout << "b b b";
			for (int l = 0; l < i + j + k; l++){
				cout << ' ' << 'g';
			}
			cout << endl;
		}
	} else {
		cout << -1 << endl;
	}
}
0