結果
問題 | No.3036 Restricted Lucas (Easy) |
ユーザー | 👑 Nachia |
提出日時 | 2020-10-22 22:43:17 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 584 ms / 2,000 ms |
コード長 | 2,883 bytes |
コンパイル時間 | 793 ms |
コンパイル使用メモリ | 72,192 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-21 09:38:06 |
合計ジャッジ時間 | 4,361 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 10 ms
5,248 KB |
testcase_01 | AC | 39 ms
5,376 KB |
testcase_02 | AC | 577 ms
5,376 KB |
testcase_03 | AC | 584 ms
5,376 KB |
testcase_04 | AC | 563 ms
5,376 KB |
testcase_05 | AC | 565 ms
5,376 KB |
testcase_06 | AC | 575 ms
5,376 KB |
ソースコード
#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; }