結果

問題 No.1706 Many Bus Stops (hard)
ユーザー miscalcmiscalc
提出日時 2021-10-08 23:32:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,105 bytes
コンパイル時間 4,557 ms
コンパイル使用メモリ 208,728 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-30 13:42:15
合計ジャッジ時間 3,650 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/modint>
using namespace std;
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();

  if (n2 != m1)
  {
    cerr << "Error: matrix product is not defined\n";
    abort();
  }

  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 C, N, M;
  cin >> C >> N >> M;
  const mint inv = mint(1) / C;
  mmat A = {{inv, 0, 0, inv},
            {0, inv, (C - 1) * inv, inv},
            {1, 0, 0, 0},
            {0, 1, 0, 0}};

  mmat pwA = mmatrixpow(A, N - 1);
  mmat x = {{inv}, {0}, {1}, {0}};
  mmat y = mmatrixprod(pwA, x);
  mint tmp = y.at(0).at(0);
  mint ans = 1 - (1 - tmp).pow(M);
  cout << ans.val() << endl;
}
0