結果
問題 | No.1759 Silver Tour |
ユーザー | NyaanNyaan |
提出日時 | 2021-11-18 19:00:16 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 1,805 bytes |
コンパイル時間 | 1,432 ms |
コンパイル使用メモリ | 114,228 KB |
最終ジャッジ日時 | 2025-01-25 19:20:22 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 40 |
ソースコード
#include <algorithm> #include <cassert> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <utility> #include <vector> using namespace std; struct IoSetupNya { IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7); } } iosetupnya; constexpr long long TEN(int n) { return n ? TEN(n - 1) * 10 : 1; } #include "atcoder/modint.hpp" using mint = atcoder::dynamic_modint<-1>; #define rep(i, N) for (int i = 0; i < (int)(N); i++) struct Mat : vector<vector<mint>> { using vector<vector<mint>>::vector; static Mat gen(int a, int b) { return Mat(a, vector<mint>(b, mint{0})); } friend Mat operator*(Mat a, Mat b) { Mat c = Mat::gen(a.size(), b[0].size()); rep(i, a.size()) rep(k, a[0].size()) rep(j, b[0].size()) { c[i][j] += a[i][k] * b[k][j]; } return c; } }; int main() { int H, W, M; cin >> H >> W >> M; mint::set_mod(M); if (H % 2 != 0) { int ans = W == 1 ? 1 % M : 0; std::cout << ans << "\n"; exit(0); } Mat v = Mat::gen(W, 1); rep(i, W) v[i][0] = 1; Mat a = Mat::gen(W, W); Mat b = a; if (W % 2 == 0) { rep(i, W) rep(j, W) { if (i < j) { if (i % 2 == 0 and j % 2 == 1) a[i][j] = 1; } if (j < i) { if (i % 2 == 1 and j % 2 == 0) a[i][j] = 1; } } } else { rep(i, W) rep(j, W) { if (i % 2 == 0 and j % 2 == 0) { if (i == j and i != 0 and i != W - 1) continue; a[i][j] = 1; } } } rep(i, W) rep(j, W) { if (abs(i - j) <= 1) b[i][j] = 1; } v = a * v; rep(_, H / 2 - 1) { v = a * (b * v); } mint ans = 0; rep(i, W) ans += v[i][0]; cout << ans.val() << "\n"; }