結果
| 問題 | No.1810 RGB Biscuits |
| コンテスト | |
| ユーザー |
蜜蜂
|
| 提出日時 | 2022-01-14 21:43:50 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 37 ms / 2,000 ms |
| コード長 | 2,361 bytes |
| 記録 | |
| コンパイル時間 | 3,813 ms |
| コンパイル使用メモリ | 235,136 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-20 09:03:06 |
| 合計ジャッジ時間 | 4,776 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 20 |
ソースコード
//g++ 2.cpp -std=c++14 -O2 -I .
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vst = vector<string>;
using vvst = vector<vst>;
#define fi first
#define se second
#define pb push_back
#define pq_big(T) priority_queue<T,vector<T>,less<T>>
#define pq_small(T) priority_queue<T,vector<T>,greater<T>>
#define all(a) a.begin(),a.end()
#define rep(i,start,end) for(ll i=start;i<(ll)(end);i++)
#define per(i,start,end) for(ll i=start;i>=(ll)(end);i--)
#define uniq(a) sort(all(a));a.erase(unique(all(a)),a.end())
//p*q行列aとr*s行列bの積(mod)
template <class X> vector<vector<X>> matmulti(const vector<vector<X>> &a,const vector<vector<X>> &b,X mod){
int p=a.size(),q=a[0].size(),r=b.size(),s=b[0].size();
if(q!=r){
cout<<"WARNING : SIZE ERROR"<<endl;
}
vector<vector<X>> res(p,vector<X>(s,0));
for(int i=0;i<p;i++){
for(int j=0;j<s;j++){
for(int k=0;k<q;k++){
res[i][j]+=(a[i][k]%mod*b[k][j]%mod)%mod;
}
res[i][j]%=mod;
}
}
return res;
}
//x*x行列matrixのn乗(mod)
template <class X> vector<vector<X>> matpower(const vector<vector<X>> &mat,ll n,X mod){
int x=mat.size();
if(n==0){
vector<vector<X>> res(x,vector<X>(x,0));
for(int i=0;i<x;i++){
res[i][i]=1;
}
return res;
}
if(n==1){
return mat;
}
if(n%2==0){
vector<vector<X>> p=matpower(mat,n/2,mod);
vector<vector<X>> res=matmulti(p,p,mod);
return res;
}
vector<vector<X>> p=matpower(mat,n/2,mod),q=matpower(mat,n%2,mod);
vector<vector<X>> res=matmulti(matmulti(p,p,mod),q,mod);
return res;
}
constexpr ll mod = 1e9+7;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
/*
R G B
x y 0 0
x y Ax+By 1
Ax+By x 0 2
(A B) (x)
(1 0) (y)
*/
ll a,b;
cin>>a>>b;
vvll m={{a,b},{1,0}};
int n;
cin>>n;
while(n--){
ll t;
cin>>t;
ll z=t/2;
vvll p=matpower(m,z,mod);
ll ans=0;
rep(i,0,2){
rep(j,0,2){
ans+=p[i][j];
}
}
ll r=p[0][0]+p[0][1];
ll g=p[1][0]+p[1][1];
if(t%2==1){
ans+=r*a+g*b;
}
cout<<ans%mod<<endl;
}
}
蜜蜂