結果
問題 |
No.444 旨味の相乗効果
|
ユーザー |
![]() |
提出日時 | 2025-01-01 23:01:25 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 226 ms / 2,500 ms |
コード長 | 1,122 bytes |
コンパイル時間 | 456 ms |
コンパイル使用メモリ | 31,440 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2025-01-01 23:01:34 |
合計ジャッジ時間 | 2,526 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 23 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:24:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 24 | long long c; scanf("%d %lld",&n,&c); | ~~~~~^~~~~~~~~~~~~~~~~ main.cpp:25:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 25 | for(int i=1;i<=n;i++) scanf("%d",&a[i]); | ~~~~~^~~~~~~~~~~~
ソースコード
#include<cstdio> using namespace std; const int N=90,Mod=1e9+7; int n,a[N]; struct Matrix { long long a[N][N]; Matrix() { for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) a[i][j]=0; } }; Matrix operator *(Matrix a,Matrix b) { Matrix c; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) for(int k=1;k<=n;k++) (c.a[i][j]+=a.a[i][k]*b.a[k][j]%Mod)%=Mod; return c; } int qpow(int a,long long b) { int ans=1; while(b) { if(b&1) ans=1ll*ans*a%Mod; a=1ll*a*a%Mod,b>>=1; } return ans; } int main() { //freopen("spice.in","r",stdin); //freopen("spice.out","w",stdout); long long c; scanf("%d %lld",&n,&c); for(int i=1;i<=n;i++) scanf("%d",&a[i]); Matrix ans,p; for(int i=1;i<=n;i++) ans.a[1][i]=a[i]; for(int i=1;i<=n;i++) for(int j=i;j<=n;j++) p.a[i][j]=a[j]; long long t=c; c--; while(c) { if(c&1) ans=ans*p; p=p*p,c>>=1; } //for(int i=1;i<=n;i++) { //for(int j=1;j<=n;j++) printf("%lld ",ans.a[i][j]); //puts(""); //} int sum=0; for(int i=1;i<=n;i++) (sum+=ans.a[1][i])%=Mod; for(int i=1;i<=n;i++) (sum-=qpow(a[i],t))%=Mod,(sum+=Mod)%=Mod; printf("%d",sum); return 0; }