結果

問題 No.1706 Many Bus Stops (hard)
ユーザー tabae326tabae326
提出日時 2021-10-08 23:55:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 3,134 bytes
コンパイル時間 2,831 ms
コンパイル使用メモリ 220,924 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-30 14:24:31
合計ジャッジ時間 3,974 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
// Ref: https://qiita.com/ysuzuki19/items/d89057d65284ba1a16ac
#define dump(var)  do{std::cerr << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cerr << e << "\n";}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cerr << e << " "; } std::cerr << "\n";}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ std::cerr << "\n"; for(const auto& v : vv){ view(v); } }
template<typename T> void dump_cout(const T& v) { for(long long i = 0; i < v.size(); i++) std::cout << v[i] << (i == v.size()-1 ? "\n" : " "); }

#include <atcoder/modint>
using mint = atcoder::modint1000000007;

namespace mm {
 
    template <class T> using matrix = std::vector<std::vector<T>>;

    template <class T> 
    matrix<T> E(int n) {
        matrix<T> res(n, std::vector<T>(n, 0));
        for(int i = 0; i < n; i++) res[i][i] = 1;
        return res;
    }

    template <class T> 
    matrix<T> matMul(matrix<T> a, matrix<T> b) {
        assert(a.size() && b.size());
        assert(a[0].size() == b.size());
        matrix<T> res(a.size(), std::vector<T>(b[0].size(), 0));
        for(int i = 0; i < a.size(); i++) {
            for(int j = 0; j < b[0].size(); j++) {
                for(int k = 0; k < b.size(); k++) {
                    res[i][j] += a[i][k] * b[k][j];
                }
            }
        }
        return res;
    }
 
    template <class T> 
    std::vector<T> vecMul(matrix<T> a, std::vector<T> b) {
        assert(a.size() && b.size());
        assert(a[0].size() == b.size());
        std::vector<T> res(b.size(), 0);
        for(int i = 0; i < a.size(); i++) {
            for(int j = 0; j < b.size(); j++) {
                res[i] += a[i][j] * b[j];
            }
        }
        return res;
    }

    template <class T> 
    matrix<T> matPow(matrix<T> a, long long p) {
        assert(a.size() && a.size() == a[0].size());
        matrix<T> res(a.size(), std::vector<T>(a.size(), 0));
        for(int i = 0; i < a.size(); i++) res[i][i] = 1;
        while(p) {
            if(p & 1) res = matMul(res, a);
            a = matMul(a, a);
            p /= 2;
        }
        return res;
    }
 
}

using namespace mm;

void F(ll c, ll n, ll m) {
    double a = 1. / c;   
    double b = 1. - a;
    matrix<double> M = {
        {a, 0, 0, a},
        {0, b, b, 0},
        {1, 0, 0, 0},
        {0, 1, 0, 0}
    };
    vector<double> V = {a, 0, 1, 0};
    auto RM = matPow(M, n);
    auto RV = vecMul(RM, V);
    dump(RV);
}


void solve() {
    ll c, n, m;
    cin >> c >> n >> m;    
    mint C = c;
    matrix<mint> M = {
        {1/C, 0, 0, 1/C},
        {0, 1/C, 1-1/C, 1-2/C},
        {1, 0, 0, 0},
        {0, 1, 0, 0}
    };
    vector<mint> V = {1/C, 0, 1, 0};
    auto RM = matPow(M, n);
    auto RV = vecMul(RM, V);
    mint ans = 1 - (1-RV[2]).pow(m);
    cout << ans.val() << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}
0