結果

問題 No.1810 RGB Biscuits
ユーザー miscalcmiscalc
提出日時 2022-01-14 22:50:27
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 2,027 bytes
コンパイル時間 2,817 ms
コンパイル使用メモリ 209,196 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-08-12 21:27:45
合計ジャッジ時間 3,924 ms
ジャッジサーバーID
(参考情報)
judge9 / judge8
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 14 ms
4,380 KB
testcase_06 AC 15 ms
4,376 KB
testcase_07 AC 16 ms
4,380 KB
testcase_08 AC 16 ms
4,508 KB
testcase_09 AC 15 ms
4,380 KB
testcase_10 AC 10 ms
4,376 KB
testcase_11 AC 4 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 4 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 9 ms
4,380 KB
testcase_18 AC 9 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/modint>
using namespace atcoder;
//using mint = modint998244353;
using mint = modint1000000007;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using tlll = tuple<ll, ll, ll>;
constexpr ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll safemod(ll A, ll M) {return (A % M + M) % M;}
ll divfloor(ll A, ll B) {if (B < 0) {return divfloor(-A, -B);} return (A - safemod(A, B)) / B;}
ll divceil(ll A, ll B) {if (B < 0) {return divceil(-A, -B);} return divfloor(A + B - 1, B);}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)

using mmat = vector<vector<mint>>;
mmat mmatrixprod(mmat &A1, mmat &A2)
{
  ll n1 = A1.size(), n2 = A2.size();
  ll m1 = A1.front().size(), m2 = A2.front().size();

  assert(n2 == m1);

  mmat ret(n1, vector<mint>(m2, 0));
  for (ll i = 0; i < n1; i++)
  {
    for (ll j = 0; j < m2; j++)
    {
      for (ll k = 0; k < n2; k++)
      {
        ret[i][j] += A1[i][k] * A2[k][j];
      }
    }
  }

  return ret;
}
mmat mmatrixpow(mmat &A1, ll k)
{
  ll n = A1.size();
  mmat A10(n, vector<mint>(n, 0));
  for (ll i = 0; i < n; i++)
  {
    for (ll j = 0; j < n; j++)
    {
      A10[i][j] = A1[i][j];
    }
  }
  
  mmat ret(n, vector<mint>(n, 0));
  for (ll i = 0; i < n; i++)
  {
    ret[i][i] = 1;
  }

  while (k > 0)
  {
    if ((k & 1) != 0)
      ret = mmatrixprod(ret, A10);
    A10 = mmatrixprod(A10, A10);
    k >>= 1;
  }

  return ret;
}

int main()
{
  ll A, B;
  cin >> A >> B;

  mmat C = {{A, B}, {1, 0}};

  ll N;
  cin >> N;
  for (ll t = 0; t < N; t++)
  {
    ll T;
    cin >> T;

    mmat pw = mmatrixpow(C, T / 2);
    mmat ret0 = {{1}, {1}};
    mmat ret = mmatrixprod(pw, ret0);
    mint r = ret.at(0).at(0), g = ret.at(1).at(0);
    mint ans = r + g + (T % 2 == 0 ? 0 : A * r + B * g);
    cout << ans.val() << '\n';
  }
}
0