結果
問題 | No.980 Fibonacci Convolution Hard |
ユーザー | ysystem7 |
提出日時 | 2020-03-17 16:58:51 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 420 ms / 2,000 ms |
コード長 | 1,408 bytes |
コンパイル時間 | 5,330 ms |
コンパイル使用メモリ | 209,792 KB |
実行使用メモリ | 50,392 KB |
最終ジャッジ日時 | 2023-08-20 18:51:18 |
合計ジャッジ時間 | 13,914 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 409 ms
50,208 KB |
testcase_01 | AC | 410 ms
50,192 KB |
testcase_02 | AC | 403 ms
50,252 KB |
testcase_03 | AC | 406 ms
50,208 KB |
testcase_04 | AC | 407 ms
50,252 KB |
testcase_05 | AC | 405 ms
50,276 KB |
testcase_06 | AC | 402 ms
50,196 KB |
testcase_07 | AC | 403 ms
50,256 KB |
testcase_08 | AC | 406 ms
50,276 KB |
testcase_09 | AC | 415 ms
50,192 KB |
testcase_10 | AC | 411 ms
50,276 KB |
testcase_11 | AC | 405 ms
50,252 KB |
testcase_12 | AC | 420 ms
50,332 KB |
testcase_13 | AC | 407 ms
50,392 KB |
testcase_14 | AC | 409 ms
50,252 KB |
testcase_15 | AC | 403 ms
50,212 KB |
testcase_16 | AC | 372 ms
50,260 KB |
ソースコード
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<n;i++) #define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i]; #define ft first #define sc second #define pb push_back #define lb lower_bound #define ub upper_bound #define all(v) (v).begin(),(v).end() #define mod 1000000007 using namespace std; typedef long long ll; template<class T> using V=vector<T>; using Graph = vector<vector<int>>; using P=pair<ll,ll>; typedef unsigned long long ull; typedef long double ldouble; template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } const ll INF=1e18; ll a[2000005],s[2000005],t[2000005]; int main(){ ll p; cin>>p; int Q; cin>>Q; a[1]=0; a[2]=1; a[3]=p; s[2]=0; s[3]=0; t[2]=1; t[3]=(t[2]+a[3]*a[3]%mod)%mod; for(ll i=4;i<=2000000;i++){ a[i]=((p*a[i-1])%mod+a[i-2])%mod; t[i]=(t[i-1]+a[i]*a[i]%mod)%mod; if(i%2==0){ ll k=i/2; ll m=(i-2)/2; s[i]=((p*s[i-1])%mod+(s[i-2]+a[k]*a[k]%mod+a[k-1]*a[k-1]%mod)%mod)%mod; }else{ ll k=i/2; s[i]=((p*((s[i-1]+a[k]*a[k])%mod))%mod+s[i-2]+2*a[k]*a[k-1]%mod)%mod; } } while(Q--){ int q; cin>>q; cout<<s[q]<<endl; } }