結果
問題 |
No.3 ビットすごろく
|
ユーザー |
![]() |
提出日時 | 2017-03-30 17:21:42 |
言語 | C90 (gcc 12.3.0) |
結果 |
AC
|
実行時間 | 552 ms / 5,000 ms |
コード長 | 705 bytes |
コンパイル時間 | 576 ms |
コンパイル使用メモリ | 24,448 KB |
実行使用メモリ | 392,320 KB |
最終ジャッジ日時 | 2024-07-01 08:37:54 |
合計ジャッジ時間 | 6,754 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 33 |
コンパイルメッセージ
main.c: In function ‘main’: main.c:10:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 10 | scanf("%d",&n); | ^~~~~~~~~~~~~~
ソースコード
#include <stdio.h> #include <string.h> #include <ctype.h> #include <math.h> #include <stdlib.h> #define INF 1000000000; int main(void){ int n; scanf("%d",&n); int b[n+1]; int i,j; for(i=1;i<n+1;i++){ int j=i; int cnt=0; while(j/2!=0){ if(j%2==1){ cnt++; } j=j/2; } if(j==1){ cnt++; } b[i]=cnt; } int dp[n+2][n+1]; for(i=0;i<n+2;i++){ for(j=0;j<n+1;j++){ dp[i][j]=0; } } dp[1][1]=1; i=1; while(i<=n && dp[i][n]==0){ for(j=1;j<n+1;j++){ if(dp[i][j]==1){ if(j+b[j]<n+1){ dp[i+1][j+b[j]]=1; } if(j-b[j]>0){ dp[i+1][j-b[j]]=1; } } } i++; } if(dp[i][n]==0){ printf("-1\n"); }else{ printf("%d\n",i); } return 0; }