結果
| 問題 |
No.954 Result
|
| コンテスト | |
| ユーザー |
bal4u
|
| 提出日時 | 2019-12-18 07:36:59 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 2,000 ms |
| コード長 | 783 bytes |
| コンパイル時間 | 127 ms |
| コンパイル使用メモリ | 23,168 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-04 12:37:30 |
| 合計ジャッジ時間 | 1,161 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 7 |
| other | AC * 29 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:32:39: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
32 | for (i = 4; i >= 0; --i) scanf("%lld", a+i);
| ~~~~~^~~~~~~~~~~~~
ソースコード
// yuki 954 Result
// 2019.12.18 bal4u
#include <stdio.h>
typedef long long ll;
#define MAX 73 // f[73]=1304969544928657
ll f[MAX+5]; // f[0]=1, f[1]=1, f[2]=2, f[3]=3
void fibonacci(int a0, int a1) {
int i;
f[0] = a0, f[1] = a1;
for (i = 2; i <= MAX; ++i) f[i] = f[i-2]+f[i-1];
}
int bsch(ll x) {
int m, l = 0, r = MAX;
while (l < r) {
m = (l + r) >> 1;
if (f[m] == x) return m;
if (f[m] < x) l = m + 1; else r = m;
}
return f[l] == x? l: -1;
}
int main()
{
int i, j;
ll a[5];
fibonacci(1, 1);
for (i = 4; i >= 0; --i) scanf("%lld", a+i);
i = 0;
if (a[0] == 1) {
j = 1;
if (a[1] == 1) i = 1;
} else if ((j = bsch(a[0])) < 0) { puts("0"); return 0; }
while (++i < 5) {
if (a[i] != f[++j]) break;
}
printf("%d\n", i);
return 0;
}
bal4u