結果

問題 No.1050 Zero (Maximum)
ユーザー 夜
提出日時 2021-02-09 18:27:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 1,693 bytes
コンパイル時間 1,664 ms
コンパイル使用メモリ 102,484 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-21 06:01:26
合計ジャッジ時間 2,368 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	long long mod = 1000000007;
	int m_size;
	cin >> m_size;
	vector<vector<long long>> mat(220);
	long long y;
	cin >> y;
	vector<vector<long long>> ans(220);
	for (int i = 0; i < m_size; i++) {
		for (int j = 0; j < m_size; j++) {
			mat[i].emplace_back(0);
		}
	}
	for (int i = 0; i < m_size; i++) {
		for (int j = 0; j < m_size; j++) {
			mat[(i + j) % m_size][i]++;
			mat[(i * j) % m_size][i]++;
		}
	}
	for (int i = 0; i < m_size; i++) {
		for (int j = 0; j < m_size; j++) {
			ans[i].emplace_back(mat[i][j]);
		}
	}
	y--;
	while (y > 0) {
		if ((y & 1) == 1) {
			vector<vector<long long>> ans_mem(220);
			for (int i = 0; i < m_size; i++) {
				for (int j = 0; j < m_size; j++) {
					ans_mem[i].emplace_back(0);
				}
			}
			for (int i = 0; i < m_size; i++) {
				for (int j = 0; j < m_size; j++) {
					for (int k = 0; k < m_size; k++) {
						ans_mem[i][j] += ans[i][k] * mat[k][j] % mod;
						ans_mem[i][j] %= mod;
					}
				}
			}
			ans = ans_mem;
		}
		vector<vector<long long>> mat_mem(220);
		for (int i = 0; i < m_size; i++) {
			for (int j = 0; j < m_size; j++) {
				mat_mem[i].emplace_back(0);
			}
		}
		for (int i = 0; i < m_size; i++) {
			for (int j = 0; j < m_size; j++) {
				for (int k = 0; k < m_size; k++) {
					mat_mem[i][j] += mat[i][k] * mat[k][j] % mod;
					mat_mem[i][j] %= mod;
				}
			}
		}
		mat = mat_mem;
		y >>= 1;
	}
	cout << ans[0][0] << endl;
}
0