結果
問題 | No.1136 Four Points Tour |
ユーザー | hedwig100 |
提出日時 | 2020-08-29 15:32:57 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 2,876 bytes |
コンパイル時間 | 1,784 ms |
コンパイル使用メモリ | 173,600 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-14 13:47:38 |
合計ジャッジ時間 | 3,063 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,816 KB |
testcase_02 | AC | 2 ms
6,820 KB |
testcase_03 | AC | 2 ms
6,816 KB |
testcase_04 | AC | 2 ms
6,816 KB |
testcase_05 | AC | 2 ms
6,816 KB |
testcase_06 | AC | 2 ms
6,820 KB |
testcase_07 | AC | 2 ms
6,816 KB |
testcase_08 | AC | 1 ms
6,816 KB |
testcase_09 | AC | 2 ms
6,816 KB |
testcase_10 | AC | 2 ms
6,816 KB |
testcase_11 | AC | 2 ms
6,820 KB |
testcase_12 | AC | 2 ms
6,820 KB |
testcase_13 | AC | 2 ms
6,820 KB |
testcase_14 | AC | 2 ms
6,820 KB |
testcase_15 | AC | 2 ms
6,816 KB |
testcase_16 | AC | 2 ms
6,816 KB |
testcase_17 | AC | 2 ms
6,820 KB |
testcase_18 | AC | 2 ms
6,820 KB |
testcase_19 | AC | 2 ms
6,820 KB |
testcase_20 | AC | 2 ms
6,820 KB |
testcase_21 | AC | 2 ms
6,816 KB |
01_Sample03_evil.txt | AC | 2 ms
6,820 KB |
04_Rnd_large_evil1.txt | AC | 1 ms
6,816 KB |
04_Rnd_large_evil2.txt | AC | 2 ms
6,820 KB |
04_Rnd_large_evil3.txt | AC | 2 ms
6,820 KB |
04_Rnd_large_evil4.txt | AC | 2 ms
6,816 KB |
04_Rnd_large_evil5.txt | AC | 2 ms
6,820 KB |
04_Rnd_large_evil6.txt | AC | 2 ms
6,816 KB |
04_Rnd_large_evil7.txt | AC | 1 ms
6,816 KB |
04_Rnd_large_evil8.txt | AC | 2 ms
6,816 KB |
04_Rnd_large_evil9.txt | AC | 2 ms
6,816 KB |
04_Rnd_large_evil10.txt | AC | 2 ms
6,820 KB |
05_Rnd_huge_evil1.txt | AC | 2 ms
6,820 KB |
05_Rnd_huge_evil2.txt | AC | 2 ms
6,820 KB |
05_Rnd_huge_evil3.txt | AC | 2 ms
6,816 KB |
05_Rnd_huge_evil4.txt | AC | 2 ms
6,816 KB |
05_Rnd_huge_evil5.txt | AC | 2 ms
6,816 KB |
05_Rnd_huge_evil6.txt | AC | 2 ms
6,820 KB |
05_Rnd_huge_evil7.txt | AC | 2 ms
6,816 KB |
99_evil_01.txt | AC | 2 ms
6,816 KB |
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (int)(n); i ++) #define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i) using namespace std; using ll = long long; using PL = pair<ll,ll>; using P = pair<int,int>; constexpr int INF = 1000000000; constexpr long long HINF = 1000000000000000; constexpr long long MOD = 1000000007;// = 998244353; constexpr double EPS = 1e-4; constexpr double PI = 3.14159265358979; template<int Modulus> struct ModInt { long long x; ModInt(long long x = 0) :x((x%Modulus + Modulus)%Modulus) {} constexpr ModInt &operator+=(const ModInt a) {if ((x += a.x) >= Modulus) x -= Modulus; return *this;} constexpr ModInt &operator-=(const ModInt a) {if ((x += Modulus - a.x) >= Modulus) x -= Modulus; return *this;} constexpr ModInt &operator*=(const ModInt a) {(x *= a.x) %= Modulus; return *this;} constexpr ModInt &operator/=(const ModInt a) {return *this *= a.inverse();} constexpr ModInt operator+(const ModInt a) const {return ModInt(*this) += a.x;} constexpr ModInt operator-(const ModInt a) const {return ModInt(*this) -= a.x;} constexpr ModInt operator*(const ModInt a) const {return ModInt(*this) *= a.x;} constexpr ModInt operator/(const ModInt a) const {return ModInt(*this) /= a.x;} friend constexpr ostream& operator<<(ostream& os,const ModInt<Modulus>& a) {return os << a.x;} friend constexpr istream& operator>>(istream& is,ModInt<Modulus>& a) {return is >> a.x;} ModInt inverse() const {// x ^ (-1) long long a = x,b = Modulus,p = 1,q = 0; while (b) {long long d = a/b; a -= d*b; swap(a,b); p -= d*q; swap(p,q);} return ModInt(p); } ModInt pow(long long N) {// x ^ N ModInt a = 1; while (N) { if (N&1) a *= *this; *this *= *this; N >>= 1; } return a; } }; using mint = ModInt<1000000007>; using Matrix = vector<vector<mint>>; Matrix mat_mul(Matrix &A,Matrix &B) { Matrix ans(A.size(),vector<mint>(B[0].size(),0)); for (int i = 0;i < A.size(); i++) { for (int j = 0;j < A[0].size();j ++) { for (int k = 0;k < A[0].size(); k++) { ans[i][j] += A[i][k]*B[k][j]; } } } return ans; } Matrix mat_pow(Matrix &A,long long N) { Matrix ans(A.size(),vector<mint>(A.size(),0)); for (int i = 0;i < A.size();i ++) ans[i][i] = 1; Matrix X = A; while (N > 0) { if (N&1) ans = mat_mul(ans,X); N >>= 1; X = mat_mul(X,X); } return ans; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); ll N; cin >> N; Matrix mat(4,vector<mint>(4)); rep(i,4)rep(j,4) { if (i == j) mat[i][j] = 0; else mat[i][j] = 1; } Matrix m = mat_pow(mat,N); mint ans = m[0][0]; cout << ans << '\n'; return 0; }