結果

問題 No.1759 Silver Tour
ユーザー NyaanNyaanNyaanNyaan
提出日時 2021-11-18 19:00:16
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,805 bytes
コンパイル時間 1,229 ms
コンパイル使用メモリ 117,344 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-09-02 00:11:35
合計ジャッジ時間 4,397 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,384 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 3 ms
4,376 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 1 ms
4,384 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 2 ms
4,508 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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";
}
0