結果
問題 | No.2426 Select Plus or Minus |
ユーザー |
|
提出日時 | 2023-08-18 22:15:36 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 16 ms / 2,000 ms |
コード長 | 905 bytes |
コンパイル時間 | 1,917 ms |
コンパイル使用メモリ | 194,436 KB |
最終ジャッジ日時 | 2025-02-16 10:14:01 |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 41 |
ソースコード
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; ++i) typedef long long ll; using namespace std; int main() { cin.tie(0)->sync_with_stdio(0); ll N; cin >> N; string ans = ""; while (N != 1) { if (N % 2 == 0) { N /= 2; ans += "/"; } else { ll tmp = 3 * N + 1; int cnt1 = 0; while (tmp % 2 == 0) { tmp /= 2; cnt1++; } tmp = 3 * N - 1; int cnt2 = 0; while (tmp % 2 == 0) { tmp /= 2; cnt2++; } if (cnt1 > cnt2) { N = 3 * N + 1; ans += "+"; } else { N = 3 * N - 1; ans += "-"; } } } cout << ans.size() << "\n"; cout << ans << "\n"; return 0; }