QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#655101 | #9225. Fibonacci Fusion | real_sigma_team# | TL | 334ms | 406072kb | C++17 | 2.0kb | 2024-10-19 00:33:37 | 2024-10-19 00:33:42 |
Judging History
answer
#include<bits/stdc++.h>
const int K = 5;
std::array<uint64_t, K> MOD = {(1ll << 61) - 1, 100000000003, 99999999977, 100000000019, 100000000057};
int64_t add(int64_t a, int64_t b, uint64_t mod) {
return a + b >= mod ? a + b - mod : a + b;
}
int64_t sub(int64_t a, int64_t b, uint64_t mod) {
return a >= b ? a - b : a + mod - b;
}
int64_t mul(int64_t a, int64_t b, uint64_t mod) {
return (__int128)a * b % mod;
}
using num = std::array<uint64_t, K>;
num add(num a, num b) {
for (int i = 0; i < K; ++i) {
a[i] = add(a[i], b[i], MOD[i]);
}
return a;
}
num sub(num a, num b) {
for (int i = 0; i < K; ++i) {
a[i] = sub(a[i], b[i], MOD[i]);
}
return a;
}
num mul(num a, num b) {
for (int i = 0; i < K; ++i) {
a[i] = mul(a[i], b[i], MOD[i]);
}
return a;
}
const double E = 2.7182818284590452353602874713526624977572470936999595749669676277;
const double PI = 3.1415926535897932384626433832795028841971693993751058209749445923;
const double LOVV66 = sqrtl((-7286 + 183 * E + 2729 * PI + 530 * logl(2)) / 94);
const int A = 1e7;
num fib[A];
int main() {
std::cin.tie(nullptr)->sync_with_stdio(false);
fib[0].fill(0);
fib[1].fill(1);
for (int i = 2; i < A; ++i) {
fib[i] = add(fib[i - 1], fib[i - 2]);
}
int n;
std::cin >> n;
std::vector<std::string> a(n);
for (auto& i : a) std::cin >> i;
std::sort(a.begin(), a.end(), [&](auto& i, auto& j) {
if (i.size() != j.size()) return i.size() < j.size();
return i < j;
});
std::map<num, int> mp;
long long ans = 0;
for (int i = 0; i < n; ++i) {
int q = a[i].size() * LOVV66;
num h1; h1.fill(0);
for (auto c : a[i]) {
num ten; ten.fill(10);
num ch; ch.fill(c - '0');
h1 = add(mul(h1, ten), ch);
}
for (int j = std::max(0, q - 5); j <= q + 10; ++j) {
ans += mp[sub(fib[j], h1)];
}
mp[h1]++;
}
std::cout << ans;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 111ms
memory: 394224kb
input:
6 50 8 8 5 72 354224848179261915070
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 286ms
memory: 399040kb
input:
28 200878223506436882933619847964496455022155117513398820563747455993172799881403389571477889821109288771413214004090719097929400406252135763028179112130390003528046316900603668569910008417315162907579003880220844686222148696041857432602133894827753998572080650383305777912447151917272483538029469449...
output:
27
result:
ok 1 number(s): "27"
Test #3:
score: 0
Accepted
time: 334ms
memory: 406072kb
input:
5187 2640352926124261912741724778991366987330659389621881876017670644497364093930668042530271338851702874394631009332660937266680740235862107353443518003194307853104942996827176097428402408674756368623972812842571069642405111849826172879369776309763468485788964245903781380419155348915131587410703749...
output:
6073
result:
ok 1 number(s): "6073"
Test #4:
score: 0
Accepted
time: 207ms
memory: 399912kb
input:
200000 2 2 2 2 1 2 1 1 2 2 1 1 1 2 2 1 1 2 1 1 2 2 1 2 2 2 1 1 1 1 2 2 1 2 1 2 1 1 2 2 1 1 1 2 1 1 2 1 2 2 2 2 1 2 2 1 1 1 2 1 1 1 1 1 2 1 2 2 1 1 1 2 2 2 1 1 2 1 1 2 1 2 1 1 1 2 2 2 1 1 1 1 2 1 2 1 1 2 2 1 1 2 1 1 2 1 2 2 1 2 1 2 2 1 1 2 1 1 1 2 2 2 1 2 2 1 1 2 2 2 2 1 2 1 1 2 1 2 2 1 1 1 1 2 2 2 2...
output:
15003749259
result:
ok 1 number(s): "15003749259"
Test #5:
score: -100
Time Limit Exceeded
input:
200000 944176313232170622314 2590599414036674999101 753315073608896000424 9299685298577430049245 9361800333778142620806 8988699166328904060999 9606920674025578304023 4203331868598952026136 5183047027116137697788 3968714342776915029801 8130984095583566992354 3206443643596048048798 6248561214283254355...