結果
問題 | No.995 タピオカオイシクナーレ |
ユーザー | 37zigen |
提出日時 | 2020-02-21 23:04:59 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 637 ms / 2,000 ms |
コード長 | 1,448 bytes |
コンパイル時間 | 4,404 ms |
コンパイル使用メモリ | 77,560 KB |
実行使用メモリ | 49,004 KB |
最終ジャッジ日時 | 2024-04-17 09:11:50 |
合計ジャッジ時間 | 13,860 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 120 ms
41,004 KB |
testcase_01 | AC | 119 ms
41,172 KB |
testcase_02 | AC | 109 ms
40,256 KB |
testcase_03 | AC | 108 ms
40,192 KB |
testcase_04 | AC | 119 ms
40,864 KB |
testcase_05 | AC | 121 ms
41,108 KB |
testcase_06 | AC | 123 ms
41,272 KB |
testcase_07 | AC | 119 ms
41,116 KB |
testcase_08 | AC | 124 ms
41,260 KB |
testcase_09 | AC | 124 ms
41,052 KB |
testcase_10 | AC | 119 ms
41,124 KB |
testcase_11 | AC | 176 ms
42,252 KB |
testcase_12 | AC | 174 ms
41,900 KB |
testcase_13 | AC | 165 ms
42,136 KB |
testcase_14 | AC | 166 ms
41,488 KB |
testcase_15 | AC | 155 ms
41,916 KB |
testcase_16 | AC | 522 ms
48,724 KB |
testcase_17 | AC | 618 ms
48,812 KB |
testcase_18 | AC | 609 ms
48,680 KB |
testcase_19 | AC | 637 ms
48,996 KB |
testcase_20 | AC | 617 ms
48,656 KB |
testcase_21 | AC | 633 ms
48,784 KB |
testcase_22 | AC | 580 ms
49,004 KB |
testcase_23 | AC | 618 ms
48,904 KB |
testcase_24 | AC | 573 ms
48,608 KB |
testcase_25 | AC | 617 ms
48,840 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)); } }