結果
| 問題 |
No.673 カブトムシ
|
| コンテスト | |
| ユーザー |
ngtkana
|
| 提出日時 | 2020-04-04 11:15:18 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 797 bytes |
| コンパイル時間 | 1,882 ms |
| コンパイル使用メモリ | 199,164 KB |
| 最終ジャッジ日時 | 2025-01-09 13:59:41 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 14 |
ソースコード
#include<bits/stdc++.h>
using lint=long long;
using real=long double;
int main(){
std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
lint mod=1'000'000'007;
lint b,c,d;std::cin>>b>>c>>d;b%=mod,c%=mod;
assert(c==1||c%mod!=1);
auto cal=[b,c,mod,memo=std::map<lint,std::pair<lint,lint>>()]
(auto&&cal,lint x)mutable->std::pair<lint,lint>
{
if(x==0)return {0,1};
if(x==1)return {1,c};
if(auto found=memo.find(x);found!=memo.end()){
return found->second;
}
auto&&[fi,ci]=cal(cal,x/2);
auto&&[fj,cj]=cal(cal,(x+1)/2);
return memo[x]={(fi+ci*fj)%mod,(ci*cj)%mod};
};
std::cout<<((cal(cal,d).first*b)%mod*c)%mod<<'\n';
}
ngtkana