結果

問題 No.1419 Power Moves
ユーザー SSRSSSRS
提出日時 2021-03-05 21:48:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,525 bytes
コンパイル時間 1,806 ms
コンパイル使用メモリ 167,224 KB
実行使用メモリ 13,760 KB
最終ジャッジ日時 2024-04-16 09:15:14
合計ジャッジ時間 7,812 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
long long modpow(long long a, long long b, long long mod){
  long long ans = 1;
  while (b > 0){
    if (b % 2 == 1){
      ans *= a;
      ans %= MOD;
    }
    a *= a;
    a %= MOD;
    b /= 2;
  }
  return ans;
}
long long modinv(long long a){
  return modpow(a, MOD - 2, MOD);
}
int main(){
  int N, K;
  cin >> N >> K;
  if (N % 2 == 1){
    vector<long long> cnt(N, 0);
    long long r = modpow(2, K - 1, N);
    long long q = (modpow(2, K - 1, MOD) - r + MOD) % MOD * modinv(N) % MOD;
    for (int i = 0; i < N; i++){
      cnt[i] += q * 2;
      cnt[i] %= MOD;
    }
    for (int i = 0; i < r; i++){
      int p = (i * 2 + 1) % N;
      cnt[p]++;
      cnt[p] %= MOD;
      cnt[(N - p) % N]++;
      cnt[(N - p) % N] %= MOD;
    }
    for (int i = 0; i < N; i++){
      cnt[i] *= modinv(modpow(2, K, MOD));
      cnt[i] %= MOD;
      cout << cnt[i] << endl;
    }
  } else {
    vector<long long> cnt(N, 0);
    long long r = modpow(2, K - 1, N / 2);
    long long q = (modpow(2, K - 1, MOD) - r + MOD) % MOD * modinv(N / 2) % MOD;
    for (int i = 0; i < N / 2; i++){
      cnt[i * 2 + 1] += q * 2;
      cnt[i * 2 + 1] %= MOD;
    }
    for (int i = 0; i < r; i++){
      int p = (i * 2 + 1) % N;
      cnt[p]++;
      cnt[p] %= MOD;
      cnt[(N - p) % N]++;
      cnt[(N - p) % N] %= MOD;
    }
    for (int i = 0; i < N; i++){
      cnt[i] *= modinv(modpow(2, K, MOD));
      cnt[i] %= MOD;
      cout << cnt[i] << endl;
    }
  }
}
0