結果

問題 No.1419 Power Moves
ユーザー minatominato
提出日時 2020-12-28 07:35:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 4,247 bytes
コンパイル時間 2,004 ms
コンパイル使用メモリ 204,192 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-08 10:58:27
合計ジャッジ時間 4,022 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 2 ms
5,248 KB
testcase_03 AC 1 ms
5,248 KB
testcase_04 AC 2 ms
5,248 KB
testcase_05 AC 2 ms
5,248 KB
testcase_06 AC 1 ms
5,248 KB
testcase_07 AC 2 ms
5,248 KB
testcase_08 AC 2 ms
5,248 KB
testcase_09 AC 11 ms
5,248 KB
testcase_10 AC 2 ms
5,248 KB
testcase_11 AC 3 ms
5,248 KB
testcase_12 AC 12 ms
5,248 KB
testcase_13 AC 11 ms
5,248 KB
testcase_14 AC 13 ms
5,248 KB
testcase_15 AC 14 ms
5,248 KB
testcase_16 AC 12 ms
5,248 KB
testcase_17 AC 2 ms
5,248 KB
testcase_18 AC 2 ms
5,248 KB
testcase_19 AC 2 ms
5,248 KB
testcase_20 AC 13 ms
5,248 KB
testcase_21 AC 14 ms
5,248 KB
testcase_22 AC 13 ms
5,248 KB
testcase_23 AC 12 ms
5,248 KB
testcase_24 AC 12 ms
5,248 KB
testcase_25 AC 13 ms
5,248 KB
testcase_26 AC 15 ms
5,248 KB
testcase_27 AC 14 ms
5,248 KB
testcase_28 AC 14 ms
5,248 KB
testcase_29 AC 14 ms
5,248 KB
testcase_30 AC 14 ms
5,248 KB
testcase_31 AC 14 ms
5,248 KB
testcase_32 AC 15 ms
5,248 KB
testcase_33 AC 13 ms
5,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)

//末尾空白

template<int m>
struct ModInt {
  public:
    static constexpr int mod() { return m; }
    static ModInt raw(int v) {
        ModInt x;
        x._v = v;
        return x;
    }

    ModInt() : _v(0) {}
    ModInt(long long v) {
        long long x = (long long)(v % (long long)(umod()));
        if (x < 0) x += umod();
        _v = (unsigned int)(x);
    }

    unsigned int val() const { return _v; }

    ModInt& operator++() {
        _v++;
        if (_v == umod()) _v = 0;
        return *this;
    }
    ModInt& operator--() {
        if (_v == 0) _v = umod();
        _v--;
        return *this;
    }
    ModInt operator++(int) {
        ModInt result = *this;
        ++*this;
        return result;
    }
    ModInt operator--(int) {
        ModInt result = *this;
        --*this;
        return result;
    }

    ModInt& operator+=(const ModInt& rhs) {
        _v += rhs._v;
        if (_v >= umod()) _v -= umod();
        return *this;
    }
    ModInt& operator-=(const ModInt& rhs) {
        _v -= rhs._v;
        if (_v >= umod()) _v += umod();
        return *this;
    }
    ModInt& operator*=(const ModInt& rhs) {
        unsigned long long z = _v;
        z *= rhs._v;
        _v = (unsigned int)(z % umod());
        return *this;
    }
    ModInt& operator^=(long long n) {
        ModInt x = *this;
        *this = 1;
        if (n < 0) x = x.inv(), n = -n;
        while (n) {
            if (n & 1) *this *= x;
            x *= x;
            n >>= 1;
        }
        return *this;
    }
    ModInt& operator/=(const ModInt& rhs) { return *this = *this * rhs.inv(); }

    ModInt operator+() const { return *this; }
    ModInt operator-() const { return ModInt() - *this; }

    ModInt pow(long long n) const {
        ModInt r = *this;
        r ^= n;
        return r;
    }
    ModInt inv() const {
        int a = _v, b = umod(), y = 1, z = 0, t;
        for (; ; ) {
            t = a / b; a -= t * b;
            if (a == 0) {
                assert(b == 1 || b == -1);
                return ModInt(b * z);
            }
            y -= t * z;
            t = b / a; b -= t * a;
            if (b == 0) {
                assert(a == 1 || a == -1);
                return ModInt(a * y);
            }
            z -= t * y;
        }
    }

    friend ModInt operator+(const ModInt& lhs, const ModInt& rhs) { return ModInt(lhs) += rhs; }
    friend ModInt operator-(const ModInt& lhs, const ModInt& rhs) { return ModInt(lhs) -= rhs; }
    friend ModInt operator*(const ModInt& lhs, const ModInt& rhs) { return ModInt(lhs) *= rhs; }
    friend ModInt operator/(const ModInt& lhs, const ModInt& rhs) { return ModInt(lhs) /= rhs; }
    friend ModInt operator^(const ModInt& lhs, long long rhs) { return ModInt(lhs) ^= rhs; }
    friend bool operator==(const ModInt& lhs, const ModInt& rhs) { return lhs._v == rhs._v; }
    friend bool operator!=(const ModInt& lhs, const ModInt& rhs) { return lhs._v != rhs._v; }
    friend ModInt operator+(long long lhs, const ModInt& rhs) { return (ModInt(lhs) += rhs); }
    friend ModInt operator-(long long lhs, const ModInt& rhs) { return (ModInt(lhs) -= rhs); }
    friend ModInt operator*(long long lhs, const ModInt& rhs) { return (ModInt(lhs) *= rhs); }
    friend ostream &operator<<(ostream& os, const ModInt& rhs) { return os << rhs._v; }

  private:
    unsigned int _v;
    static constexpr unsigned int umod() { return m; }
};

constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;

using mint = ModInt<MOD>;

ll pow_mod(ll x, ll k, ll mod) {
    ll ret = 1;
    while (k > 0) {
        if (k&1) {
            ret = ret*x%mod;
        }
        x = x*x%mod;
        k >>= 1;
    }
    return ret;
};

int main() {
    int N,K; cin >> N >> K;

    int q = pow_mod(2,K-1,N);
    mint p = mint(2).pow(K-1);
    p -= q;
    p /= N;

    vector<mint> ans(N);
    rep(i,N) {
        int m = (i*2+1)%N;
        ans[m] += p;
        if (i < q) ans[m]++;
    }
    auto ansrev = ans;
    rep(i,N) ans[(N-i)%N] += ansrev[i];

    mint b = mint(2).pow(-K);
    rep(i,N) ans[i] *= b;

    rep(i,N) cout << ans[i] << " " << '\n';
}
0