結果

問題 No.541 3 x N グリッド上のサイクルの個数
ユーザー 37zigen37zigen
提出日時 2017-07-01 06:11:28
言語 Java21
(openjdk 21)
結果
AC  
実行時間 172 ms / 2,000 ms
コード長 1,712 bytes
コンパイル時間 2,838 ms
コンパイル使用メモリ 80,384 KB
実行使用メモリ 54,824 KB
最終ジャッジ日時 2024-04-15 09:48:32
合計ジャッジ時間 13,324 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 142 ms
54,344 KB
testcase_01 AC 136 ms
54,244 KB
testcase_02 AC 142 ms
54,152 KB
testcase_03 AC 132 ms
53,996 KB
testcase_04 AC 139 ms
54,624 KB
testcase_05 AC 135 ms
54,128 KB
testcase_06 AC 136 ms
54,236 KB
testcase_07 AC 139 ms
54,468 KB
testcase_08 AC 137 ms
54,312 KB
testcase_09 AC 138 ms
53,948 KB
testcase_10 AC 142 ms
53,924 KB
testcase_11 AC 142 ms
54,708 KB
testcase_12 AC 142 ms
54,248 KB
testcase_13 AC 141 ms
54,244 KB
testcase_14 AC 141 ms
54,108 KB
testcase_15 AC 142 ms
53,900 KB
testcase_16 AC 141 ms
54,100 KB
testcase_17 AC 145 ms
53,868 KB
testcase_18 AC 142 ms
54,620 KB
testcase_19 AC 144 ms
53,876 KB
testcase_20 AC 144 ms
54,476 KB
testcase_21 AC 159 ms
54,364 KB
testcase_22 AC 160 ms
54,640 KB
testcase_23 AC 170 ms
54,148 KB
testcase_24 AC 170 ms
54,388 KB
testcase_25 AC 172 ms
54,824 KB
testcase_26 AC 159 ms
54,040 KB
testcase_27 AC 158 ms
54,348 KB
testcase_28 AC 159 ms
54,388 KB
testcase_29 AC 137 ms
54,220 KB
testcase_30 AC 142 ms
54,072 KB
testcase_31 AC 141 ms
54,132 KB
testcase_32 AC 139 ms
54,556 KB
testcase_33 AC 138 ms
53,956 KB
testcase_34 AC 140 ms
54,204 KB
testcase_35 AC 138 ms
53,864 KB
testcase_36 AC 140 ms
54,140 KB
testcase_37 AC 142 ms
54,136 KB
testcase_38 AC 143 ms
54,088 KB
testcase_39 AC 139 ms
54,060 KB
testcase_40 AC 144 ms
54,272 KB
testcase_41 AC 141 ms
54,500 KB
testcase_42 AC 139 ms
54,068 KB
testcase_43 AC 139 ms
54,144 KB
testcase_44 AC 141 ms
53,892 KB
testcase_45 AC 141 ms
54,380 KB
testcase_46 AC 139 ms
53,852 KB
testcase_47 AC 143 ms
54,220 KB
testcase_48 AC 138 ms
54,180 KB
testcase_49 AC 140 ms
54,128 KB
testcase_50 AC 141 ms
54,260 KB
testcase_51 AC 158 ms
53,924 KB
testcase_52 AC 167 ms
53,992 KB
testcase_53 AC 160 ms
54,228 KB
testcase_54 AC 169 ms
54,232 KB
testcase_55 AC 168 ms
53,944 KB
testcase_56 AC 159 ms
54,212 KB
testcase_57 AC 162 ms
54,400 KB
testcase_58 AC 169 ms
54,288 KB
testcase_59 AC 170 ms
54,120 KB
testcase_60 AC 158 ms
54,416 KB
testcase_61 AC 160 ms
54,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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);
		long n = sc.nextLong();
		// (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, long 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