結果

問題 No.1050 Zero (Maximum)
ユーザー i_mrhji_mrhj
提出日時 2020-05-11 10:13:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 130 ms / 2,000 ms
コード長 1,862 bytes
コンパイル時間 774 ms
コンパイル使用メモリ 94,280 KB
実行使用メモリ 4,856 KB
最終ジャッジ日時 2023-09-25 06:52:01
合計ジャッジ時間 2,805 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 29 ms
4,376 KB
testcase_03 AC 17 ms
4,376 KB
testcase_04 AC 79 ms
4,508 KB
testcase_05 AC 84 ms
4,528 KB
testcase_06 AC 35 ms
4,376 KB
testcase_07 AC 44 ms
4,376 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 22 ms
4,376 KB
testcase_10 AC 107 ms
4,764 KB
testcase_11 AC 74 ms
4,500 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 117 ms
4,856 KB
testcase_17 AC 130 ms
4,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#include <set>
#include <map>
#include <complex>

#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 1000000007;
long long INF = 1000000000000000; //10^15
typedef long long ll;
typedef unsigned long long ull;


ll powMod(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll t = powMod(x, n/2, mod);
  t = t * t % mod;
  if (n & 1) return t * x % mod;
  return t;
}

ll gcd(ll a, ll b) {
  if (a == 0 || b == 0) return a + b;
  if (b > a) return gcd(b, a);
  return gcd(b, a % b);
}

void MatrixPro(ll *g, ll *h, ll *m, int size) {
  //g * h = m
  rep(i, size) rep(j, size) {
    m[size * i + j] = 0;
    rep(k, size) {
      m[size * i + j] += g[size * i + k] * h[size * k + j] % MOD;
      m[size * i + j] %= MOD;
    }
  }
  return;
}

//g^n = h, size <= 100
void MatrixExpo(ll *g, ll *h, int size, ll n) {
  if (n == 0) {
    rep(i, size) rep(j, size) {
      if (i == j) h[size * i + j] = 1;
      else h[size * i + j] = 0;
    }
    return;
  }
  
  ll a[10010];
  MatrixExpo(g, a, size, n / 2);
  ll b[10010];
  MatrixPro(a, a, b, size);
  if (!(n & 1)) {
    rep(i, size) rep(j, size) {
      h[size * i + j] = b[size * i + j];
    }
    return;
  } else {
    MatrixPro(b, g, h, size);
    return;
  }
}


int main(void) {

  ll m, k;
  cin >> m >> k;

  ll x[3000] = {};
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      int t = i*j%m;
      x[t*m+i]++;
      t = (i+j)%m;
      x[t*m+i]++;
    }
  }
  //rep(i, m*m) cout << x[i] << endl;

  ll y[3000] = {};
  MatrixExpo(x, y, m, k);

  cout << y[0] << endl;

}
  
0