結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
mono1977
|
| 提出日時 | 2017-02-08 01:53:52 |
| 言語 | C90 (gcc 12.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 719 bytes |
| コンパイル時間 | 975 ms |
| コンパイル使用メモリ | 23,168 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-25 15:36:48 |
| 合計ジャッジ時間 | 1,716 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 14 WA * 19 |
コンパイルメッセージ
main.c: In function ‘main’:
main.c:38:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
38 | scanf("%d",&n);
| ^~~~~~~~~~~~~~
ソースコード
#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){
sugoroku(a,n,position-bit_cnt,turn+1);
}
}
if(position+bit_cnt<n+1){
if(a[position+bit_cnt]==-1){
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