結果
| 問題 |
No.1050 Zero (Maximum)
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2020-05-09 18:48:07 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 22 ms / 2,000 ms |
| コード長 | 2,123 bytes |
| コンパイル時間 | 791 ms |
| コンパイル使用メモリ | 94,988 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-06 03:26:44 |
| 合計ジャッジ時間 | 1,517 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 15 |
ソースコード
/* -*- 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;
}
tnakao0123