結果
| 問題 |
No.2426 Select Plus or Minus
|
| コンテスト | |
| ユーザー |
Manuel1024
|
| 提出日時 | 2023-08-18 21:36:31 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,170 bytes |
| コンパイル時間 | 1,107 ms |
| コンパイル使用メモリ | 97,184 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-11-28 06:02:46 |
| 合計ジャッジ時間 | 3,251 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 35 WA * 6 |
ソースコード
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <queue>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(){
ll n; cin >> n;
map<ll, int> mem;
map<ll, ll> pre;
queue<ll> Q;
Q.emplace(n);
mem[n] = 0;
while(!Q.empty()){
ll cur = Q.front(); Q.pop();
if(cur == 1) break;
if(cur%2 == 0){
if(mem.count(cur/2) == 1) continue;
mem[cur/2] = mem[cur]+1;
pre[cur/2] = cur;
if(cur/2 == 1) break;
Q.emplace(cur/2);
}else{
for(auto &it: {cur*3+1}){
if(mem.count(it) == 1) continue;
mem[it] = mem[cur]+1;
pre[it] = cur;
if(it == 1) break;
Q.emplace(it);
}
}
}
string ans = "";
ll x = 1;
while(x != n){
ll p = pre[x];
if(x*2 == p) ans += "/";
else if(p*3+1 == x) ans += "+";
else ans += "-";
x = p;
}
reverse(ans.begin(), ans.end());
cout << ans.size() << endl;
cout << ans << endl;
return 0;
}
Manuel1024