結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
IL_msta
|
| 提出日時 | 2015-06-03 13:18:40 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 1,287 bytes |
| コンパイル時間 | 620 ms |
| コンパイル使用メモリ | 69,380 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-01 07:23:28 |
| 合計ジャッジ時間 | 1,583 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <math.h>
#include <string>
#include <list>
/////////
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
/////////
typedef long long LL;
typedef long double LD;
/////////
using namespace::std;
/////////
int pop(int n){
int ans = n;
ans = ((ans & 0xaaaa)>>1) +(ans&0x5555);
ans = ((ans & 0xcccc)>>2) +(ans&0x3333);
ans = ((ans & 0xf0f0)>>4) +(ans&0x0f0f);
ans = ((ans & 0xff00)>>8) +(ans&0x00ff);
return ans;
}
int N;
int m[10001];
int d[10001];
int main(void){
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed;//
//cout << setprecision(6);//
cin>>N;
rep(i,N+1){
m[i] = pop(i);
d[i] = -1;
}
int ans = -1;
int c[10001];
int num = 0;
int left;
int temp;
c[num] = 1;
d[c[num]] = 1;
left = 1;
for(;num<left;)
{
if(c[num] == N){
ans = d[c[num]];
break;
}
temp = c[num] + m[c[num]];
if( 1 <= temp && temp <= N){
if(d[temp] == -1)
{
c[left] = temp;
++left;
d[temp] = d[c[num]] + 1;
}
}
temp = c[num] - m[c[num]];
if( 1 <= temp && temp <= N){
if(d[temp] == -1)
{
c[left] = temp;
++left;
d[temp] = d[c[num]] + 1;
}
}
++num;
}
P(ans);
return 0;
}
IL_msta