結果

問題 No.194 フィボナッチ数列の理解(1)
ユーザー fujisufujisu
提出日時 2015-04-26 22:58:30
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 3,015 bytes
コンパイル時間 2,190 ms
コンパイル使用メモリ 77,072 KB
実行使用メモリ 56,712 KB
最終ジャッジ日時 2023-09-18 12:23:38
合計ジャッジ時間 6,324 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
52,104 KB
testcase_01 AC 73 ms
52,560 KB
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 AC 113 ms
55,476 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 RE -
testcase_31 WA -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
	long MOD = (long) 1e+9 + 7;

	class Node {
		int value;
		Node next;

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

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

		Node p = null;
		int 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;

		int 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;

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

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

		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] a = sc.nextIntArray(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