QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#655065 | #9225. Fibonacci Fusion | real_sigma_team# | WA | 2364ms | 411184kb | C++17 | 3.6kb | 2024-10-19 00:14:16 | 2024-10-19 00:14:17 |
Judging History
answer
#include<bits/stdc++.h>
int64_t mod = 1836311903ll * 17711;
int64_t mod2 = 1836311903ll * 17711;
const int K = 2200;
int64_t add(int64_t a, int64_t b) {
return a + b >= mod ? a + b - mod : a + b;
}
int64_t sub(int64_t a, int64_t b) {
return a >= b ? a - b : a + mod - b;
}
int64_t mul(int64_t a, int64_t b) {
return 1ll * a * b % mod;
}
std::vector<int64_t> st, hsh;
int main() {
std::cin.tie(nullptr)->sync_with_stdio(false);
{
int64_t a = 0, b = 1;
st = {a, b};
for (int i = 0; i < 100000; ++i) {
int64_t c = add(a, b);
st.push_back(c);
a = b;
b = c;
}
std::sort(st.begin(), st.end());
st.resize(std::unique(st.begin(), st.end()) - st.begin());
}
{
mod = (1ll << 61) - 1;
int64_t a = 0, b = 1;
hsh = {a, b};
for (int i = 0; i < 1e7; ++i) {
int64_t c = add(a, b);
hsh.push_back(c);
a = b;
b = c;
}
std::sort(hsh.begin(), hsh.end());
}
int n;
std::cin >> n;
std::unordered_map<int64_t, std::map<int64_t, int>> mp;
std::vector<std::string> fib;
long long ans = 0;
for (int i = 0; i < n; ++i) {
std::string s;
std::cin >> s;
int64_t h1 = 0, h2 = 0;
for (auto x : s) {
int64_t h12 = add(h1, h1);
int64_t h14 = add(h12, h12);
int64_t h18 = add(h14, h14);
h1 = add(add(h18, h12), x - '0');
h2 = (h2 * 10 + (x - '0')) % mod2;
}
if (std::binary_search(hsh.begin(), hsh.end(), h1)) {
fib.push_back(s);
continue;
}
for (auto h : st) {
int64_t need = h - h2;
if (need < 0) need += mod2;
for (auto [h3, w] : mp[need]) {
ans += std::binary_search(hsh.begin(), hsh.end(), add(h1, h3)) * w;
}
}
mp[h2][h1]++;
}
std::sort(fib.begin(), fib.end(), [&](auto& i, auto& j) {
if (i.size() != j.size()) return i.size() < j.size();
return i < j;
});
std::vector<std::pair<std::string, int>> buba;
for (auto s : fib) {
if (buba.empty() || buba.back().first != s) buba.emplace_back(s, 1);
else buba.back().second++;
}
for (int i = 0; i + 1 < buba.size(); ++i) {
int64_t h1 = 0;
for (auto x : buba[i].first) {
int64_t h12 = add(h1, h1);
int64_t h14 = add(h12, h12);
int64_t h18 = add(h14, h14);
h1 = add(add(h18, h12), x - '0');
}
int64_t h2 = 0;
for (auto x : buba[i + 1].first) {
int64_t h22 = add(h2, h2);
int64_t h24 = add(h22, h22);
int64_t h28 = add(h24, h24);
h2 = add(add(h28, h22), x - '0');
}
ans += std::binary_search(hsh.begin(), hsh.end(), add(h1, h2)) * 1ll * buba[i].second * buba[i + 1].second;
}
for (auto [s, cnt] : buba) {
int64_t h1 = 0, h2 = 0;
for (auto x : s) {
int64_t h12 = add(h1, h1);
int64_t h14 = add(h12, h12);
int64_t h18 = add(h14, h14);
h1 = add(add(h18, h12), x - '0');
h2 = (h2 * 10 + (x - '0')) % mod2;
}
for (auto h : st) {
int64_t need = h - h2;
if (need < 0) need += mod2;
for (auto [h3, w] : mp[need]) {
ans += std::binary_search(hsh.begin(), hsh.end(), add(h1, h3)) * 1ll * w * cnt;
}
}
}
std::cout << ans << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 824ms
memory: 136316kb
input:
6 50 8 8 5 72 354224848179261915070
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 923ms
memory: 136260kb
input:
28 200878223506436882933619847964496455022155117513398820563747455993172799881403389571477889821109288771413214004090719097929400406252135763028179112130390003528046316900603668569910008417315162907579003880220844686222148696041857432602133894827753998572080650383305777912447151917272483538029469449...
output:
27
result:
ok 1 number(s): "27"
Test #3:
score: 0
Accepted
time: 2364ms
memory: 411184kb
input:
5187 2640352926124261912741724778991366987330659389621881876017670644497364093930668042530271338851702874394631009332660937266680740235862107353443518003194307853104942996827176097428402408674756368623972812842571069642405111849826172879369776309763468485788964245903781380419155348915131587410703749...
output:
6073
result:
ok 1 number(s): "6073"
Test #4:
score: -100
Wrong Answer
time: 854ms
memory: 136876kb
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:
9999998556
result:
wrong answer 1st numbers differ - expected: '15003749259', found: '9999998556'