結果
問題 | No.3 ビットすごろく |
ユーザー | TAKEKATSU |
提出日時 | 2019-03-24 12:57:51 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 3 ms / 5,000 ms |
コード長 | 1,406 bytes |
コンパイル時間 | 1,641 ms |
コンパイル使用メモリ | 169,372 KB |
実行使用メモリ | 4,384 KB |
最終ジャッジ日時 | 2023-09-14 01:14:19 |
合計ジャッジ時間 | 3,083 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,380 KB |
testcase_01 | AC | 2 ms
4,376 KB |
testcase_02 | AC | 1 ms
4,376 KB |
testcase_03 | AC | 2 ms
4,376 KB |
testcase_04 | AC | 2 ms
4,376 KB |
testcase_05 | AC | 2 ms
4,380 KB |
testcase_06 | AC | 2 ms
4,380 KB |
testcase_07 | AC | 2 ms
4,380 KB |
testcase_08 | AC | 2 ms
4,376 KB |
testcase_09 | AC | 2 ms
4,380 KB |
testcase_10 | AC | 2 ms
4,376 KB |
testcase_11 | AC | 2 ms
4,380 KB |
testcase_12 | AC | 2 ms
4,376 KB |
testcase_13 | AC | 2 ms
4,380 KB |
testcase_14 | AC | 2 ms
4,380 KB |
testcase_15 | AC | 2 ms
4,376 KB |
testcase_16 | AC | 2 ms
4,384 KB |
testcase_17 | AC | 2 ms
4,380 KB |
testcase_18 | AC | 2 ms
4,376 KB |
testcase_19 | AC | 2 ms
4,376 KB |
testcase_20 | AC | 2 ms
4,380 KB |
testcase_21 | AC | 2 ms
4,376 KB |
testcase_22 | AC | 2 ms
4,376 KB |
testcase_23 | AC | 2 ms
4,376 KB |
testcase_24 | AC | 3 ms
4,376 KB |
testcase_25 | AC | 2 ms
4,376 KB |
testcase_26 | AC | 2 ms
4,376 KB |
testcase_27 | AC | 2 ms
4,380 KB |
testcase_28 | AC | 2 ms
4,380 KB |
testcase_29 | AC | 2 ms
4,380 KB |
testcase_30 | AC | 2 ms
4,376 KB |
testcase_31 | AC | 1 ms
4,384 KB |
testcase_32 | AC | 2 ms
4,376 KB |
コンパイルメッセージ
main.cpp: 関数 ‘long long int gcd(long long int, long long int)’ 内: main.cpp:30:11: 警告: 制御が非 void 関数の終りに到達しました [-Wreturn-type] 30 | else gcd(b, a%b); | ~~~^~~~~~~~
ソースコード
#include "bits/stdc++.h" using namespace std; #define ll long long #define vi vector<int> #define vvi vector<vi> #define pi pair<int,int> #define mp make_pair #define pb push_back #define MOD 1e9 + 7 #define PAI 3.1415 #define all(x) (x).begin(),(x).end() #define chmax(x,y) x = max(x,y) #define chmin(x,y) x = min(x,y) #define pr(x) cout << x << endl #define Endl endl #define rep(i,n) for(int i = 0 ; i < n; i++) const int dx[4] = {1,0,-1,0}; const int dy[4] = {0,1,0,-1}; const int ddx[8] = {-1,0,1,-1,1,-1,0,1}; const int ddy[8] = {-1,-1,-1,0,0,1,1,1}; const int inf = 99999999; const ll linf = 1LL << 62; ll gcd(ll a,ll b){ if(a < b)swap(a , b); if(a % b == 0) return b; else gcd(b, a%b); } ll lcm(ll a,ll b){ if(a < b)swap(a , b); return (a/gcd(a , b)) * b; } vi mass(100010, 0); int bitnum(int a){ int b = a%2; while(a /= 2) b += a%2; return b; } int main(){ int n; cin >> n; mass[1] = 1; queue<int> q; q.push(1); while(!q.empty()){ int pos = q.front(); q.pop(); int move = bitnum(pos); if(pos - move > 1 and mass[pos - move] == 0 and pos - move <= n){ mass[pos - move] = mass[pos] + 1; q.push(pos - move); } if(pos + move > 1 and mass[pos + move] == 0 and pos + move <= n){ mass[pos + move] = mass[pos] + 1; q.push(pos + move); } } if(mass[n] != 0) pr(mass[n]); else pr("-1"); return 0; }