結果
問題 | No.3037 Restricted Lucas (Hard) |
ユーザー | 👑 Nachia |
提出日時 | 2020-10-22 22:37:51 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,895 bytes |
コンパイル時間 | 817 ms |
コンパイル使用メモリ | 72,320 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-21 09:37:50 |
合計ジャッジ時間 | 1,915 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
ソースコード
#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))))))); // sixty two 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 = 0; 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; }