結果
問題 | No.194 フィボナッチ数列の理解(1) |
ユーザー | 37zigen |
提出日時 | 2016-05-04 23:54:07 |
言語 | Java21 (openjdk 21) |
結果 |
MLE
|
実行時間 | - |
コード長 | 2,260 bytes |
コンパイル時間 | 3,001 ms |
コンパイル使用メモリ | 94,136 KB |
実行使用メモリ | 769,972 KB |
最終ジャッジ日時 | 2024-04-15 11:45:25 |
合計ジャッジ時間 | 20,635 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 161 ms
106,712 KB |
testcase_01 | AC | 166 ms
42,780 KB |
testcase_02 | AC | 260 ms
43,296 KB |
testcase_03 | AC | 198 ms
42,584 KB |
testcase_04 | AC | 231 ms
42,964 KB |
testcase_05 | AC | 213 ms
43,108 KB |
testcase_06 | AC | 222 ms
42,932 KB |
testcase_07 | AC | 232 ms
43,080 KB |
testcase_08 | AC | 194 ms
42,968 KB |
testcase_09 | AC | 220 ms
43,064 KB |
testcase_10 | AC | 201 ms
42,976 KB |
testcase_11 | AC | 203 ms
43,128 KB |
testcase_12 | AC | 212 ms
43,168 KB |
testcase_13 | AC | 198 ms
42,976 KB |
testcase_14 | AC | 166 ms
42,920 KB |
testcase_15 | AC | 250 ms
43,076 KB |
testcase_16 | AC | 232 ms
43,284 KB |
testcase_17 | AC | 201 ms
43,128 KB |
testcase_18 | AC | 237 ms
43,332 KB |
testcase_19 | AC | 252 ms
43,372 KB |
testcase_20 | AC | 190 ms
42,724 KB |
testcase_21 | MLE | - |
testcase_22 | AC | 190 ms
42,680 KB |
testcase_23 | MLE | - |
testcase_24 | MLE | - |
testcase_25 | MLE | - |
testcase_26 | MLE | - |
testcase_27 | MLE | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
ソースコード
package yukicoder; import java.math.BigInteger; import java.util.Arrays; import java.util.Scanner; public class Main{ public static void main(String[] args)throws Exception{ new Main().solve(); } final long mod=1_000_000_000+7; void solve(){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); Long k=sc.nextLong(); long ansS=0,ansF=0; long[][] a=new long[n+1][1]; for(int i=0;i<n;i++){ int d=sc.nextInt(); if(i+1==n)ansF=d; a[0][0]+=d; a[n-i][0]=d; if(i+1==k)ansS=d; } //コンパニオン行列 long[][] B=new long[n+1][n+1]; for(int i=0;i<n+1;i++)B[0][i]=1; for(int i=1;i<n+1;i++)B[1][i]=1; for(int i=0;i<n-1;i++)B[i+2][i+1]=1; long[][] ans=MtPow(k-n,B); ans=MtPrd(ans, a,mod); if(n<k){ System.out.println(ans[1][0]+" "+ans[0][0]); }else{ System.out.println(ansF+" "+ansS); } } //行列のN乗;R=A^n long[][] MtPow(long n,long[][] A){ BigInteger b=new BigInteger("0"); b=bi(n); long[][] B=new long[A.length][A[0].length]; for(int i=0;i<A.length;i++){ B[i][i]=1; } while(b.compareTo(BigInteger.valueOf(1))>=0){ if((b.remainder(BigInteger.valueOf(10)).compareTo(BigInteger.valueOf(1)))==0){ B=MtPrd(A,B,mod); b=b.subtract(BigInteger.valueOf(1)); b=b.divide(BigInteger.valueOf(10)); }else if((b.remainder(BigInteger.valueOf(10)).compareTo(BigInteger.valueOf(1)))!=0){ b=b.divide(BigInteger.valueOf(10)); } A=MtPrd(A,A,mod); } return B; } long[][] MtPrd(long[][] A,long[][] B,long mod){ long[][] C=new long[A.length][B[0].length]; for(int i=0;i<A.length;i++){ for(int j=0;j<B[0].length;j++){ for(int k=0;k<A[0].length;k++){ C[i][j]+=(A[i][k]%mod)*(B[k][j]%mod); C[i][j]%=mod; } } } return C; } //2進数に変換;convert to binary BigInteger bi(long n){ BigInteger b=new BigInteger("0"); BigInteger digit=new BigInteger("10"); for(int i=0;n!=0;i++){ if(n%2==0){ n/=2; }else{ n-=1; n/=2; b=b.add(digit.pow(i)); } } return b; } void showMt(long[][] A){ for(int i=0;i<A.length;i++){ for(int j=0;j<A[0].length;j++){ System.out.print(A[i][j]+" "); } System.out.println(); } } void tr(Object...o){System.out.println(Arrays.deepToString(o));} }