結果

問題 No.1419 Power Moves
ユーザー m_tsubasam_tsubasa
提出日時 2021-03-05 22:35:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 135 ms / 2,000 ms
コード長 2,755 bytes
コンパイル時間 2,132 ms
コンパイル使用メモリ 203,988 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-07-29 02:47:30
合計ジャッジ時間 7,089 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

template <int mod = (int)(1e9 + 7)>
struct ModInt {
  int x;
  constexpr ModInt() : x(0) {}
  constexpr ModInt(int64_t y)
      : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  constexpr ModInt &operator+=(const ModInt &p) noexcept {
    if ((x += p.x) >= mod) x -= mod;
    return *this;
  }
  constexpr ModInt &operator-=(const ModInt &p) noexcept {
    if ((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
  constexpr ModInt &operator*=(const ModInt &p) noexcept {
    x = (int)(1LL * x * p.x % mod);
    return *this;
  }
  constexpr ModInt &operator/=(const ModInt &p) noexcept {
    *this *= p.inverse();
    return *this;
  }
  constexpr ModInt operator-() const { return ModInt(-x); }
  constexpr ModInt operator+(const ModInt &p) const noexcept {
    return ModInt(*this) += p;
  }
  constexpr ModInt operator-(const ModInt &p) const noexcept {
    return ModInt(*this) -= p;
  }
  constexpr ModInt operator*(const ModInt &p) const noexcept {
    return ModInt(*this) *= p;
  }
  constexpr ModInt operator/(const ModInt &p) const noexcept {
    return ModInt(*this) /= p;
  }
  constexpr bool operator==(const ModInt &p) const noexcept { return x == p.x; }
  constexpr bool operator!=(const ModInt &p) const noexcept { return x != p.x; }
  constexpr ModInt inverse() const noexcept {
    int a = x, b = mod, u = 1, v = 0, t = 0;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
  constexpr ModInt pow(int64_t n) const {
    ModInt res(1), mul(x);
    while (n) {
      if (n & 1) res *= mul;
      mul *= mul;
      n >>= 1;
    }
    return res;
  }
  friend constexpr ostream &operator<<(ostream &os, const ModInt &p) noexcept {
    return os << p.x;
  }
  friend constexpr istream &operator>>(istream &is, ModInt &a) noexcept {
    int64_t t = 0;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }
  constexpr int get_mod() { return mod; }
};
using mint = ModInt<>;

int n, k;

vector<mint> solve();

int main() {
  cin >> n >> k;
  auto res = solve();
  for (auto p : res) cout << p << endl;
  return 0;
}

vector<mint> solve() {
  mint all = mint(2).pow(k).inverse();
  vector<mint> cnt(n, 0);
  for (int i = 1; i <= 2 * n; i += 2) cnt[i % n] += 1;
  mint now = mint(2).pow(k) - 1;
  int len = 1, b = 2;
  while (k) {
    if (k & 1) len = 1LL * len * b % (2 * n);
    b = 1LL * b * b % (2 * n);
    k >>= 1;
  }
  len = (len - 1 + 2 * n) % (2 * n);
  now -= len;
  now /= 2 * n;
  for (auto &p : cnt) p *= now;
  for (int i = 1; i <= len; i += 2) cnt[i % n] += 1;
  vector<mint> res(n);
  for (int i = 0; i < n; ++i) res[i] = cnt[i] + cnt[(n - i) % n];
  for (auto &p : res) p *= all;
  return res;
}
0