QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#596647 | #9225. Fibonacci Fusion | rikka_lyly# | TL | 209ms | 165208kb | C++20 | 1.5kb | 2024-09-28 16:11:08 | 2024-09-28 16:11:08 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
const ll MOD = 4179340454199820289;
#define MAXN 20000010
ll fib[MAXN];
void pre()
{
fib[0] = 0, fib[1] = 1;
for (int i = 2; i < MAXN; i++)
{
fib[i] = ((__int128_t)fib[i - 2] + fib[i - 1]) % MOD;
}
}
__int128 trans(const string& s)
{
__int128 ans = 0;
for (int i = 0; i < s.length(); i++)
{
(ans *= 10) %= MOD;
(ans += s[i] - '0') %= MOD;
}
return ans;
}
const double lgB = log10((1 + sqrt(5)) / 2);
void solve()
{
int n;
cin >> n;
multiset<ll> sts;
vector<string> ss(n);
for (int i = 0; i < n; i++)
{
cin >> ss[i];
}
sort(ss.begin(), ss.end(), [](const string &a, const string &b)->bool
{
if(a.length() != b.length())
return a.length() < b.length();
return a < b; });
ll ans = 0;
for (int i = 0; i < n; i++)
{
const string &s = ss[i];
ll x = trans(s);
int p = s.length() / lgB;
for (int i = max(0, p - 20); i < min(p + 20, MAXN); i++)
{
ll y = (fib[i] - x + MOD) % MOD;
ans += sts.count(y);
}
sts.insert(x);
}
cout << ans << '\n';
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
pre();
int t = 1;
while (t--)
{
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 122ms
memory: 159872kb
input:
6 50 8 8 5 72 354224848179261915070
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 174ms
memory: 164800kb
input:
28 200878223506436882933619847964496455022155117513398820563747455993172799881403389571477889821109288771413214004090719097929400406252135763028179112130390003528046316900603668569910008417315162907579003880220844686222148696041857432602133894827753998572080650383305777912447151917272483538029469449...
output:
27
result:
ok 1 number(s): "27"
Test #3:
score: 0
Accepted
time: 209ms
memory: 165208kb
input:
5187 2640352926124261912741724778991366987330659389621881876017670644497364093930668042530271338851702874394631009332660937266680740235862107353443518003194307853104942996827176097428402408674756368623972812842571069642405111849826172879369776309763468485788964245903781380419155348915131587410703749...
output:
6073
result:
ok 1 number(s): "6073"
Test #4:
score: -100
Time Limit Exceeded
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...