結果

問題 No.1275 綺麗な式
ユーザー longrunlongrun
提出日時 2020-10-31 00:02:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,127 bytes
コンパイル時間 2,030 ms
コンパイル使用メモリ 199,544 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-29 09:08:58
合計ジャッジ時間 4,674 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
#define rep2(i,m,n) for (int i = (m); i < (n); ++i)
#define rep(i,n) rep2(i,0,n)
#define debug(x) cout << x << endl;
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> P;
template<typename T> struct V : vector<T> { using vector<T>::vector; };
V() -> V<int>;
V(size_t) -> V<int>;
template<typename T> V(size_t, T) -> V<T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
const int INF = 1<<30;
const ll LINF = 1LL<<61;
const ll MOD = 1000000007;
// using mint = modint1000000007;

struct mint
{
    ll x;
    mint(ll x = 0) : x(x % MOD) {}
    mint& operator+=(const mint rh) { if((x += rh.x) >= MOD) x -= MOD; return *this; }
    mint& operator-=(const mint rh) { if((x += MOD-rh.x) >= MOD) x -= MOD; return *this; }
    mint& operator*=(const mint rh) { (x *= rh.x) %= MOD; return *this; }
    mint operator+(const mint rh) const { return mint(*this) += rh; }
    mint operator-(const mint rh) const { return mint(*this) -= rh; }
    mint operator*(const mint rh) const { return mint(*this) *= rh; }
    mint pow(ll k) const
    {
        if(!k) return 1;
        mint a = x;
        mint res = 1;
        while(k)
        {
            if(k & 1) res *= a;
            k >>= 1;
            a *= a;
        }
        return res;
    }
    mint inv() const { return pow(MOD-2); }
    mint& operator/=(const mint rh) { return *this *= rh.inv(); }
    mint operator/(const mint rh) { return mint(*this) /= rh; }
};

//2*2正方行列
struct matrix
{
    mint a, b, c, d;
    matrix(mint a, mint b, mint c, mint d) : a(a), b(b), c(c), d(d) {}
    matrix& operator*=(const matrix rh)
    {
        mint p = rh.a, q = rh.b, r = rh.c, s = rh.d;
        mint na, nb, nc, nd;
        na = a*p + b*r;
        nb = a*q + b*s;
        nc = c*p + d*r;
        nd = c*q + d*s;
        a = na; b = nb; c = nc; d = nd;
        return *this;
    }
    matrix operator*(const matrix rh) const { return matrix(*this) *= rh; }
};

matrix power(matrix x, ll k)
{
    if(k <= 1)
    {
        return x;
    }
    matrix res = x;
    k--;
    while(k)
    {
        if(k & 1) res = (res * x);
        k >>= 1;
        x = (x * x);
    }
    return res;
}



int main()
{
    ll a, b, n;
    cin >> a >> b >> n;
    mint a1(2), a2(2*a);
    matrix s(mint(2*a), mint(mint(b)-mint(a*a)), mint(1), mint(0));
    matrix p = power(s, n);
    mint ans = p.c * a2 + p.d * a1;
    cout << ans.x << endl;
    return 0;
}
0