結果
問題 | No.2156 ぞい文字列 |
ユーザー | warabi0906 |
提出日時 | 2023-02-05 13:06:07 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 3,248 bytes |
コンパイル時間 | 4,589 ms |
コンパイル使用メモリ | 243,852 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-04 03:03:18 |
合計ジャッジ時間 | 4,982 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 2 ms
6,944 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 2 ms
6,944 KB |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | AC | 2 ms
6,944 KB |
testcase_10 | AC | 2 ms
6,944 KB |
testcase_11 | AC | 2 ms
6,944 KB |
testcase_12 | AC | 2 ms
6,940 KB |
testcase_13 | AC | 2 ms
6,940 KB |
testcase_14 | AC | 2 ms
6,944 KB |
testcase_15 | AC | 2 ms
6,944 KB |
testcase_16 | AC | 2 ms
6,940 KB |
testcase_17 | AC | 2 ms
6,944 KB |
testcase_18 | AC | 2 ms
6,944 KB |
testcase_19 | AC | 2 ms
6,940 KB |
ソースコード
#include <bits/stdc++.h> #include "atcoder/all" #define debug cout << "OK" << endl; template<typename T> inline bool chmax(T& a, const T b) { if (a < b) { a = b; return true; } return false; } template<typename T> inline bool chmin(T& a, const T b) { if (a > b) { a = b; return true; } return false; } inline int Code(char c) { if ('A' <= c and c <= 'Z')return (int)(c - 'A'); if ('a' <= c and c <= 'z')return (int)(c - 'a'); if ('0' <= c and c <= '9')return (int)(c - '0'); assert(false); } using namespace std; using namespace atcoder; #define int long long constexpr int MOD = 998244353; constexpr int INF = (1LL << 62); using minit = modint998244353; template<typename T> ostream& operator << (ostream& st, const vector<T> &v) { for (const T value : v) { st << value << " "; } return st; } template<typename T> istream& operator >> (istream& st, vector<T>& v) { for (T &value : v) { st >> value; } return st; } class Matrix { public: int mod = MOD; Matrix() {} Matrix(int x) { mat.resize(x); } Matrix(int x, int y) { mat.resize(x, vector<int>(y)); } vector<vector<int>> mat; void Set(int x, int y, int value) { mat[x][y] = value; return; } void operator = (const Matrix& m) { mat = m.mat; return; } void operator = (const vector<vector<int>>& v) { mat = v; return; } bool operator == (const Matrix& m) { return mat == m.mat; } Matrix operator + (Matrix& m) { assert(mat.size() == m.mat.size()); assert(mat[0].size() == m.mat[0].size()); Matrix m2(mat.size(), mat[0].size()); for (int i = 0; i < mat.size(); i++) { for (int j = 0; j < mat[0].size(); j++) { m2.mat[i][j] = mat[i][j] + m.mat[i][j]; m2.mat[i][j] %= mod; } } return m2; } Matrix operator - (Matrix& m) { assert(mat.size() == m.mat.size()); assert(mat[0].size() == m.mat[0].size()); Matrix m2(mat.size(), mat[0].size()); for (int i = 0; i < mat.size(); i++) { for (int j = 0; j < mat[0].size(); j++) { m2.mat[i][j] = mat[i][j] - m.mat[i][j]; m2.mat[i][j] += mod; m2.mat[i][j] %= mod; } } return m2; } Matrix operator * (Matrix& m) { assert(mat[0].size() == m.mat.size()); Matrix m2(mat.size(), m.mat[0].size()); for (int i = 0; i < mat.size(); i++) { for (int j = 0; j < m.mat[0].size(); j++) { for (int k = 0; k < m.mat.size(); k++) { m2.mat[i][j] += (mat[i][k] * m.mat[k][j]) % mod; m2.mat[i][j] %= mod; } } } return m2; } Matrix pow(int a) { bool inited = false; Matrix ans; Matrix base = (*this); for (int i = 0; i < 63; i++) { if (a & (1ll << i)) { if (!inited) { ans = base; inited = true; } else ans = ans * base; } base = base * base; } return ans; } }; ostream& operator << (ostream& st, const Matrix& m) { for (const vector<int> v : m.mat) { for (const int a : v) { cout << a << " "; } cout << endl; } return st; } void solve() { Matrix base(2, 2); base = { {1,1},{1,0} }; Matrix ot(2, 1); vector<vector<int>> p = { {1},{1} }; ot = p; int N; cin >> N; if (N == 1) { cout << 0 << endl; return; } Matrix ans = base.pow(N) * ot; cout << ans.mat[1][0] - 1 << endl; } signed main() { int T = 1; // cin >> T; for (int i = 0; i < T; i++) solve(); return 0; }