結果

問題 No.1050 Zero (Maximum)
ユーザー le_panda_noirle_panda_noir
提出日時 2020-05-30 19:56:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 2,079 bytes
コンパイル時間 1,159 ms
コンパイル使用メモリ 85,320 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-25 13:32:12
合計ジャッジ時間 2,148 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,948 KB
testcase_02 AC 8 ms
6,944 KB
testcase_03 AC 6 ms
6,944 KB
testcase_04 AC 20 ms
6,940 KB
testcase_05 AC 22 ms
6,940 KB
testcase_06 AC 10 ms
6,940 KB
testcase_07 AC 12 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 6 ms
6,944 KB
testcase_10 AC 27 ms
6,940 KB
testcase_11 AC 19 ms
6,940 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 29 ms
6,940 KB
testcase_17 AC 33 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
void ins() {}
template<class T,class... Rest>void ins(T& v,Rest&... rest){cin>>v;ins(rest...);}
#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)

template<int MOD> struct MInt {
  long long val;
  constexpr MInt(long long val = 0) : val(val % MOD) { if (val < 0) val += MOD; }
  MInt operator+(const MInt& n) const { return MInt(val) += n; }
  MInt operator*(const MInt& n) const { return MInt(val) *= n; }
  MInt& operator+=(const MInt& n) { val = (val + n.val) % MOD; return *this; }
  MInt& operator*=(const MInt& n) { val = (val * n.val) % MOD; return *this; }
  friend ostream& operator<<(ostream& os, const MInt& n) { os<<n.val; return os; }
};
using mint = MInt<1000000007>;

template<class T> struct Matrix {
  int width, height;
  vector<vector<T>> v;
  Matrix(int w) : width(w), height(w), v(w, vector<T>(w, 0)) {};
  Matrix(int w, int h) : width(w), height(h), v(w, vector<T>(h, 0)) {};
  Matrix operator+(const Matrix& n) const { Matrix ans = v; return ans += n; }
  Matrix operator*(const Matrix& n) const { Matrix ans = v; return ans *= n; }
  Matrix& operator+=(const Matrix& rhs) {
    for (int i = 0; i < height; ++i)
      for (int j = 0; j < width; ++j)
        v[i][j] += rhs.v[i][j];
    return *this;
  }
  Matrix& operator*=(const Matrix& rhs) {
    Matrix<T> ans(height, rhs.width);
    for (int i = 0; i < height; ++i)
      for (int j = 0; j < rhs.width; ++j)
        for (int k = 0; k < width; ++k)
          ans[i][j] += v[i][k] * rhs.v[k][j];
    width = rhs.width;
    v = ans.v;
    return *this;
  }
  Matrix pow(ll N) {
    Matrix pow = *this, ans(width);
    for (int i = 0; i < width; ++i) ans[i][i] = 1;
    for (ll p = N; p > 0; p >>= 1) {
      if (p & 1) ans *= pow;
      pow *= pow;
    }
    return ans;
  }
  vector<T>& operator[](int i) {
    return v[i];
  }
};

int main() {
  int M, K;
  ins(M, K);
  Matrix<mint> m(M);

  rep(i, M) rep(j, M) {
    m[i][(i + j)%M] += 1; m[i][(i * j)%M] += 1;
  }
  m = m.pow(K);
  cout << m[0][0] << endl;

  return 0;
}
0