結果
問題 | No.2426 Select Plus or Minus |
ユーザー |
![]() |
提出日時 | 2024-09-01 13:16:49 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 867 bytes |
コンパイル時間 | 900 ms |
コンパイル使用メモリ | 85,260 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-01 13:16:52 |
合計ジャッジ時間 | 2,940 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 41 |
ソースコード
#include <cstdint>#include <iostream>#include <sstream>int main() {std::uint64_t a, b;std::cin >> a;std::stringstream ss;int n = 0;while (a != 1) {if (a % 4 == 0) {n += 2;a >>= 2;ss << "//";}else if (a % 4 == 1) {n += 1;b = a;a = 3 * a + 1;if (a > 1000000000000000000ULL) {a = 3 * b - 1;ss << "-";}else {ss << "+";}}else if (a % 4 == 2) {n += 1;a >>= 1;ss << "/";}else /* a % 4 == 3 */ {n += 1;a = 3 * a - 1;ss << "-";}}std::cout<< n << '\n'<< ss.str() << std::endl;}