結果

問題 No.314 ケンケンパ
ユーザー tsuchinagatsuchinaga
提出日時 2019-03-25 11:03:54
言語 Go
(1.22.1)
結果
AC  
実行時間 51 ms / 1,000 ms
コード長 720 bytes
コンパイル時間 11,773 ms
コンパイル使用メモリ 223,192 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2024-04-16 16:52:40
合計ジャッジ時間 11,826 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
6,400 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 1 ms
5,248 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 5 ms
5,376 KB
testcase_18 AC 25 ms
6,272 KB
testcase_19 AC 51 ms
6,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	_, _ = fmt.Scan(&n)
	mod := int(math.Pow10(9)) + 7

	k := []int{0, 1, 0} // 0: ケンが0回連続している状態, 1: ケンが1回連続している状態, 2: ケンが2回連続している状態
	// 状態の遷移
	// [1, 0, 0] -> [0, 1, 0] // パの状態からはケンしかできない
	// [0, 1, 0] -> [1, 0, 1] // ケンの状態からはパかケンを選択できる
	// [0, 0, 1] -> [1, 0, 0] // ケンケンの状態からはパしかできない
	for i := 1; i < n; i++ {
		t := make([]int, 3)
		t[0] = (k[1] + k[2]) % mod
		t[1] += k[0]
		t[2] += k[1]

		// fmt.Println(i, k, t)
		k = t
	}

	fmt.Println((k[0] + k[1] + k[2]) % mod)
}
0