結果

問題 No.1050 Zero (Maximum)
ユーザー tnakao0123tnakao0123
提出日時 2020-05-09 18:48:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 2,123 bytes
コンパイル時間 1,019 ms
コンパイル使用メモリ 91,892 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-20 07:31:13
合計ジャッジ時間 2,033 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 7 ms
4,380 KB
testcase_03 AC 5 ms
4,380 KB
testcase_04 AC 16 ms
4,380 KB
testcase_05 AC 17 ms
4,376 KB
testcase_06 AC 8 ms
4,380 KB
testcase_07 AC 10 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 6 ms
4,376 KB
testcase_10 AC 22 ms
4,380 KB
testcase_11 AC 15 ms
4,384 KB
testcase_12 AC 1 ms
4,384 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 23 ms
4,380 KB
testcase_17 AC 26 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1050.cc:  No.1050 Zero (Maximum) - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_M = 50;
const int MOD = 1000000007;

/* typedef */

typedef long long ll;

typedef int vec[MAX_M];
typedef vec mat[MAX_M];

/* global variables */

mat ma, mb, ms, mt;
vec va, vb;

/* subroutines */

inline void addmod(int &a, int b) { a = (a + b) % MOD; }

inline void initvec(const int n, vec a) { memset(a, 0, sizeof(vec)); }
inline void initmat(const int n, mat a) { memset(a, 0, sizeof(mat)); }

inline void unitmat(const int n, mat a) {
  initmat(n, a);
  for (int i = 0; i < n; i++) a[i][i] = 1;
}

inline void copymat(const int n, const mat a, mat b) {
  memcpy(b, a, sizeof(mat));
}

inline void mulmat(const int n, const mat a, const mat b, mat c) {
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      c[i][j] = 0;
      for (int k = 0; k < n; k++)
        addmod(c[i][j], (ll)a[i][k] * b[k][j] % MOD);
    }
}

inline void powmat(const int n, const mat a, int b, mat c) {
  copymat(n, a, ms);
  unitmat(n, c);

  while (b > 0) {
    if (b & 1) {
      mulmat(n, c, ms, mt);
      copymat(n, mt, c);
    }

    mulmat(n, ms, ms, mt);
    copymat(n, mt, ms);
    b >>= 1;
  }
}

inline void mulmatvec(const int n, const mat a, const vec b, vec c) {
  for (int i = 0; i < n; i++) {
    c[i] = 0;
    for (int j = 0; j < n; j++)
      addmod(c[i], (ll)a[i][j] * b[j] % MOD);
  }
}

/* main */

int main() {
  int m, k;
  scanf("%d%d", &m, &k);

  initmat(m, ma);
  for (int i = 0; i < m; i++)
    for (int j = 0; j < m; j++) {
      int a = (i + j) % m, p = i * j % m;
      addmod(ma[a][i], 1);
      addmod(ma[p][i], 1);
    }

  powmat(m, ma, k, mb);

  initvec(m, va);
  va[0] = 1;

  mulmatvec(m, mb, va, vb);

  printf("%d\n", vb[0]);
  return 0;
}
0