結果
問題 | No.2426 Select Plus or Minus |
ユーザー |
|
提出日時 | 2023-08-18 21:19:40 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 837 bytes |
コンパイル時間 | 1,692 ms |
コンパイル使用メモリ | 167,140 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-28 05:23:49 |
合計ジャッジ時間 | 2,933 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 41 |
ソースコード
#include<bits/stdc++.h>using namespace std;using ll=long long;int main(){ll n;cin>>n;string ans;ll m=n;while(m>1){if(m%2==0){m/=2;ans+='/';}else{ll num1=3*m+1;ll num2=3*m-1;ll num;if(num1>1e18){num=num2;}else if(num2>1e18){num=num1;}else{ll cons1=num1;ll cnt1=0;ll cons2=num2;ll cnt2=0;while(cons1%2==0){cons1/=2;cnt1++;}while(cons2%2==0){cons2/=2;cnt2++;}if(cnt1>=cnt2){num=num1;}else{num=num2;}}if(num==num1){m=num;ans+='+';}else{m=num;ans+='-';}}}cout<<ans.size()<<endl;cout<<ans<<endl;}