結果
問題 | No.1136 Four Points Tour |
ユーザー | Tlapesium |
提出日時 | 2021-01-24 05:12:01 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 5,194 bytes |
コンパイル時間 | 3,432 ms |
コンパイル使用メモリ | 234,384 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-10 16:12:30 |
合計ジャッジ時間 | 4,445 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 1 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 2 ms
5,376 KB |
testcase_14 | AC | 1 ms
5,376 KB |
testcase_15 | AC | 1 ms
5,376 KB |
testcase_16 | AC | 2 ms
5,376 KB |
testcase_17 | AC | 1 ms
5,376 KB |
testcase_18 | AC | 1 ms
5,376 KB |
testcase_19 | AC | 1 ms
5,376 KB |
testcase_20 | AC | 2 ms
5,376 KB |
testcase_21 | AC | 2 ms
5,376 KB |
01_Sample03_evil.txt | AC | 1 ms
5,376 KB |
04_Rnd_large_evil1.txt | AC | 2 ms
5,376 KB |
04_Rnd_large_evil2.txt | AC | 1 ms
5,376 KB |
04_Rnd_large_evil3.txt | AC | 1 ms
5,376 KB |
04_Rnd_large_evil4.txt | AC | 2 ms
5,376 KB |
04_Rnd_large_evil5.txt | AC | 2 ms
5,376 KB |
04_Rnd_large_evil6.txt | AC | 1 ms
5,376 KB |
04_Rnd_large_evil7.txt | AC | 1 ms
5,376 KB |
04_Rnd_large_evil8.txt | AC | 2 ms
5,376 KB |
04_Rnd_large_evil9.txt | AC | 2 ms
5,376 KB |
04_Rnd_large_evil10.txt | AC | 2 ms
5,376 KB |
05_Rnd_huge_evil1.txt | AC | 2 ms
5,376 KB |
05_Rnd_huge_evil2.txt | AC | 1 ms
5,376 KB |
05_Rnd_huge_evil3.txt | AC | 2 ms
5,376 KB |
05_Rnd_huge_evil4.txt | AC | 1 ms
5,376 KB |
05_Rnd_huge_evil5.txt | AC | 2 ms
5,376 KB |
05_Rnd_huge_evil6.txt | AC | 2 ms
5,376 KB |
05_Rnd_huge_evil7.txt | AC | 2 ms
5,376 KB |
99_evil_01.txt | AC | 1 ms
5,376 KB |
ソースコード
#pragma GCC optimize("O3") #pragma GCC optimize ("unroll-loops") #pragma GCC target ("avx2") #define io_init cin.tie(0);ios::sync_with_stdio(0);cout<<fixed<<setprecision(20) #include <bits/stdc++.h> constexpr int INF = 2147483647; constexpr long long int INF_LL = 9223372036854775807; constexpr int MOD = 1000000007; constexpr double PI = 3.14159265358979323846; using namespace std; typedef long long int ll; typedef unsigned long long int ull; struct Modint { long long val = 0, mod = 1000000007; Modint(long long x, long long m) : mod(m) { val = ((x % mod) + mod) % mod; } Modint(long long x) { val = ((x % mod) + mod) % mod; } Modint& operator+=(const Modint& r) { val = (val + r.val >= mod ? val + r.val - mod : val + r.val); return *this; } Modint& operator-=(const Modint& r) { val = (val - r.val < 0 ? val - r.val + mod : val - r.val); return *this; } Modint& operator*=(const Modint& r) { val = (val * r.val) % mod; return *this; } Modint& operator/=(const Modint& r) { long long a = r.val, b = mod, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= mod; if (u < 0) u += mod; val = val * u % mod; return *this; } Modint& operator ++ () noexcept { val++; return *this; } Modint& operator -- () noexcept { val--; return *this; } Modint operator ++ (int) noexcept { auto tmp = *this; val++; return tmp; } Modint operator -- (int) noexcept { auto tmp = *this; val--; return tmp; } }; Modint operator+(const Modint& l, const Modint& r) { return Modint(l) += r; } Modint operator-(const Modint& l, const Modint& r) { return Modint(l) -= r; } Modint operator*(const Modint& l, const Modint& r) { return Modint(l) *= r; } Modint operator/(const Modint& l, const Modint& r) { return Modint(l) /= r; } Modint operator+(const Modint& l, const long long& r) { return Modint(l) += Modint(r, l.mod); } Modint operator-(const Modint& l, const long long& r) { return Modint(l) -= Modint(r, l.mod); } Modint operator*(const Modint& l, const long long& r) { return Modint(l) *= Modint(r, l.mod); } Modint operator/(const Modint& l, const long long& r) { return Modint(l) /= Modint(r, l.mod); } Modint operator+(const long long& l, const Modint& r) { return Modint(l, r.mod) += r; } Modint operator-(const long long& l, const Modint& r) { return Modint(l, r.mod) -= r; } Modint operator*(const long long& l, const Modint& r) { return Modint(l, r.mod) *= r; } Modint operator/(const long long& l, const Modint& r) { return Modint(l, r.mod) /= r; } ostream& operator << (ostream& stream, const Modint& mi) { return stream << mi.val; }; istream& operator >> (istream& stream, Modint& mi) { long long tmp; stream >> tmp; mi = Modint(tmp); return stream; }; Modint modpow(Modint x, int k) { if (k == 0)return 1; if (k % 2 == 0) return modpow(x * x, k / 2); else return x * modpow(x, k - 1); } template <class T> struct Matrix { public: std::vector<std::vector<T>> v; Matrix() = default; Matrix(int N) { v = std::vector(N, std::vector(N, T(0))); for (int i = 0; i < N; i++)v[i][i] = T(1); } Matrix(int N, int M, T x) { v = std::vector(N, std::vector(M, x)); } Matrix(std::initializer_list<std::initializer_list<long long>> list) { for (auto row : list) { v.push_back(vector<T>()); for (auto x : row) { v.back().push_back(T(x)); } } } int height() const { return v.size(); }; int width() const { return v[0].size(); }; Matrix& operator=(std::initializer_list<std::initializer_list<long long>> list) { v.clear(); for (auto row : list) { v.push_back(vector<T>()); for (auto x : row) { v.back().push_back(T(x)); } } return *this; } Matrix& operator+= (const Matrix& r) { for (int i = 0; i < height(); i++)for (int j = 0; j < width(); j++) { v[i][j] += r.v[i][j]; } return *this; } Matrix& operator-= (const Matrix& r) { for (int i = 0; i < height(); i++)for (int j = 0; j < width(); j++) { v[i][j] -= r.v[i][j]; } return *this; } Matrix& operator*= (const Matrix& r) { std::vector c(height(), std::vector(r.width(), T(0))); for (int i = 0; i < height(); i++) { for (int j = 0; j < r.width(); j++) { for (int k = 0; k < width(); k++) { c[i][j] += v[i][k] * r.v[k][j]; } } } v = c; return *this; } void dump() { for (int i = 0; i < height(); i++)for (int j = 0; j < width(); j++) { std::cout << v[i][j] << (j == width() - 1 ? "\n" : " "); } } }; template <class T> Matrix<T> operator+(const Matrix<T>& l, const Matrix<T>& r) { return Matrix<T>(l) += r; } template <class T> Matrix<T> operator-(const Matrix<T>& l, const Matrix<T>& r) { return Matrix<T>(l) -= r; } template <class T> Matrix<T> operator*(const Matrix<T>& l, const Matrix<T>& r) { return Matrix<T>(l) *= r; } using modmat = Matrix<Modint>; modmat matpow(const modmat& x, ll n) { if (n == 0)return modmat(x.height()); if (n % 2 == 0) { modmat tmp = matpow(x, n / 2); return tmp * tmp; } else { return x * matpow(x, n - 1); } } int main() { ll N; cin >> N; auto m = matpow(modmat{ {0,1,1,1},{1,0,1,1},{1,1,0,1},{1,1,1,0} }, N); m = m * modmat{ {1},{0},{0},{0} }; cout << m.v[0][0] << endl; }