結果
問題 | No.1136 Four Points Tour |
ユーザー | face4 |
提出日時 | 2020-08-04 22:22:29 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 55 ms / 2,000 ms |
コード長 | 1,574 bytes |
コンパイル時間 | 2,891 ms |
コンパイル使用メモリ | 77,476 KB |
実行使用メモリ | 50,360 KB |
最終ジャッジ日時 | 2024-09-14 21:57:17 |
合計ジャッジ時間 | 5,690 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 53 ms
50,268 KB |
testcase_01 | AC | 53 ms
49,908 KB |
testcase_02 | AC | 54 ms
50,064 KB |
testcase_03 | AC | 54 ms
50,348 KB |
testcase_04 | AC | 55 ms
49,892 KB |
testcase_05 | AC | 53 ms
50,176 KB |
testcase_06 | AC | 54 ms
50,188 KB |
testcase_07 | AC | 55 ms
50,184 KB |
testcase_08 | AC | 54 ms
50,092 KB |
testcase_09 | AC | 54 ms
50,172 KB |
testcase_10 | AC | 55 ms
49,968 KB |
testcase_11 | AC | 54 ms
49,860 KB |
testcase_12 | AC | 54 ms
50,160 KB |
testcase_13 | AC | 54 ms
50,188 KB |
testcase_14 | AC | 54 ms
50,152 KB |
testcase_15 | AC | 55 ms
50,240 KB |
testcase_16 | AC | 54 ms
49,928 KB |
testcase_17 | AC | 54 ms
50,256 KB |
testcase_18 | AC | 54 ms
49,976 KB |
testcase_19 | AC | 55 ms
50,360 KB |
testcase_20 | AC | 53 ms
50,272 KB |
testcase_21 | AC | 54 ms
50,300 KB |
01_Sample03_evil.txt | AC | 54 ms
50,260 KB |
04_Rnd_large_evil1.txt | AC | 53 ms
50,080 KB |
04_Rnd_large_evil2.txt | AC | 54 ms
50,236 KB |
04_Rnd_large_evil3.txt | AC | 55 ms
50,024 KB |
04_Rnd_large_evil4.txt | AC | 54 ms
50,244 KB |
04_Rnd_large_evil5.txt | AC | 55 ms
50,320 KB |
04_Rnd_large_evil6.txt | AC | 54 ms
50,076 KB |
04_Rnd_large_evil7.txt | AC | 54 ms
50,100 KB |
04_Rnd_large_evil8.txt | AC | 54 ms
50,212 KB |
04_Rnd_large_evil9.txt | AC | 54 ms
49,884 KB |
04_Rnd_large_evil10.txt | AC | 53 ms
50,324 KB |
05_Rnd_huge_evil1.txt | AC | 54 ms
50,200 KB |
05_Rnd_huge_evil2.txt | AC | 55 ms
50,068 KB |
05_Rnd_huge_evil3.txt | AC | 55 ms
50,304 KB |
05_Rnd_huge_evil4.txt | AC | 54 ms
50,236 KB |
05_Rnd_huge_evil5.txt | AC | 54 ms
50,220 KB |
05_Rnd_huge_evil6.txt | AC | 55 ms
50,188 KB |
05_Rnd_huge_evil7.txt | AC | 54 ms
50,244 KB |
99_evil_01.txt | AC | 54 ms
50,224 KB |
ソースコード
import java.io.*; import java.util.Stack; class Matrix{ long a[][]; int r, c; long mod; Matrix(int r, int c){ this(r, c, 1000000007); } Matrix(int r, int c, long m){ this.r = r; this.c = c; this.mod = m; a = new long[r][c]; } static Matrix pow(Matrix A, long n){ Matrix B = new Matrix(A.r, A.r); for(int i = 0; i < A.r; i++){ B.a[i][i] = 1; } while(n > 0){ if((n&1) == 1){ B = mul(B, A); } A = mul(A, A); n >>>= 1; } return B; } static Matrix mul(Matrix A, Matrix B){ Matrix C = new Matrix(A.r, B.c); for(int i = 0; i < A.r; i++){ for(int j = 0; j < B.c; j++){ for(int k = 0; k < A.c; k++){ C.a[i][j] += A.a[i][k]*B.a[k][j]%A.mod; C.a[i][j] %= A.mod; } } } return C; } } public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); long n = Long.parseLong(br.readLine()); Matrix m = new Matrix(4, 4); for(int i = 0; i < 4; i++){ for(int j = 0; j < 4; j++){ if(i != j) m.a[i][j] = 1; } } m = Matrix.pow(m, n); Matrix x = new Matrix(4, 1); x.a[0][0] = 1; x = Matrix.mul(m, x); System.out.println(x.a[0][0]); } }