結果
| 問題 |
No.954 Result
|
| コンテスト | |
| ユーザー |
RISE70226821
|
| 提出日時 | 2020-10-06 17:22:34 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 56 ms / 2,000 ms |
| コード長 | 3,239 bytes |
| コンパイル時間 | 2,602 ms |
| コンパイル使用メモリ | 78,632 KB |
| 実行使用メモリ | 37,260 KB |
| 最終ジャッジ日時 | 2024-07-20 02:07:29 |
| 合計ジャッジ時間 | 5,721 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 7 |
| other | AC * 29 |
ソースコード
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main {
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
// 入力
FastScanner sc = new FastScanner(System.in);
long[] A = new long[5];
for(int i = 0; i < 5; i++){
A[i] = sc.nextLong();
}
// フィボナッチ数列作成
long[] fibo = new long[100];
Arrays.fill(fibo,-1L);
fibo[0] = 1L;
fibo[1] = 1L;
for(int i = 2; i < 100; i++){
fibo[i] = fibo[i-1] + fibo[i-2];
if(fibo[i] > 1000000000000000L){
break;
}
}
// 判定
int count = 0;
int startId = -1;
long num = A[4];
for(int j = 0; j < 100; j++){
if(num == fibo[j]){
startId = j;
count++;
break;
}else if(num < fibo[j]){
break;
}
}
//System.out.println(startId);
if(startId != -1){
int id = startId + 1;
for(int i = 3; i >= 0; i--){
//System.out.println("A=" + A[i] + " fibo=" + fibo[id]);
if(A[i] == fibo[id]){
count++;
id++;
}else{
break;
}
}
}
if(startId == 0){
startId = 1;
int id = startId + 1;
int count2 = 1;
for(int i = 3; i >= 0; i--){
if(A[i] == fibo[id]){
count2++;
id++;
}else{
break;
}
}
//System.out.println(count);
//System.out.println(count2);
if(count < count2){
count = count2;
}
}
// 出力
System.out.println(count);
}
// 高速スキャナー
static class FastScanner {
private BufferedReader reader = null;
private StringTokenizer tokenizer = null;
public FastScanner(InputStream in) {
reader = new BufferedReader(new InputStreamReader(in));
tokenizer = null;
}
public String next() {
if (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public String nextLine() {
if (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
return reader.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken("\n");
}
public long nextLong() {
return Long.parseLong(next());
}
public int nextInt() {
return Integer.parseInt(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public int[] nextIntArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public long[] nextLongArray(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
}
}
RISE70226821