結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
mono1977
|
| 提出日時 | 2017-02-08 02:01:04 |
| 言語 | C90(gcc15) (gcc 15.2.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 885 bytes |
| 記録 | |
| コンパイル時間 | 296 ms |
| コンパイル使用メモリ | 28,480 KB |
| 最終ジャッジ日時 | 2026-02-24 00:17:24 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.c: In function 'sugoroku':
main.c:24:25: error: C++ style comments are not allowed in ISO C90
24 | //printf("%d <- %d\n",position-bit_cnt,position);
| ^
main.c:24:25: note: (this will be reported only once per input file)
ソースコード
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>
int numOfBits(int n){
int bits=0;
do{
bits += n %2;
n /= 2;
}while(n>0);
return bits;
}
void sugoroku(int a[],int n,int position,int turn){
a[position]=turn;
int bit_cnt = numOfBits(position);
if(position-bit_cnt>0){
if(a[position-bit_cnt]==-1 || a[position-bit_cnt]>turn+1){
//printf("%d <- %d\n",position-bit_cnt,position);
sugoroku(a,n,position-bit_cnt,turn+1);
}
}
if(position+bit_cnt<n+1){
if(a[position+bit_cnt]==-1 || a[position+bit_cnt]>turn+1){
//printf("%d -> %d\n",position,position+bit_cnt);
sugoroku(a,n,position+bit_cnt,turn+1);
}
}
}
int main(){
int n;
scanf("%d",&n);
int a[n+1];
int i;
for(i=0;i<n+1;i++){
a[i]=-1;
}
sugoroku(a,n,1,1);
printf("%d\n",a[n]);
return 0;
}
mono1977