QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#673521#9225. Fibonacci Fusionucup-team191#TL 268ms144020kbC++231.7kb2024-10-24 23:17:102024-10-24 23:17:13

Judging History

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

  • [2024-10-24 23:17:13]
  • 评测
  • 测评结果:TL
  • 用时:268ms
  • 内存:144020kb
  • [2024-10-24 23:17:10]
  • 提交

answer

#include <cstdio>
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <array>

#define PB push_back

using namespace std;

const int N = 1e7 + 500;

int MOD[3] = {(int)1e9 + 7, (int)1e9 + 9, 998244353};

int F[3][N];

void precompute() {
	for(int j = 0;j < 3;j++) {
		F[j][0] = 0;
		F[j][1] = 1;
		for(int i = 2;i < N;i++) {
			F[j][i] = F[j][i - 1] + F[j][i - 2];
			if(F[j][i] >= MOD[j]) F[j][i] -= MOD[j];
		}
	}
}

int n;

bool cmp(const string &A, const string &B) {
	if(A.size() != B.size()) return A.size() < B.size();
	return A < B;
}

int ja[3];

void calc(const string &s) {
	ja[0] = 0, ja[1] = 0, ja[2] = 0;
	for(const char &c : s) {
		for(int j = 0;j < 3;j++) {
			ja[j] = (10LL * ja[j] + (c - '0')) % MOD[j];
		}
	}
}

map < array<int, 3>, int > cnt; 



inline int sub(int A, int B, int j) {
	if(A - B >= 0) return A - B;
	return A - B + MOD[j];
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	precompute();
	cin >> n;
	vector < string > svi;
	for(int i = 0;i < n;i++) {
		string s; cin >> s;
		svi.PB(s);
	}
	sort(svi.begin(), svi.end(), cmp);
	long long ans = 0;
	for(const string &s : svi) {
		calc(s);
		long double dulj = (long double)s.size();
		dulj *= 4.78497196678;
		int lo = max(0, (int)(dulj - 30));
		int hi = (int)(dulj + 30);
		array<int,3> tmp;
		for(int j = lo;j <= hi;j++) {
			tmp[0] = sub(F[0][j], ja[0], 0);
			tmp[1] = sub(F[1][j], ja[1], 1);
			tmp[2] = sub(F[2][j], ja[2], 2);
			ans += cnt[tmp];
		}
		tmp[0] = ja[0];
		tmp[1] = ja[1];
		tmp[2] = ja[2];
		cnt[tmp]++;
	}
	cout << ans << endl;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 48ms
memory: 121044kb

input:

6
50
8
8
5
72
354224848179261915070

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 119ms
memory: 125884kb

input:

28
200878223506436882933619847964496455022155117513398820563747455993172799881403389571477889821109288771413214004090719097929400406252135763028179112130390003528046316900603668569910008417315162907579003880220844686222148696041857432602133894827753998572080650383305777912447151917272483538029469449...

output:

27

result:

ok 1 number(s): "27"

Test #3:

score: 0
Accepted
time: 268ms
memory: 144020kb

input:

5187
2640352926124261912741724778991366987330659389621881876017670644497364093930668042530271338851702874394631009332660937266680740235862107353443518003194307853104942996827176097428402408674756368623972812842571069642405111849826172879369776309763468485788964245903781380419155348915131587410703749...

output:

6073

result:

ok 1 number(s): "6073"

Test #4:

score: 0
Accepted
time: 162ms
memory: 129904kb

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: