結果
問題 |
No.3 ビットすごろく
|
ユーザー |
|
提出日時 | 2020-01-02 21:40:44 |
言語 | C (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 995 bytes |
コンパイル時間 | 1,302 ms |
コンパイル使用メモリ | 29,312 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-11-22 18:20:13 |
合計ジャッジ時間 | 1,502 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 32 WA * 1 |
ソースコード
#include <stdio.h> #include <stdlib.h> int bit(int a); int main(void) { int N; int s = 1; // step int c = 0; // check scanf("%d", &N); int math[10001] = {0}; math[1] = 1; for (; ; s++) { c = 0; for (int i = 1; i <= N; i++) { if (math[i] == s) { int d = bit(i); // distance if (i+d == N) { printf("%d\n", s+1); exit(EXIT_SUCCESS); } if (i+d < N && !math[i+d]) { math[i+d] = s+1; c = 1; } if (0 < i-d && !math[i-d]) { math[i-d] = s+1; c = 1; } } } if (!c) { printf("-1\n"); exit(EXIT_SUCCESS); } } return EXIT_SUCCESS; } int bit(int a) { int t = 0; for (; a;) { if (a % 2) {t++;}; a /= 2; } return t; }