結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
roaiziro
|
| 提出日時 | 2015-09-22 07:03:26 |
| 言語 | C90 (gcc 12.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 1,988 bytes |
| コンパイル時間 | 125 ms |
| コンパイル使用メモリ | 22,528 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-01 07:33:35 |
| 合計ジャッジ時間 | 1,067 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
コンパイルメッセージ
main.c: In function ‘end’:
main.c:27:9: warning: implicit declaration of function ‘free’ [-Wimplicit-function-declaration]
27 | free(h);
| ^~~~
main.c:2:1: note: include ‘<stdlib.h>’ or provide a declaration of ‘free’
1 | #include<stdio.h>
+++ |+#include <stdlib.h>
2 | #include<stdio.h>
main.c:27:9: warning: incompatible implicit declaration of built-in function ‘free’ [-Wbuiltin-declaration-mismatch]
27 | free(h);
| ^~~~
main.c:27:9: note: include ‘<stdlib.h>’ or provide a declaration of ‘free’
main.c: In function ‘newmyq’:
main.c:35:11: warning: implicit declaration of function ‘malloc’ [-Wimplicit-function-declaration]
35 | new = malloc(sizeof(struct MYQ));
| ^~~~~~
main.c:35:11: note: include ‘<stdlib.h>’ or provide a declaration of ‘malloc’
main.c:35:11: warning: incompatible implicit declaration of built-in function ‘malloc’ [-Wbuiltin-declaration-mismatch]
main.c:35:11: note: include ‘<stdlib.h>’ or provide a declaration of ‘malloc’
main.c: In function ‘main’:
main.c:84:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
84 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
ソースコード
#include<stdio.h>
#include<stdio.h>
#define N 10001
struct MASU{
int n, f, k;
}bord[N];
struct MYQ{
void *current;
struct MYQ *next;
struct MYQ *back;
};
struct MYQ *head, *tail;
void ini(void)
{
head = tail = NULL;
return;
}
void end(void)
{
struct MYQ *h, *w;
for(h = head; h != NULL; h = w){
w = h->next;
free(h);
}
return;
}
struct MYQ* newmyq(void *current)
{
struct MYQ *new;
new = malloc(sizeof(struct MYQ));
new->next = new->back = NULL;
new->current = current;
return(new);
}
void enque(struct MYQ *q)
{
if(tail == NULL){
head = tail = q;
}else{
q->next = head;
head->back = q;
head = q;
}
return;
}
struct MYQ* deque(void)
{
struct MYQ *w;
if(tail == NULL){
return(NULL);
}
w = tail;
tail = tail->back;
return(w);
}
int bit(int n)
{
int bit = 0;
do{
if(n % 2 == 1){
bit++;
}
}while(n >>= 1);
return(bit);
}
int main(int argc, const char * argv[])
{
int n, i, front, back;
struct MYQ *w;
struct MASU *b;
ini();
scanf("%d", &n);
for(i = 1; i <= n; i++){
bord[i].n = i;
bord[i].f = 0;
bord[i].k = 0;
}
enque(newmyq(&bord[1]));
bord[1].f = bord[1].k = 1;
while((w = deque()) != NULL){
b = w->current;
front = b->n + bit(b->n);
if(front <= n && bord[front].f == 0){
enque(newmyq(&bord[front]));
bord[front].f = 1;
bord[front].k = bord[b->n].k + 1;
}
back = b->n - bit(b->n);
if(1 <= back && bord[back].f == 0){
enque(newmyq(&bord[back]));
bord[back].f = 1;
bord[back].k = bord[b->n].k + 1;
}
}
if(0 < bord[n].k){
printf("%d\n", bord[n].k);
}else{
printf("%d\n", -1);
}
end();
return 0;
}
roaiziro