結果

問題 No.995 タピオカオイシクナーレ
ユーザー ganmodokixganmodokix
提出日時 2019-06-27 08:15:40
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 4,942 bytes
コンパイル時間 2,211 ms
コンパイル使用メモリ 170,848 KB
最終ジャッジ日時 2024-04-17 08:03:06
合計ジャッジ時間 2,762 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/string:43,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/bitset:52,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/x86_64-pc-linux-gnu/bits/stdc++.h:52,
                 from main.cpp:5:
/home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/bits/allocator.h: In destructor 'std::_Vector_base<long long int, std::allocator<long long int> >::_Vector_impl::~_Vector_impl()':
/home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/bits/allocator.h:184:7: error: inlining failed in call to 'always_inline' 'std::allocator< <template-parameter-1-1> >::~allocator() noexcept [with _Tp = long long int]': target specific option mismatch
  184 |       ~allocator() _GLIBCXX_NOTHROW { }
      |       ^
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/vector:66,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/queue:63,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/x86_64-pc-linux-gnu/bits/stdc++.h:157:
/home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/bits/stl_vector.h:133:14: note: called from here
  133 |       struct _Vector_impl
      |              ^~~~~~~~~~~~

ソースコード

diff #

#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール
// 剰余演算
constexpr ll p = 1000000007LL; // 10^9+7
ll powll(ll a, ll n) {
    if (n == 0) {
        return 1LL;
    } else if (n == 1) {
        return a % p;
    } else {
        ll temp = powll(a, n/2);
        temp = temp * temp % p;
        return n % 2 ? temp * a % p : temp;
    }
}

inline ll invll(ll a) { return powll(a, p-2); }

vector<ll> fac_cache = {1}, invfac_cache = {1};
void make_fac_cache(ll a) {
    ll old_max = fac_cache.size() - 1;
    if (a > old_max) {
        fac_cache   .resize(a+1);
        invfac_cache.resize(a+1);
        for (ll i = old_max + 1; i <= a; i++) {
            fac_cache[i] = fac_cache[i-1] * i % p;
        }
        invfac_cache[a] = invll(fac_cache[a]);
        for (ll i = a-1; i > old_max; i--) {
            invfac_cache[i] = invfac_cache[i+1] * (i + 1) % p;
        }
    }
}

inline ll    facll(ll a) { make_fac_cache(a); return fac_cache[a]; }
inline ll invfacll(ll a) { make_fac_cache(a); return invfac_cache[a]; }
inline bool isoutll(ll n, ll r) { return n < 0 || r < 0 || n < r; }
inline ll nPr(ll n, ll r) { return isoutll(n, r) ? 0 : facll(n) * invfacll(n-r) % p; }
inline ll nCr(ll n, ll r) { return isoutll(n, r) ? 0 : facll(n) * invfacll(n-r) % p * invfacll(r) % p; }

// 行列累乗; 1e9+7で割ったあまりを求めたい場合は適宜コメントアウトを解除

// 単位行列; idtm<型>(大きさ)
template<typename T>
vector<vector<T>> idtm(const size_t n) {
    vector<vector<T>> r(n, vector<T>(n, 0));
    REP(i, n) r[i][i] = 1;
    return r;
}

// 行列の積
template<typename T>
vector<vector<T>> mltm(const vector<vector<T>> &a, const vector<vector<T>> &b) {
    ull m = a.size(), q = b.size(), r = b[0].size();
    vector<vector<T>> c(m, vector<T>(r, (T)0));
    REP(i, m) REP(j, r) {
        REP(k, m) {
            // c[i][j] += a[i][k] * b[k][j];
            c[i][j] += a[i][k] * b[k][j] % p; c[i][j] %= p;
        }
    }
    return c;
}

// 行列の累乗
template<typename T>
vector<vector<T>> powm(const vector<vector<T>> &a, const ll n) {
    if (n == 0) {
        return idtm<T>(a.size());
    } else if (n == 1) {
        return a;
    } else if (n % 2 == 0) {
        vector<vector<T>> t = powm(a, n/2);
        return mltm(t, t);
    } else {
        vector<vector<T>> t = powm(a, n/2);
        return mltm(mltm(t, t), a);
    }
}

// 処理内容
int main() {

    clock_t sclk = clock();
    
    ll n, m, k, pp, q; cin >> n >> m >> k >> pp >> q;
    vector<ll> b(n);
    REP(i, n) cin >> b[i];

    ll bmlk = 0, bktc = 0;
    REP(i, n) {
        if (i < m){
            bmlk += b[i];
            bmlk %= p;
        } else {
            bktc += b[i];
            bktc %= p;
        }
    }

    ll pq2 = pp * invll(q) % p * 2 % p;

    ll half = invll(2);
    ll term = (1 + p - pq2) % p;
    ll pmlk = (1 + powll(term, k)    ) % p * half % p;
    ll pktc = (1 - powll(term, k) + p) % p * half % p;
    
    // DUMP(n);
    // DUMP(m);
    // DUMP(k);
    // DUMP(pp);
    // DUMP(q);
    // DUMP(bmlk);
    // DUMP(bktc);
    // DUMP(pq2);
    // DUMP(pmlk);
    // DUMP(pktc);

    cout << (bmlk * pmlk % p + bktc * pktc % p) % p << endl;

    cerr << "[DEBUG] Done in " << (double)(clock() - sclk) / CLOCKS_PER_SEC * 1e3 << " ms" << endl;
    
}
0