結果

問題 No.1136 Four Points Tour
ユーザー nmnmnmnmnmnmnmnmnmnmnmnmnmnm
提出日時 2020-07-26 22:27:22
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,295 bytes
コンパイル時間 2,542 ms
コンパイル使用メモリ 100,808 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-11 05:37:06
合計ジャッジ時間 4,648 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
01_Sample03_evil.txt AC 1 ms
4,376 KB
04_Rnd_large_evil1.txt AC 1 ms
4,376 KB
04_Rnd_large_evil2.txt AC 2 ms
4,376 KB
04_Rnd_large_evil3.txt AC 2 ms
4,380 KB
04_Rnd_large_evil4.txt AC 1 ms
4,380 KB
04_Rnd_large_evil5.txt AC 2 ms
4,376 KB
04_Rnd_large_evil6.txt AC 2 ms
4,376 KB
04_Rnd_large_evil7.txt AC 2 ms
4,380 KB
04_Rnd_large_evil8.txt AC 2 ms
4,376 KB
04_Rnd_large_evil9.txt AC 2 ms
4,376 KB
04_Rnd_large_evil10.txt AC 2 ms
4,380 KB
05_Rnd_huge_evil1.txt AC 2 ms
4,380 KB
05_Rnd_huge_evil2.txt AC 2 ms
4,376 KB
05_Rnd_huge_evil3.txt AC 1 ms
4,376 KB
05_Rnd_huge_evil4.txt AC 1 ms
4,380 KB
05_Rnd_huge_evil5.txt AC 1 ms
4,380 KB
05_Rnd_huge_evil6.txt AC 2 ms
4,376 KB
05_Rnd_huge_evil7.txt AC 2 ms
4,376 KB
99_evil_01.txt AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <assert.h>
     
using namespace std;
     
typedef long long ll;
     
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
     
#define MOD 1000000007

vector<vector<long long> > mul(vector<vector<long long> > v1, vector<vector<long long> > v2){
    vector<vector<long long> > ret(v1.size(),vector<long long>(v2[0].size(),0));
    for(int i=0;i<v1.size();i++) {
        for(int j=0;j<v2[0].size();j++) {
            for(int k=0;k<v1.size();k++) {
                ret[i][j]+=v1[i][k]*v2[k][j];
                ret[i][j]%=MOD;
            }
        }
    }
    return ret;
}

vector<vector<long long> > powmatrix(vector<vector<long long> > vv, vector<vector<long long> > v, long long n){
    vector<vector<vector<long long> > > vvv;
    vvv.push_back(vv);
    for(long long i = 0; i < 64; i++){
        vvv.push_back(mul(vvv[i],vvv[i]));
    }
    vector<vector<long long> > v1(vv.size(), vector<long long>(vv.size(), 0));
    for(int i = 0; i < vv.size(); i++)v1[i][i] = 1;
    for(int i = 0; i < 64; i++){
        if((n>>i)&1){
            v1 = mul(v1,vvv[i]);
        }
    }
    v = mul(v1,v);
    return v;
}

int main(){
  ll n;
  cin>>n;

  vector<vector<long long> > v(4, vector<long long>(1, 0));
  v[0][0] = 1;
  v[1][0] = 0;
  v[2][0] = 0;
  v[3][0] = 0;
  vector<vector<long long> > vv(4, vector<long long>(4, 0));
  vv[0][0] = 0; vv[0][1] = 1;vv[0][2] = 1; vv[0][3] = 1;
  vv[1][0] = 1; vv[1][1] = 0;vv[1][2] = 1; vv[1][3] = 1;
  vv[2][0] = 1; vv[2][1] = 1;vv[2][2] = 0; vv[2][3] = 1;
  vv[3][0] = 1; vv[3][1] = 1;vv[3][2] = 1; vv[3][3] = 0;

  vector<vector<long long> > va = powmatrix(vv,v,n);

  cout << va[0][0] << endl;
  return 0;
}
0