QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#708318 | #9225. Fibonacci Fusion | mzh | RE | 364ms | 527860kb | C++14 | 1.8kb | 2024-11-03 21:24:05 | 2024-11-03 21:24:05 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define mk make_pair
using namespace std;
const int N = 1e5 + 10,M = 1e7 + 1e6 + 10;
int P[5] = {1000000000 + 7,998244353,11451419198};
int Q,n;
int h[3][M],tmp[5],t[5];
long double a[M];
int b[M];
string s[N];
map <pair<int,pair<int,int> >,int> mp;
bool cmp(string x,string y){
if(x.size() != y.size())return x.size() < y.size();
return x < y;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin >> n;
a[1] = 1;b[1] = 0;
a[2] = 1;b[2] = 0;
for(int j = 3;j < M;j ++){
int d = b[j - 1];
if(b[j - 2] < d){
a[j] = a[j - 2] / 10 + a[j - 1];
b[j] = floor(a[j] / 10) + b[j - 1];
if(b[j] > b[j - 1])a[j] /= 10;
}else{
a[j] = a[j - 1] + a[j - 2];
b[j] = floor(a[j] / 10) + b[j - 1];
if(b[j] > b[j - 1])a[j] /= 10;
}
}
for(int i = 0;i < 3;i ++){
h[i][1] = 1;
h[i][2] = 1;
for(int j = 3;j < M;j++){
h[i][j] = (h[i][j - 1] + h[i][j - 2]) % P[i];
}
}
for(int i = 1;i <= n;i ++){
cin >> s[i];
}
sort(s + 1,s + n + 1,cmp);
int ans = 0;
for(int i = 1;i <= n;i ++){
tmp[0] = tmp[1] = tmp[2] = 0;
for(auto u : s[i]){
for(int j = 0;j < 3;j ++){
tmp[j] = tmp[j] * 10 + u - '0';
tmp[j] %= P[j];
}
}
int len = s[i].size();
int p,l = 1,r = M - 1;
while(l + 1 < r){
int mid = l + r >> 1;
if(b[mid] >= len)r = mid;
else l = mid;
}
if(b[l] >= len)p = l;
else p = r;
// cout<<p<<endl;
for(int j = max((int)-10,-p + 1);j <= 10;j ++){
// cout<<j<<endl;
for(int k = 0;k < 3;k ++){
t[k] = (h[k][p + j] - tmp[k] + P[k]) % P[k];
}
pair<int,pair<int,int> > tt = mk(t[0],mk(t[1],t[2]));
if(mp.find(tt) != mp.end()){
ans += mp[tt];
}
}
mp[mk(tmp[0],mk(tmp[1],tmp[2]))]++;
}
cout<<ans<<'\n';
return 0;
}
/*
2
1
1
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 304ms
memory: 522564kb
input:
6 50 8 8 5 72 354224848179261915070
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 341ms
memory: 527532kb
input:
28 200878223506436882933619847964496455022155117513398820563747455993172799881403389571477889821109288771413214004090719097929400406252135763028179112130390003528046316900603668569910008417315162907579003880220844686222148696041857432602133894827753998572080650383305777912447151917272483538029469449...
output:
27
result:
ok 1 number(s): "27"
Test #3:
score: 0
Accepted
time: 364ms
memory: 527860kb
input:
5187 2640352926124261912741724778991366987330659389621881876017670644497364093930668042530271338851702874394631009332660937266680740235862107353443518003194307853104942996827176097428402408674756368623972812842571069642405111849826172879369776309763468485788964245903781380419155348915131587410703749...
output:
6073
result:
ok 1 number(s): "6073"
Test #4:
score: -100
Runtime Error
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...