結果

問題 No.314 ケンケンパ
ユーザー fjafjafja
提出日時 2017-09-19 12:13:02
言語 Java
(openjdk 23)
結果
AC  
実行時間 181 ms / 1,000 ms
コード長 626 bytes
コンパイル時間 3,531 ms
コンパイル使用メモリ 75,384 KB
実行使用メモリ 41,472 KB
最終ジャッジ日時 2024-11-08 05:32:50
合計ジャッジ時間 7,220 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class N314
{
	static long cnt=0;
	static int n;
	public static void main(String[] args)
	{
		Scanner sc=new Scanner(System.in);
		n=sc.nextInt();
		int length=2;
		long[] state=new long[3];
		long[] buf=new long[3];
		int beki=(int)Math.pow(10, 9)+7;
		state[0]=1;state[1]=1;state[2]=0;
		if(n>2)
		{
			while(length!=n)
			{
				for(int i=0;i<3;i++)
				{
					buf[i]=state[i]%beki;
				}
				state[0]=buf[2];
				state[1]=(buf[0]+buf[2]);
				state[2]=buf[1];
				length++;
			}
			for(int i=0;i<3;i++)
			{
				cnt+=state[i];
			}
		}
		else
		{cnt=n;}
		System.out.println(cnt%beki);
	}
}
0