結果
問題 | No.995 タピオカオイシクナーレ |
ユーザー | 37zigen |
提出日時 | 2020-02-21 23:04:59 |
言語 | Java19 (openjdk 21) |
結果 |
AC
|
実行時間 | 630 ms / 2,000 ms |
コード長 | 1,448 bytes |
コンパイル時間 | 2,901 ms |
コンパイル使用メモリ | 74,508 KB |
実行使用メモリ | 60,884 KB |
最終ジャッジ日時 | 2023-07-30 07:52:31 |
合計ジャッジ時間 | 13,166 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 125 ms
56,040 KB |
testcase_01 | AC | 128 ms
55,724 KB |
testcase_02 | AC | 127 ms
55,712 KB |
testcase_03 | AC | 125 ms
55,320 KB |
testcase_04 | AC | 127 ms
55,836 KB |
testcase_05 | AC | 128 ms
55,596 KB |
testcase_06 | AC | 128 ms
55,976 KB |
testcase_07 | AC | 128 ms
55,480 KB |
testcase_08 | AC | 128 ms
55,748 KB |
testcase_09 | AC | 128 ms
55,904 KB |
testcase_10 | AC | 127 ms
55,524 KB |
testcase_11 | AC | 186 ms
55,964 KB |
testcase_12 | AC | 184 ms
56,140 KB |
testcase_13 | AC | 176 ms
55,744 KB |
testcase_14 | AC | 155 ms
57,480 KB |
testcase_15 | AC | 183 ms
55,988 KB |
testcase_16 | AC | 584 ms
60,340 KB |
testcase_17 | AC | 580 ms
60,588 KB |
testcase_18 | AC | 591 ms
60,500 KB |
testcase_19 | AC | 609 ms
60,884 KB |
testcase_20 | AC | 618 ms
60,476 KB |
testcase_21 | AC | 594 ms
60,712 KB |
testcase_22 | AC | 617 ms
60,232 KB |
testcase_23 | AC | 607 ms
60,624 KB |
testcase_24 | AC | 630 ms
58,512 KB |
testcase_25 | AC | 592 ms
60,524 KB |
ソースコード
import java.io.PrintWriter; import java.util.Arrays; import java.util.HashMap; import java.util.Scanner; import java.math.*; class Main { public static void main(String[] args) throws Exception { new Main().run(); } long[][] mul(long[][] a,long[][] b){ long[][] ret=new long[2][2]; for(int i=0;i<a.length;++i){ for(int j=0;j<b[i].length;++j){ for(int k=0;k<a[i].length;++k){ ret[i][j]+=a[i][k]*b[k][j]%M; ret[i][j]%=M; } } } return ret; } long[][] mat_pow(long[][] a,long n){ long[][] ret=new long[2][2]; ret[0][0]=ret[1][1]=1; for(;n>0;n>>=1,a=mul(a,a))if(n%2==1)ret=mul(ret,a); return ret; } long pow(long a,long n){ long ret=1; for(;n>0;n>>=1,a=a*a%M)if(n%2==1)ret=ret*a%M; return ret; } long inv(long a){ return pow(a,M-2); } final long M=(long)1e9+7; void run() { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); long K=sc.nextLong(); long p=sc.nextLong(); long q=sc.nextLong(); long[] b=new long[n]; for(int i=0;i<n;++i){ b[i]=sc.nextLong(); } long prob=p*inv(q)%M; long[][] mat={{(M+1-prob)%M,prob},{prob,(M+1-prob)%M}}; long[][] A=mat_pow(mat,K); long ans=0; for(int i=0;i<n;++i){ if(i<m){ ans+=A[0][0]*b[i]%M; }else{ ans+=A[0][1]*b[i]%M; } ans%=M; } System.out.println((ans+M)%M); } static void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } }