結果
問題 |
No.2426 Select Plus or Minus
|
ユーザー |
|
提出日時 | 2023-08-18 21:26:10 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 638 bytes |
コンパイル時間 | 2,419 ms |
コンパイル使用メモリ | 197,380 KB |
最終ジャッジ日時 | 2025-02-16 09:35:13 |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 3 |
other | AC * 19 WA * 1 TLE * 1 -- * 20 |
ソースコード
#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 = ""; set<ll> st; st.insert(N); while (N != 1) { if (N % 2 == 0) { N /= 2; ans += "/"; } else if (N * 3 - 1 > 0 && st.find(N * 3 - 1) == st.end()) { N = N * 3 - 1; ans += "-"; } else { N = N * 3 + 1; ans += "+"; } st.insert(N); } cout << ans.size() << "\n"; cout << ans << "\n"; return 0; }