結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
TLwiegehtt
|
| 提出日時 | 2015-07-08 16:33:03 |
| 言語 | C90 (gcc 12.3.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 5,000 ms |
| コード長 | 820 bytes |
| コンパイル時間 | 198 ms |
| コンパイル使用メモリ | 21,536 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-01 07:27:18 |
| 合計ジャッジ時間 | 1,165 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
コンパイルメッセージ
main.c: In function ‘main’:
main.c:15:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
15 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
ソースコード
#include <stdio.h>
#define MOD (5000)
int main(void){
int i,n;
int st=0,goal=0;
int next[5000];
int s[10100];
for(i=0;i<5000;i++){next[i]=0;}
for(i=0;i<10100;i++){s[i]=-1;}
scanf("%d", &n);
s[1] = 1;
next[goal] = 1;
goal++;
while(st!=goal){
int bit=0,tmp;
int nowPos = next[st];
int nextPos;
st = (st+1)%MOD;
if( nowPos == n ){
break;
}
tmp = nowPos;
while(tmp>0){
if(tmp%2 == 1){
bit++;
}
tmp >>= 1;
}
nextPos = nowPos - bit;
if( 1 <= nextPos && s[nextPos] == -1 ){
next[goal] = nextPos;
s[nextPos] = s[nowPos]+1;
goal = (goal+1)%MOD;
}
nextPos = nowPos + bit;
if( nextPos <= n && s[nextPos] == -1 ){
next[goal] = nextPos;
s[nextPos] = s[nowPos]+1;
goal = (goal+1)%MOD;
}
}
printf("%d\n", s[n]);
return 0;
}
TLwiegehtt