結果

問題 No.1810 RGB Biscuits
ユーザー 蜜蜂蜜蜂
提出日時 2022-01-14 21:43:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 2,361 bytes
コンパイル時間 3,365 ms
コンパイル使用メモリ 235,148 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-30 13:49:51
合計ジャッジ時間 4,292 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 29 ms
6,944 KB
testcase_06 AC 33 ms
6,940 KB
testcase_07 AC 32 ms
6,944 KB
testcase_08 AC 34 ms
6,944 KB
testcase_09 AC 33 ms
6,940 KB
testcase_10 AC 21 ms
6,940 KB
testcase_11 AC 3 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 7 ms
6,940 KB
testcase_15 AC 2 ms
6,948 KB
testcase_16 AC 3 ms
6,940 KB
testcase_17 AC 17 ms
6,940 KB
testcase_18 AC 17 ms
6,940 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 1 ms
6,940 KB
testcase_21 AC 5 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//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;
  }
}
0