結果

問題 No.657 テトラナッチ数列 Easy
ユーザー tsuchinagatsuchinaga
提出日時 2019-03-27 14:28:01
言語 Go
(1.22.1)
結果
AC  
実行時間 447 ms / 2,000 ms
コード長 505 bytes
コンパイル時間 13,331 ms
コンパイル使用メモリ 221,240 KB
実行使用メモリ 80,024 KB
最終ジャッジ日時 2024-04-19 09:55:54
合計ジャッジ時間 13,946 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,812 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 383 ms
79,768 KB
testcase_05 AC 16 ms
6,940 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 401 ms
80,024 KB
testcase_09 AC 17 ms
6,944 KB
testcase_10 AC 19 ms
6,940 KB
testcase_11 AC 19 ms
6,940 KB
testcase_12 AC 46 ms
7,704 KB
testcase_13 AC 447 ms
80,020 KB
testcase_14 AC 420 ms
80,020 KB
testcase_15 AC 423 ms
80,020 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	var n, m int
	_, _ = fmt.Scan(&n)
	mod := 17

	sc := bufio.NewScanner(os.Stdin)
	nacci := map[int]int{1: 0, 2: 0, 3: 0, 4: 1}
	last := 4
	for i := 0; i < n; i++ {
		sc.Scan()
		m, _ = strconv.Atoi(sc.Text())

		if num, ok := nacci[m]; ok {
			fmt.Println(num)
		} else {
			for j := last + 1; j <= m; j++ {
				nacci[j] = (nacci[j-1] + nacci[j-2] + nacci[j-3] + nacci[j-4]) % mod
			}
			last = m
			fmt.Println(nacci[m])
		}
	}
}
0