結果

問題 No.1136 Four Points Tour
ユーザー TlapesiumTlapesium
提出日時 2021-01-24 03:04:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,947 bytes
コンパイル時間 3,719 ms
コンパイル使用メモリ 230,552 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-30 14:45:07
合計ジャッジ時間 6,310 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#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 matrix {
public:
	std::vector<std::vector<long long>> v;
	matrix() = default;
	matrix(int N) {
		v = std::vector(N, std::vector(N, 0LL));
		for (int i = 0; i < N; i++)v[i][i] = 1;
	}
	matrix(int N, int M, ll 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(row);
		}
	}

	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(row);
		}
		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(), 0LL));
		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" : " ");
		}
	}
};

matrix operator+(const matrix& l, const matrix& r) { return matrix(l) += r; }
matrix operator-(const matrix& l, const matrix& r) { return matrix(l) -= r; }
matrix operator*(const matrix& l, const matrix& r) { return matrix(l) *= r; }

struct modmat : public matrix {
	using matrix::matrix;
	modmat& operator*= (const modmat& r) {
		std::vector c(height(), std::vector(r.width(), 0LL));
		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] % MOD;
					c[i][j] %= MOD;
				}
			}
		}
		v = c;
		return *this;
	}
};

modmat operator*(const modmat& l, const modmat& r) { return modmat(l) *= r; }

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.dump();
	m = m * modmat{ {1},{0},{0},{0} };
	cout << m.v[0][0] << endl;
}
0