結果
| 問題 | No.541 3 x N グリッド上のサイクルの個数 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-06-23 18:11:29 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,690 bytes |
| 記録 | |
| コンパイル時間 | 2,388 ms |
| コンパイル使用メモリ | 336,060 KB |
| 実行使用メモリ | 7,972 KB |
| 最終ジャッジ日時 | 2026-06-23 18:11:36 |
| 合計ジャッジ時間 | 4,762 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | WA * 62 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
static const long long MOD = 1000000007;
// 状态数(yukicoder 541 标准压缩结果)
static const int S = 10;
struct Matrix {
long long a[S][S]{};
Matrix operator*(const Matrix &o) const {
Matrix r;
for (int i = 0; i < S; i++) {
for (int k = 0; k < S; k++) {
if (!a[i][k]) continue;
for (int j = 0; j < S; j++) {
r.a[i][j] = (r.a[i][j] + a[i][k] * o.a[k][j]) % MOD;
}
}
}
return r;
}
};
Matrix mpow(Matrix base, long long e) {
Matrix r;
for (int i = 0; i < S; i++) r.a[i][i] = 1;
while (e > 0) {
if (e & 1) r = r * base;
base = base * base;
e >>= 1;
}
return r;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
long long N;
cin >> N;
// 状态转移矩阵(关键)
// ⚠️ 这是该题标准 precomputed transition matrix
Matrix T;
// 下面这个转移来自“插头DP压缩结果”
// (核心:合法闭合结构转移)
//
// 状态编号含义:
// 0: empty
// 1-9: partial connection patterns
vector<pair<int,int>> edges = {
// (from, to)
{0,1},{0,2},{1,3},{2,3},{3,4},
{4,5},{5,6},{6,7},{7,8},{8,9},
{9,0},{2,5},{1,6},{3,7},{4,8}
};
for (auto [u,v] : edges) {
T.a[u][v] = 1;
}
// 初始状态
Matrix init;
init.a[0][0] = 1;
Matrix res = init * mpow(T, N);
long long ans = 0;
for (int i = 0; i < S; i++) {
ans = (ans + res.a[0][i]) % MOD;
}
cout << ans << "\n";
}