結果
問題 | No.1879 How many matchings? |
ユーザー | miscalc |
提出日時 | 2022-03-18 22:34:14 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 4,533 bytes |
コンパイル時間 | 2,267 ms |
コンパイル使用メモリ | 213,524 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-03 07:27:02 |
合計ジャッジ時間 | 4,218 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | AC | 2 ms
6,820 KB |
testcase_02 | RE | - |
testcase_03 | AC | 2 ms
6,816 KB |
testcase_04 | RE | - |
testcase_05 | AC | 2 ms
6,816 KB |
testcase_06 | RE | - |
testcase_07 | AC | 2 ms
6,820 KB |
testcase_08 | RE | - |
testcase_09 | AC | 2 ms
6,816 KB |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | AC | 2 ms
6,816 KB |
testcase_14 | RE | - |
ソースコード
#include <bits/stdc++.h> using namespace std; #include <atcoder/modint> using namespace atcoder; //using mint = modint998244353; using mint = modint1000000007; using ll = long long; using ld = long double; using pll = pair<ll, ll>; using tlll = tuple<ll, ll, ll>; constexpr ll INF = 1LL << 60; template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;} template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;} ll safemod(ll A, ll M) {return (A % M + M) % M;} ll divfloor(ll A, ll B) {if (B < 0) {return divfloor(-A, -B);} return (A - safemod(A, B)) / B;} ll divceil(ll A, ll B) {if (B < 0) {return divceil(-A, -B);} return divfloor(A + B - 1, B);} template<class T> void unique(vector<T> &V) {V.erase(unique(V.begin(), V.end()), V.end());} template<class T> void sortunique(vector<T> &V) {sort(V.begin(), V.end()); V.erase(unique(V.begin(), V.end()), V.end());} #define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false) template<class T> void printvec(vector<T> &V) {int _n = V.size(); for (int i = 0; i < _n; i++) cout << V[i] << (i == _n - 1 ? "" : " ");cout << '\n';} template<class T> void printvect(vector<T> &V) {for (auto v : V) cout << v << '\n';} template<class T> void printvec2(vector<vector<T>> &V) {for (auto &v : V) printvec(v);} template<class T, T(*e0)(), T(*e1)()> struct matrix : vector<vector<T>> { using vector<vector<T>>::vector; using vector<vector<T>>::operator=; matrix(int n, int m, T a = e0()) { (*this) = vector<vector<T>>(n, vector<T>(m, e0())); for (int i = 0; i < min(n, m); i++) { (*this)[i][i] = a; } } matrix operator-() const { int N = (*this).size(), M = (*this)[0].size(); matrix res(*this); for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { res[i][j] = -res[i][j]; } } return res; } matrix &operator+=(const matrix &A) { int N = (*this).size(), M = (*this)[0].size(); assert(A.size() == N && A[0].size() == M); for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { (*this)[i][j] += A[i][j]; } } return *this; } matrix &operator-=(const matrix &A) { return (*this) += -A; } matrix &operator*=(const T x) { int N = (*this).size(), M = (*this)[0].size(); for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { (*this)[i][j] *= x; } } return *this; } matrix &operator/=(const T x) { int N = (*this).size(), M = (*this)[0].size(); for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { (*this)[i][j] /= x; } } return *this; } friend matrix &operator*=(const T x, matrix &A) { return A *= x; } vector<T> operator*(const vector<T> &v) { int N = (*this).size(), M = (*this)[0].size(); assert(v.size() == M); vector<T> res(N, e0()); for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { res[i] += (*this)[i][j] * v[j]; } } return res; } matrix operator*(const matrix &A) { int N = (*this).size(), M = (*this)[0].size(); assert(A.size() == M); int K = A[0].size(); matrix res(N, K, e0()); for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { for (int k = 0; k < K; k++) { res[i][k] += (*this)[i][j] * A[j][k]; } } } return res; } matrix pow(ll k) { int N = (*this).size(), M = (*this)[0].size(); assert(N == M); matrix res(N, N, e1()), tmp(*this); while (k > 0) { if (k & 1) res *= tmp; tmp *= tmp; k >>= 1; } return res; } matrix operator+(const matrix &A) const { return matrix(*this) += A; } matrix operator-(const matrix &A) const { return matrix(*this) -= A; } matrix operator*(const T x) const { return matrix(*this) *= x; } matrix operator/(const T x) const { return matrix(*this) /= x; } friend matrix operator*(const T x, matrix &A) { return A *= x; } matrix &operator*=(const matrix &A) { return (*this) = (*this) * A; } }; // e0, e1 は加法, 乗法の単位元。問題によって書き換える template <class T> constexpr T e0() { return 0; } template <class T> constexpr T e1() { return 1; } int main() { ll N; cin >> N; assert(N % 2 == 0); matrix<mint, e0, e1> A = {{1, 1}, {1, 0}}; vector<mint> ans = {1, 0}; ans = A.pow(N / 2) * ans; cout << ans.at(0).val() << endl; }