結果
問題 | No.2426 Select Plus or Minus |
ユーザー | Today03 |
提出日時 | 2023-08-18 22:23:19 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 551 bytes |
コンパイル時間 | 2,143 ms |
コンパイル使用メモリ | 202,000 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-28 08:07:11 |
合計ジャッジ時間 | 3,942 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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 += '/'; } else { long long a = n * 3 + 1; long long b = n * 3 - 1; int ac = 0, bc = 0; while (a % 2 == 0) { a /= 2; ac++; } while (b % 2 == 0) { b /= 2; bc++; } n = (ac > bc ? n * 3 + 1 : n * 3 - 1); ans += (ac > bc ? '+' : '-'); } } cout << ans.size() << endl; cout << ans << endl; }