結果
問題 |
No.3 ビットすごろく
|
ユーザー |
![]() |
提出日時 | 2017-03-29 18:53:59 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,023 bytes |
コンパイル時間 | 1,019 ms |
コンパイル使用メモリ | 157,300 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-06 15:05:52 |
合計ジャッジ時間 | 1,865 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 WA * 15 |
ソースコード
/* * 3.cpp */ //include files #include<bits/stdc++.h> using namespace std; //DEFINE MACROS #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define MIN(a,b) (a>b?b:a) #define MAX(a,b) (a>b?a:b) #define INT_IN(a) int a; cin >> a #define STR_IN(s) string s; cin >> s #define PRINTLN(s) cout << s << endl #define PRINTDOUBLELN(s) cout << setprecision(12) << (s) << endl; //DEFINE CONSTANT int N; int binary[10000]; int arrive[10000]; //DEFINE PROTOTYPE int grid(int i,int path); int main(){ int tmp; cin >> N; FOR(i,1,N+1){ tmp = i; binary[i] = 0; arrive[i] = 0; while(tmp != 0){ binary[i] += tmp%2; tmp = tmp / 2; } } int ans = grid(1,1); if(ans == 10000000) PRINTLN(-1); else PRINTLN(ans); } int grid(int now,int path){ int up,down; if (arrive[now] == 1) return 10000000; arrive[now] = 1; if(now == N) return path; if(now < 1 || now > N ) return 10000000; up = grid(now+binary[now],path+1); down = grid(now-binary[now],path+1); return MIN(up,down); }