結果
問題 |
No.3 ビットすごろく
|
ユーザー |
|
提出日時 | 2019-12-27 20:58:14 |
言語 | C (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 898 bytes |
コンパイル時間 | 451 ms |
コンパイル使用メモリ | 31,232 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-09 10:29:57 |
合計ジャッジ時間 | 1,276 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 WA * 15 |
ソースコード
#include <stdio.h> #include <stdlib.h> #include <math.h> int bit(int a); int main(void) { int N; int s = 1; int c = 1; int b; int ng = 0; int n0g[10] = {0}; scanf("%d", &N); n0g[0] = 1; if (N == 1) { printf("%d\n", s); return EXIT_SUCCESS; } for (;;) { b = bit(c); s++; if (!(s % 10)) { ng = c; } if (c+b == N) { printf("%d\n", s); break; } else if (c+b > N) { c -= b; } else { c += b; } if (c == ng) { printf("%d\n", -1); return EXIT_SUCCESS; } } return EXIT_SUCCESS; } int bit(int a) { int t = 0; int p; for (int i = 15; i >= 0; i--) { p = pow(2, i); if (a >= p) { t++; a -= p; } } return t; }