結果

問題 No.2929 Miracle Branch
ユーザー rotti_coderrotti_coder
提出日時 2024-10-12 16:55:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,707 bytes
コンパイル時間 581 ms
コンパイル使用メモリ 76,552 KB
実行使用メモリ 10,496 KB
最終ジャッジ日時 2024-10-12 16:56:15
合計ジャッジ時間 6,795 ms
ジャッジサーバーID
(参考情報)
judge / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,496 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 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 3 ms
5,248 KB
testcase_19 AC 5 ms
5,248 KB
testcase_20 AC 7 ms
5,248 KB
testcase_21 AC 13 ms
5,248 KB
testcase_22 WA -
testcase_23 AC 22 ms
5,248 KB
testcase_24 AC 76 ms
5,248 KB
testcase_25 WA -
testcase_26 AC 3 ms
5,248 KB
testcase_27 AC 3 ms
5,248 KB
testcase_28 TLE -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
using namespace std;
vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}
int main()
{
  long long X;
  cin >> X;
  if(X==1){
    cout << 2 << endl;
    cout << "1 2" << endl;
    cout << "b g" << endl;
    return 0;
  }
  vector<pair<long long,long long>>num=prime_factorize(X);
  int cnt=0;
  long long parfait=0;
  for(int i=0;i<num.size();i++){
    parfait+=(num[i].first+1)*num[i].second;
    if(parfait>(long long)2e5)break;
  }
  if(parfait>(long long)2e5){
    cout << -1 << endl;
    return 0;
  }
  cnt=parfait;
  cout << cnt << endl;
  int rotti=cnt;
  //まず茶をつなぐ
  cnt=2;
  bool nouka=true;
  for(int i=0;i<num.size();i++)for(int j=0;j<num[i].second;j++){
    if(nouka){
      nouka=false;
      continue;
    }
    cout << cnt-1 << " " << cnt << endl;
    cnt++;
  }
  //つぎに緑を付けていく
  int count=1;
  for(int i=0;i<num.size();i++){
    for(int j=0;j<num[i].second;j++){
      for(int k=0;k<num[i].first;k++){
        cout << count <<  " " << cnt << endl;
        cnt++;
      }
      count++;
    }
  }
  //色の配置を出力
  cout << "b";
  for(int i=1;i<count-1;i++)cout << " " << "b";
  for(int i=0;i<rotti-count+1;i++)cout << " " << "g";
  cout << endl;
}
0