結果

問題 No.3 ビットすごろく
ユーザー highdhighd
提出日時 2016-09-07 15:49:25
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 116 ms / 5,000 ms
コード長 766 bytes
コンパイル時間 407 ms
コンパイル使用メモリ 55,664 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-01 08:04:04
合計ジャッジ時間 2,338 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
int*cells;
int max;
void game(int run_count,int id){
    int count = (id & 0x5555) + ((id >> 1) & 0x5555);
    count = (count & 0x3333) + ((count >> 2) & 0x3333);
    count = (count & 0x0f0f) + ((count >> 4) & 0x0f0f);
    count = (count & 0x00ff) + ((count >> 8) & 0x00ff);
	cells[id]=run_count;
	if(id+count<=max&&cells[id+count]>run_count){
		cells[id+count]=run_count;
		game(run_count+1,id+count);
	}
	if(id-count>0&&cells[id-count]>run_count){
		cells[id-count]=run_count;
		game(run_count+1,id-count);
	}
}
int main(){
	std::cin>>max;
	cells=new int[max+1];
	for(int i=1;i<=max;i++){
		cells[i]=max+100;
	}
	game(1,1);
	if(cells[max]==max+100){
		std::cout<<-1<<std::endl;
	}else{
		std::cout<<cells[max]<<std::endl;
	}
	delete[] cells;
} 
0