QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#633063 | #9225. Fibonacci Fusion | Mu_Silk | WA | 60ms | 172608kb | C++20 | 1.5kb | 2024-10-12 14:28:15 | 2024-10-12 14:28:15 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=200010;
const int N1=10000010;
const ll M1=1e9+7;
const ll M2=1e9+9;
pair<ll,ll> fib[N1];
string s[200010];
void init(){
fib[0]={0,0};
fib[1]={1,1};
for(int i=2;i<N1;i++){
fib[i].first=(fib[i-1].first+fib[i-2].first)%M1;
fib[i].second=(fib[i-1].second+fib[i-2].second)%M2;
}
}
int lenfib(int n){
return n*log10((1+sqrt(5)/2))-log10(sqrt(5));
}
void solve(){
init();
int n;cin>>n;
for(int i=0;i<n;i++)cin>>s[i];
sort(s,s+n,[&](const string& a,const string& b){
if(a.size()!=b.size())return a.size()<b.size();
return a<b;
});
map<pair<ll,ll>,int> mp;
ll ans=0;
for(int i=0;i<n;i++){
int len=s[i].size();
int l=0,r=N1-1;
while(r>=l){
int m=(l+r)>>1;
if(lenfib(m)>=len)r=m-1;
else l=m+1;
}
pair<ll,ll> pi={0,0};
for(auto c:s[i]){
pi.first=(pi.first*10+c-'0')%M1;
pi.second=(pi.second*10+c-'0')%M2;
}
for(int i=max(0,l-500);i<min(l+500,N1);i++){
pair<ll,ll> tmp=pi;
tmp.first=(fib[i].first-tmp.first+M1)%M1;
tmp.second=(fib[i].second-tmp.second+M2)%M2;
ans+=mp[tmp];
}
mp[pi]+=1;
}
cout<<ans<<"\n";
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int n=1;
// cin>>n;
while(n--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 36ms
memory: 166456kb
input:
6 50 8 8 5 72 354224848179261915070
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: -100
Wrong Answer
time: 60ms
memory: 172608kb
input:
28 200878223506436882933619847964496455022155117513398820563747455993172799881403389571477889821109288771413214004090719097929400406252135763028179112130390003528046316900603668569910008417315162907579003880220844686222148696041857432602133894827753998572080650383305777912447151917272483538029469449...
output:
0
result:
wrong answer 1st numbers differ - expected: '27', found: '0'