結果
問題 |
No.2426 Select Plus or Minus
|
ユーザー |
![]() |
提出日時 | 2023-08-21 04:49:08 |
言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,070 bytes |
コンパイル時間 | 9,766 ms |
コンパイル使用メモリ | 144,100 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-12-14 13:33:08 |
合計ジャッジ時間 | 3,674 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 41 |
ソースコード
#include <cassert> #include <cmath> #include <algorithm> #include <iostream> #include <iomanip> #include <climits> #include <map> #include <queue> #include <set> #include <cstring> #include <vector> using namespace std; typedef long long ll; const ll MOD = 1000000007; struct Node { ll v; string str; Node(ll v, string str) { this->v = v; this->str = str; } bool operator>(const Node &n) const { return v > n.v; } }; int main() { ll N; cin >> N; priority_queue <Node, vector<Node>, greater<Node>> pque; pque.push(Node(N, "")); map<ll, bool> visited; while (not pque.empty()) { Node node = pque.top(); pque.pop(); if (node.v == 1) { cout << node.str.size() << endl; cout << node.str << endl; break; } if (visited[node.v]) continue; visited[node.v] = true; if (node.v % 2 == 0) { pque.push(Node(node.v / 2, node.str + "/")); } else { pque.push(Node(3 * node.v + 1, node.str + "+")); pque.push(Node(3 * node.v - 1, node.str + "-")); } } return 0; }