結果
問題 | No.2426 Select Plus or Minus |
ユーザー |
|
提出日時 | 2023-08-18 21:55:54 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 12 ms / 2,000 ms |
コード長 | 518 bytes |
コンパイル時間 | 1,850 ms |
コンパイル使用メモリ | 194,272 KB |
最終ジャッジ日時 | 2025-02-16 10:00:02 |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 41 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { long long N; cin >> N; string ans; while (N != 1){ if (N % 2 == 0){ N /= 2; ans.push_back('/'); } else { long long M = N * 3 - 1, P = N * 3 + 1; int l = 0, r = 0; while (M % 2 == 0){ M /= 2; l++; } while (P % 2 == 0){ P /= 2; r++; } if (l > r){ N = N * 3 - 1; ans.push_back('-'); } else { N = N * 3 + 1; ans.push_back('+'); } } } cout << ans.size() << '\n'; cout << ans << '\n'; }