QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#690024#9225. Fibonacci Fusionucup-team902#WA 325ms67272kbC++231.8kb2024-10-30 19:51:202024-10-30 19:51:22

Judging History

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

  • [2024-10-30 19:51:22]
  • 评测
  • 测评结果:WA
  • 用时:325ms
  • 内存:67272kb
  • [2024-10-30 19:51:20]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const double del = (1.0 + sqrt(5)) / 2.0;
const double w = log10(del);
bool cmp(string a, string b) {
    return a.length() < b.length();
}
const int mod1 = 1e9 + 7, mod2 = 1e9 + 9;
pair<int, int> add(pair<int, int> x, pair<int, int> y) {
    pair<int, int> res = {0, 0};
    res.first = (x.first + y.first) % mod1;
    res.second = (x.second + y.second) % mod2;
    return res;
}
pair<int, int> sub(pair<int, int> x, pair<int, int> y) {
    pair<int, int> res = {0, 0};
    res.first = (x.first - y.first + mod1) % mod1;
    res.second = (x.second - y.second + mod2) % mod2;
    return res;
}
pair<int, int> F[5000005];
string s[200005];
void solve() {
    int n;
    cin >> n;
    F[0] = F[1] = {1, 1};
    for (int i = 2; i <= 5000000; ++i) F[i] = add(F[i - 1], F[i - 2]);
    for (int i = 1; i <= n; ++i) cin >> s[i];
    sort(s + 1, s + n + 1, cmp);
    unordered_map<long long, int> app;
    long long ans = 0;
    for (int i = 1; i <= n; ++i) {
        int ls = 0, rs = 0;
        int len = s[i].length();
        for (int j = 0; j < len; ++j) ls = (10ll * ls % mod1 + s[i][j] - '0') % mod1, rs = (10ll * rs % mod2 + s[i][j] - '0') % mod2;
        int di = len / w;
        pair<int, int> now = {ls, rs};
        for (int j = max(di - 5, 0); j <= min(di + 15, 5000000); ++j) {
            pair<int, int> nxt = sub(F[j], now);
            long long flag = 1ll * nxt.first * mod2 + nxt.second;
            if (app.count(flag)) ans += app[flag];
        }
        long long now1 = 1ll * ls * mod2 + rs;
        if (app.count(now1))
            app[now1]++;
        else
            app[now1] = 1;
    }
    cout << ans << endl;
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int T = 1;
    //cin >> T;
    while (T--) {
        solve();
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 24ms
memory: 48872kb

input:

6
50
8
8
5
72
354224848179261915070

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 73ms
memory: 53996kb

input:

28
200878223506436882933619847964496455022155117513398820563747455993172799881403389571477889821109288771413214004090719097929400406252135763028179112130390003528046316900603668569910008417315162907579003880220844686222148696041857432602133894827753998572080650383305777912447151917272483538029469449...

output:

27

result:

ok 1 number(s): "27"

Test #3:

score: 0
Accepted
time: 77ms
memory: 54308kb

input:

5187
2640352926124261912741724778991366987330659389621881876017670644497364093930668042530271338851702874394631009332660937266680740235862107353443518003194307853104942996827176097428402408674756368623972812842571069642405111849826172879369776309763468485788964245903781380419155348915131587410703749...

output:

6073

result:

ok 1 number(s): "6073"

Test #4:

score: 0
Accepted
time: 72ms
memory: 48948kb

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: 0
Accepted
time: 325ms
memory: 67272kb

input:

200000
944176313232170622314
2590599414036674999101
753315073608896000424
9299685298577430049245
9361800333778142620806
8988699166328904060999
9606920674025578304023
4203331868598952026136
5183047027116137697788
3968714342776915029801
8130984095583566992354
3206443643596048048798
6248561214283254355...

output:

0

result:

ok 1 number(s): "0"

Test #6:

score: 0
Accepted
time: 100ms
memory: 51040kb

input:

200000
9
10
3
5
9
3
3
9
8
5
1
2
7
8
4
6
2
3
3
9
5
5
4
9
7
5
8
2
6
10
9
7
2
2
1
10
10
6
10
7
4
7
9
7
2
2
10
4
5
8
2
2
5
8
9
5
3
9
2
1
7
6
8
8
6
3
8
2
2
9
10
2
9
7
1
9
1
4
5
9
2
7
10
1
8
7
4
8
1
10
6
4
4
9
1
9
7
3
6
5
6
9
5
3
6
6
4
4
6
1
8
6
10
3
10
2
1
4
1
4
8
2
9
1
4
8
10
8
2
2
3
6
4
7
10
10
9
4
7
6...

output:

4388485679

result:

ok 1 number(s): "4388485679"

Test #7:

score: 0
Accepted
time: 319ms
memory: 66452kb

input:

200000
6828421000391895
1989111434563275
5896525738540342
7580233289915833
7220157112714422
6690072177484914
6664449707566084
8245839001391019
3008772159581769
8148007474169818
9400853099859484
6346860654847919
7403109176990407
2581313740335401
1273038733901266
9824983373567665
7206452987542085
7181...

output:

0

result:

ok 1 number(s): "0"

Test #8:

score: 0
Accepted
time: 217ms
memory: 57976kb

input:

200000
163414517
35065810
104946881
686842158
509604537
114869915
194658958
55736013
211143419
526188788
18298540
311113507
727676120
517103071
25044427
38567543
386683792
246028194
750300322
4412101
865997254
674545866
775054146
977862574
699213474
347544102
740489922
632436817
297903184
435135324
...

output:

59

result:

ok 1 number(s): "59"

Test #9:

score: -100
Wrong Answer
time: 61ms
memory: 57368kb

input:

2
2088564186870382794642016448725374479500907752342156600368614861600912666885211013490310624029649329209019866849808883315545780833167257516031795949145341911463438482795792374909577113387320732207052482556858037878075154734524317145645776084240387870219160545328462016106959746495953786767421892196...

output:

0

result:

wrong answer 1st numbers differ - expected: '1', found: '0'