結果
| 問題 |
No.1810 RGB Biscuits
|
| コンテスト | |
| ユーザー |
houren
|
| 提出日時 | 2022-01-14 22:57:44 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 42 ms / 2,000 ms |
| コード長 | 1,442 bytes |
| コンパイル時間 | 1,891 ms |
| コンパイル使用メモリ | 179,272 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-20 13:34:44 |
| 合計ジャッジ時間 | 3,043 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 20 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
template<class T>bool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool chmax(T&a, const T&b){if(a<b){a=b;return 1;}return 0;}
const ll MOD = 1000000007;
template <typename T>
vector<vector<T>> MatrixProduct(vector<vector<T>> vec1, vector<vector<T>> vec2){
int N = vec1.size(), M = vec2[0].size(), L = vec2.size();
vector<vector<T>> res(N,vector<T>(M,0));
rep(i,N) rep(j,M) rep(k,L) res[i][j] = (res[i][j] + vec1[i][k] * vec2[k][j])%MOD;
return res;
}
int main(){
ll a,b,n;
cin >> a >> b >> n;
rep(i,n){
vector<vector<ll>> o = {
{1,0,0},
{0,1,0},
{a,b,1}
};
vector<vector<ll>> e = {
{0,0,1},
{1,0,0},
{0,0,0}
};
auto oe = MatrixProduct(e,o);
vector<vector<ll>> cookie = {{1},{1},{0}};
ll t;
cin >> t;
bool b = t%2;
t >>= 1;
while(t){
if(t&1) cookie = MatrixProduct(oe, cookie);
t >>= 1;
oe = MatrixProduct(oe,oe);
}
if(b) cookie = MatrixProduct(o, cookie);
ll ans = 0;
rep(i,3){
ans = (ans + cookie[i][0]) % MOD;
}
cout << ans << endl;
}
return 0;
}
houren