結果
問題 |
No.2426 Select Plus or Minus
|
ユーザー |
![]() |
提出日時 | 2023-08-11 17:24:24 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 551 bytes |
コンパイル時間 | 1,725 ms |
コンパイル使用メモリ | 196,712 KB |
最終ジャッジ日時 | 2025-02-16 00:43:44 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 41 |
ソースコード
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main(){ random_device seed_gen; default_random_engine engine(seed_gen()); uniform_int_distribution<ll> dist(0, 1); ll n; cin >> n; vector<char> ans; while(n > 1){ if (n % 2 == 0){ ans.push_back('/'); n /= 2; }else{ if (dist(engine) == 0){ ans.push_back('+'); n = n * 3 + 1; }else{ ans.push_back('-'); n = n * 3 - 1; } } } cout << (int)ans.size() << endl; for (int i=0; i<(int)ans.size(); i++){ cout << ans[i]; } cout << endl; }