結果
| 問題 | No.2929 Miracle Branch | 
| コンテスト | |
| ユーザー |  tnakao0123 | 
| 提出日時 | 2024-10-14 15:58:01 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 40 ms / 2,000 ms | 
| コード長 | 1,043 bytes | 
| コンパイル時間 | 532 ms | 
| コンパイル使用メモリ | 57,392 KB | 
| 最終ジャッジ日時 | 2025-02-24 19:31:54 | 
| ジャッジサーバーID (参考情報) | judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 43 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:29:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   29 |   scanf("%lld", &x);
      |   ~~~~~^~~~~~~~~~~~
            
            ソースコード
/* -*- coding: utf-8 -*-
 *
 * 2929.cc:  No.2929 Miracle Branch - yukicoder
 */
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
/* constant */
const int MAX_N = 200000;
/* typedef */
using ll = long long;
using vi = vector<int>;
/* global variables */
/* subroutines */
/* main */
int main() {
  ll x;
  scanf("%lld", &x);
  vi vs;
  if (x <= 4) vs.push_back(x);
  else {
    while (x % 4 == 0) vs.push_back(4), x /= 4;
    for (int i = 2; x > 1 && i <= MAX_N; i++)
      while (x % i == 0)
	vs.push_back(i), x /= i;
    if (x > 1) { puts("-1"); return 0; }
  }
  ll sum = 0;
  for (auto v: vs) sum += v + 1;
  if (sum > MAX_N) { puts("-1"); return 0; }
  int m = vs.size(), n = sum;
  printf("%d\n", n);
  for (int i = 0; i + 1 < m; i++) printf("%d %d\n", i + 1, i + 2);
  for (int i = 0, k = m; i < m; i++)
    for (int j = 0; j < vs[i]; j++)
      printf("%d %d\n", i + 1, (k++) + 1);
  for (int i = 0; i < n; i++)
    printf("%c%c", (i < m) ? 'b' : 'g', (i + 1 < n) ? ' ' : '\n');
  
  return 0;
}
            
            
            
        