結果
問題 | No.2426 Select Plus or Minus |
ユーザー | MARTH |
提出日時 | 2023-08-18 21:29:10 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 876 bytes |
コンパイル時間 | 1,874 ms |
コンパイル使用メモリ | 171,744 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-28 05:43:25 |
合計ジャッジ時間 | 3,164 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 41 |
ソースコード
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rrep(i,a,b) for(int i=(int)(a);i<=(int)(b);i++) #define all(v) v.begin(),v.end() typedef long long ll; typedef pair<int,int> pii; #include <atcoder/modint> //using mint = atcoder::modint1000000007; //using mint = atcoder::modint998244353; //.val()でintとして出力 llに注意 ll INF=1e15; ll modpow(ll a,ll x,ll M){//a^x modM ll r=1; for (; x>0; x>>=1,a=a*a%M) if (x&1) r=r*a%M; return r; } ll N; queue<char>Q; int main(){ cin >> N; while(N!=1){ if(N%2==0){ N/=2; Q.push('/'); } else{ if((3*N-1)%4==0){ N=3*N-1; Q.push('-'); } else{ N=3*N+1; Q.push('+'); } } } cout << Q.size() << endl; while(!Q.empty()){ char s=Q.front(); Q.pop(); cout << s; } cout << endl; }