結果

問題 No.541 3 x N グリッド上のサイクルの個数
ユーザー 37zigen37zigen
提出日時 2017-07-01 06:09:29
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,731 bytes
コンパイル時間 2,280 ms
コンパイル使用メモリ 79,924 KB
実行使用メモリ 54,696 KB
最終ジャッジ日時 2024-04-15 09:46:59
合計ジャッジ時間 12,883 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 140 ms
54,128 KB
testcase_01 AC 142 ms
54,260 KB
testcase_02 AC 135 ms
53,928 KB
testcase_03 AC 139 ms
53,964 KB
testcase_04 AC 137 ms
54,000 KB
testcase_05 AC 139 ms
54,184 KB
testcase_06 AC 141 ms
54,088 KB
testcase_07 AC 139 ms
54,052 KB
testcase_08 AC 137 ms
54,268 KB
testcase_09 AC 143 ms
54,216 KB
testcase_10 AC 140 ms
54,180 KB
testcase_11 AC 141 ms
54,264 KB
testcase_12 AC 143 ms
54,256 KB
testcase_13 AC 141 ms
54,260 KB
testcase_14 AC 141 ms
53,912 KB
testcase_15 AC 140 ms
54,112 KB
testcase_16 AC 144 ms
54,016 KB
testcase_17 AC 142 ms
54,240 KB
testcase_18 AC 145 ms
54,376 KB
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 AC 140 ms
53,912 KB
testcase_30 AC 138 ms
54,160 KB
testcase_31 AC 142 ms
54,492 KB
testcase_32 AC 138 ms
54,244 KB
testcase_33 AC 140 ms
54,116 KB
testcase_34 AC 140 ms
54,260 KB
testcase_35 AC 136 ms
54,404 KB
testcase_36 AC 142 ms
54,424 KB
testcase_37 AC 144 ms
54,108 KB
testcase_38 AC 145 ms
54,292 KB
testcase_39 AC 137 ms
54,696 KB
testcase_40 AC 140 ms
54,444 KB
testcase_41 AC 140 ms
54,292 KB
testcase_42 AC 160 ms
54,116 KB
testcase_43 AC 169 ms
54,092 KB
testcase_44 AC 152 ms
54,136 KB
testcase_45 AC 143 ms
54,252 KB
testcase_46 AC 144 ms
54,372 KB
testcase_47 AC 144 ms
54,092 KB
testcase_48 AC 142 ms
54,348 KB
testcase_49 AC 145 ms
54,512 KB
testcase_50 AC 139 ms
54,156 KB
testcase_51 RE -
testcase_52 RE -
testcase_53 RE -
testcase_54 RE -
testcase_55 RE -
testcase_56 RE -
testcase_57 RE -
testcase_58 RE -
testcase_59 RE -
testcase_60 RE -
testcase_61 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

package 郵便配達;

import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Scanner;

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

	final long MODULO = 1_000_000_000 + 7;

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		// (1,4)
		// (2,3)
		// (2,4)
		// (3,4)
		// (1,2)
		// (1,3)
		// (1,2),(3,4)
		// (1,4),(2,3)
		// s
		// t
		long[][] mt = {
				{ 1, 1, 1, 1, 1, 1, 1, 0, 1, 0 }, 
				{ 1, 1, 1, 0, 0, 1, 0, 0, 1, 0 },
				{ 1, 1, 1, 1, 0, 1, 0, 0, 1, 0 }, 
				{ 1, 0, 1, 1, 0, 0, 0, 1, 1, 0 }, 
				{ 1, 0, 0, 0, 1, 1, 0, 1, 1, 0 },
				{ 1, 1, 1, 0, 1, 1, 0, 0, 1, 0 },
				{ 0, 0, 0, 1, 1, 0, 1, 0, 1, 0 },
				{ 1, 0, 0, 0, 0, 0, 0, 1, 0, 0 },
				{ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 },
				{ 1, 1, 1, 1, 1, 1, 0, 1, 0, 1 } };
		mt = pow(mt, n + 1);
		long[][] v = { { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 1 }, { 0 } };
		v = mul(mt, v);
		System.out.println(v[9][0]);
	}

	long[][] pow(long[][] a, int n) {
		long[][] ret = new long[a.length][a.length];
		for (int i = 0; i < ret.length; ++i)
			ret[i][i] = 1;
		for (; n > 0; n >>= 1, a = mul(a, a)) {
			if (n % 2 == 1) {
				ret = mul(ret, a);
			}
		}
		return ret;
	}

	long[][] mul(long[][] a, long[][] b) {
		long[][] ret = new long[a.length][b[0].length];
		int m = a[0].length;
		assert a[0].length == b.length;
		for (int i = 0; i < a.length; ++i) {
			for (int j = 0; j < b[i].length; ++j) {
				for (int k = 0; k < m; ++k) {
					ret[i][j] = (ret[i][j] + a[i][k] * b[k][j] % MODULO) % MODULO;
				}
			}
		}
		return ret;
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}
0