結果

問題 No.2426 Select Plus or Minus
ユーザー stella1225stella1225
提出日時 2023-08-18 23:51:13
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,279 bytes
コンパイル時間 1,808 ms
コンパイル使用メモリ 169,032 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-28 11:32:43
合計ジャッジ時間 3,231 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
#define rep(i,a,n) for (int i = a; i < (n); i++)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
int mod = 998244353;
int INF = 1001001001;
using pll = pair<int,int>;

int Flag=0;

//デフォルトでNoがでる
void yn(int Flag){
  if(Flag==1){
    cout<<"Yes"<<endl;
  }
  else if(Flag==0){
    cout<<"No"<<endl;
  }
  else{
    cout<<"Draw"<<endl;
  }
}

void cerrVec(vector<string> &V){
  int n=V.size();
  rep(i,0,n){
    for(auto x:V[i]){
      cerr<<x<<" ";
    }
    cerr<<endl;
  }
  cerr<<endl;
}

/*
  int H,W; cin>>H>>W;
  vector<vector<char>> C(H,vector<char> (W));
  rep(i,0,H) rep(j,0,W) cin>>C[i][j];
*/
int num(ll n){
  int res=0;
  while(n%2==0){
    res++;
    n/=2;
  }
  return res;
}

int main(){
  ll K; cin>>K;
  int cnt=0; string S;
  while(K!=1){
    if(K%2){
      K*=3;
      cerr<<K+1<<" "<<K-1<<endl;
      cerr<<num(K+1)<<" "<<num(K-1)<<endl;
      if(num(K+1)>num(K-1)){
        K++;
        S+="+";
      }
      else{
        K--;
        S+="-";
      }
    }
    else{
      K/=2;
      S+="/";
    }
    cnt++;
    cerr<<K<<endl;
  }
  cout<<cnt<<endl;
  cout<<S;
}

  
  
0