結果

問題 No.194 フィボナッチ数列の理解(1)
ユーザー fujisufujisu
提出日時 2015-04-26 23:07:02
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 3,145 bytes
コンパイル時間 4,228 ms
コンパイル使用メモリ 81,108 KB
実行使用メモリ 58,140 KB
最終ジャッジ日時 2023-09-18 09:28:29
合計ジャッジ時間 8,068 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
51,952 KB
testcase_01 AC 84 ms
52,124 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 148 ms
55,192 KB
testcase_21 AC 199 ms
56,380 KB
testcase_22 AC 153 ms
55,808 KB
testcase_23 AC 136 ms
55,448 KB
testcase_24 AC 163 ms
55,852 KB
testcase_25 AC 154 ms
58,140 KB
testcase_26 AC 166 ms
56,164 KB
testcase_27 AC 127 ms
55,500 KB
testcase_28 AC 139 ms
55,972 KB
testcase_29 AC 161 ms
57,516 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.IOException;
import java.util.InputMismatchException;

public class Main {
	long MOD = 1_000_000_000 + 7;

	class Node {
		long value;
		Node next;

		Node(long value, Node next) {
			this.value = value;
			this.next = next;
		}
	}

	void test1(int n, long k, long[] a) {
		Node first = null;
		Node last = null;

		Node p = null;
		long sum = 0;
		for (int i = 0; i < n; i++) {
			Node tmp = new Node(a[i], null);
			if (first == null) {
				first = tmp;
				p = tmp;
			} else {
				p.next = tmp;
				p = tmp;
			}
			sum += a[i];
			sum %= MOD;
		}
		last = p;

		long tmp = sum;
		for (int i = n; i < k; i++) {
			Node node = new Node(tmp, null);

			sum += tmp;

			tmp -= first.value;
			first = first.next;
			last.next = node;
			last = last.next;
			tmp += last.value;

			tmp %= MOD;
			tmp += MOD;
			tmp %= MOD;
			sum %= MOD;
			sum += MOD;
			sum %= MOD;
		}
		System.out.println(last.value + " " + sum);
	}

	void test2(int n, long k, int[] a) {

	}

	void run() {
		MyScanner sc = new MyScanner();

		int n = sc.nextInt();
		long k = sc.nextLong();
		long[] a = sc.nextLongArray(n);

		if (n <= 10000 && k <= 1000000) {
			test1(n, k, a);
		} else {

		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	public void mapDebug(int[][] a) {
		System.out.println("--------map display---------");
		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < a[i].length; j++) {
				System.out.printf("%3d ", a[i][j]);
			}
			System.out.println();
		}
		System.out.println("----------------------------" + '\n');
	}

	class MyScanner {
		int read() {
			try {
				return System.in.read();
			} catch (IOException e) {
				throw new InputMismatchException();
			}
		}

		boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		boolean isEndline(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		int[] nextIntArray(int n) {
			int[] array = new int[n];
			for (int i = 0; i < n; i++)
				array[i] = nextInt();
			return array;
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		long[] nextLongArray(int n) {
			long[] array = new long[n];
			for (int i = 0; i < n; i++)
				array[i] = nextLong();
			return array;
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		double[] nextDoubleArray(int n) {
			double[] array = new double[n];
			for (int i = 0; i < n; i++)
				array[i] = nextDouble();
			return array;
		}

		String next() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		String[] nextStringArray(int n) {
			String[] array = new String[n];
			for (int i = 0; i < n; i++)
				array[i] = next();

			return array;
		}

		String nextLine() {
			int c = read();
			while (isEndline(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndline(c));
			return res.toString();
		}
	}
}
0