結果
| 問題 |
No.8037 Restricted Lucas (Hard)
|
| コンテスト | |
| ユーザー |
Nachia
|
| 提出日時 | 2020-10-22 22:39:37 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 60 ms / 2,000 ms |
| コード長 | 2,883 bytes |
| コンパイル時間 | 715 ms |
| コンパイル使用メモリ | 73,324 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-21 09:37:54 |
| 合計ジャッジ時間 | 1,615 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 6 |
ソースコード
#include<iostream>
#include<vector>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const LL Zero = {};
LL increment_small(LL x) { auto V = vector<int>(x); V.emplace_back(); return V.size(); }
LL decrement_small(LL x) { auto V = vector<int>(x); V.pop_back(); return V.size(); }
const LL One = increment_small(Zero);
LL power_of_two(LL x) { return One << x; }
const LL BitNum = decrement_small(decrement_small(power_of_two(increment_small(increment_small(power_of_two(power_of_two(One)))))));
LL addition(LL a, LL b) {
LL crr = Zero, ans = Zero;
for (LL d = One; d < power_of_two(BitNum); d <<= One) {
ans |= d & (a ^ b ^ crr);
crr = d & ((a & b) | (a & crr) | (b & crr));
crr <<= One;
}
return ans;
}
LL subtruction(LL a, LL b) {
LL crr = Zero, ans = Zero;
for (LL d = One; d < power_of_two(BitNum); d <<= One) {
ans |= d & (a ^ b ^ crr);
crr = d & ((~a & (b | crr)) | (b & crr));
crr <<= One;
}
return ans;
}
LL multiplication(LL a, LL b) {
LL ans = Zero;
for (LL d = Zero; d < BitNum; d = addition(d, One)) {
if (b & power_of_two(d)) ans = addition(ans, a << d);
}
return ans;
}
LL power(LL a, LL i) {
if (i == Zero) return One;
LL res = power(multiplication(a, a), i >> One);
if (i & One) res = multiplication(res, a);
return res;
}
const LL MOD = addition(
power(
addition(addition(power_of_two(addition(addition(One, One), One)), One), One),
addition(power_of_two(addition(addition(One, One), One)), One)
),
subtruction(power_of_two(increment_small(increment_small(One))), One)
);
LL modulo(LL a) {
for (LL d = subtruction(BitNum >> One, One); d < BitNum; d = subtruction(d, One)) {
if (a >= MOD << d) a = subtruction(a, MOD << d);
}
return a;
}
const LL matrix_dim = power_of_two(One);
struct Matrix {
LL a = Zero, b = Zero, c = Zero, d = Zero;
};
Matrix multiplication(Matrix l, Matrix r) {
Matrix res;
res.a = modulo(addition(multiplication(l.a, r.a), multiplication(l.b, r.c)));
res.b = modulo(addition(multiplication(l.a, r.b), multiplication(l.b, r.d)));
res.c = modulo(addition(multiplication(l.c, r.a), multiplication(l.d, r.c)));
res.d = modulo(addition(multiplication(l.c, r.b), multiplication(l.d, r.d)));
return res;
}
Matrix power(Matrix a, LL i) {
if (i == Zero) return { One, Zero, Zero, One };
Matrix res = power(a, i >> One);
res = multiplication(res, res);
if (i & One) res = multiplication(res, a);
return res;
}
Matrix G = { One, One, One, Zero };
void loop() {
LL N; cin >> N;
Matrix powG = power(G, N);
LL ans = modulo(addition(powG.d << One, powG.b));
cout << ans << endl;
}
int main() {
int t; cin >> t;
for (int i = Zero; i < t; i = addition(i, One)) loop();
return Zero;
}
Nachia