結果
| 問題 |
No.1136 Four Points Tour
|
| ユーザー |
Tlapesium
|
| 提出日時 | 2021-01-24 03:05:16 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 2,936 bytes |
| コンパイル時間 | 17,730 ms |
| コンパイル使用メモリ | 294,908 KB |
| 最終ジャッジ日時 | 2025-01-18 07:45:07 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
| 純コード判定しない問題か言語 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 41 |
ソースコード
#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 = m * modmat{ {1},{0},{0},{0} };
cout << m.v[0][0] << endl;
}
Tlapesium