QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#637834#9225. Fibonacci Fusionucup-team3646#TL 366ms224060kbC++202.5kb2024-10-13 14:12:262024-10-13 14:12:27

Judging History

你现在查看的是最新测评结果

  • [2024-10-13 14:12:27]
  • 评测
  • 测评结果:TL
  • 用时:366ms
  • 内存:224060kb
  • [2024-10-13 14:12:26]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define elif else if
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define pii pair<int,int>


#define repname(a, b, c, d, e, ...) e
#define rep(...)                    repname(__VA_ARGS__, rep3, rep2, rep1, rep0)(__VA_ARGS__)
#define rep0(x)                     for (int rep_counter = 0; rep_counter < (x); ++rep_counter)
#define rep1(i, x)                  for (int i = 0; i < (x); ++i)
#define rep2(i, l, r)               for (int i = (l); i < (r); ++i)
#define rep3(i, l, r, c)            for (int i = (l); i < (r); i += (c))





struct ScalarInput {
    template<class T>
    operator T(){
        T ret;
        cin >> ret;
        return ret;
    }
};
struct VectorInput {
    size_t n;
    VectorInput(size_t n): n(n) {}
    template<class T>
    operator vector<T>(){
        vector<T> ret(n);
        for(T &x : ret) cin >> x;
        return ret;
    }
};
ScalarInput input(){ return ScalarInput(); }
VectorInput input(size_t n){ return VectorInput(n); }

template<typename T>
void print(vector<T> a){
  for(int i=0;i<a.size();i++){
    cout<<a[i]<<" \n"[i+1==a.size()];
  }
}

template<class T>
void print(T x){
    cout << x << '\n';
}
 
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail){
  cout << head << ' ';
  print(forward<Tail>(tail)...);
}

long double logphi=0.2089876402499787337692720892375554168224592399182109535392875613;

constexpr ll mod=177414070102078489LL;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int N;
  int m=2'000'100;
  vector<vector<int>>sizes(m);
  vector<ll>fib;
  
  {
    long double now=-logphi;
    int idx=0;
    while(now<m-10){
      sizes[max(0,(int)floor(now))].push_back(idx);
      idx++;
      now+=logphi;
    }
    fib.resize(idx);
    fib[0]=1;
    fib[1]=2;
    for(int i=2;i<idx;i++){
      fib[i]=fib[i-1]+fib[i-2];
      fib[i]%=mod;
    }
  }

  vector<pair<int,string>>vals;
  cin>>N;
  rep(i,N){
    string s;
    cin>>s;
    vals.push_back({s.size(),s});
  }
  sort(vals.begin(),vals.end());

  ll ans=0;
  map<ll,ll>cnt;
  for(auto [len,s]:vals){
    ll hash=0;
    for(auto x:s){
      hash=(hash*10)+(x-'0');
      hash%=mod;
    }
    for(int i=max(0,len-2);i<=len+2;i++){
      for(auto j:sizes[i]){
        ll res=(fib[j]-hash+mod)%mod;
        ans+=cnt[res];
      }
    }
    cnt[hash]++;
  }
  print(ans);
}

详细

Test #1:

score: 100
Accepted
time: 316ms
memory: 211968kb

input:

6
50
8
8
5
72
354224848179261915070

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 300ms
memory: 217416kb

input:

28
200878223506436882933619847964496455022155117513398820563747455993172799881403389571477889821109288771413214004090719097929400406252135763028179112130390003528046316900603668569910008417315162907579003880220844686222148696041857432602133894827753998572080650383305777912447151917272483538029469449...

output:

27

result:

ok 1 number(s): "27"

Test #3:

score: 0
Accepted
time: 327ms
memory: 224060kb

input:

5187
2640352926124261912741724778991366987330659389621881876017670644497364093930668042530271338851702874394631009332660937266680740235862107353443518003194307853104942996827176097428402408674756368623972812842571069642405111849826172879369776309763468485788964245903781380419155348915131587410703749...

output:

6073

result:

ok 1 number(s): "6073"

Test #4:

score: 0
Accepted
time: 366ms
memory: 222980kb

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...

output:


result: