QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#596583#9225. Fibonacci Fusionucup-team4975#WA 132ms14660kbC++172.1kb2024-09-28 16:02:562024-09-28 16:02:56

Judging History

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

  • [2024-09-28 16:02:56]
  • 评测
  • 测评结果:WA
  • 用时:132ms
  • 内存:14660kb
  • [2024-09-28 16:02:56]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
#define PII pair<signed,signed>
#define double long double
const int N=200005;
const int P1=998244353;
const int P2=1004535809;
using namespace std;
using matrix = vector<vector<int>>;
int g(int x,int mod) {
	return (x%mod+mod)%mod;
}
matrix matrix_mult(const matrix& A, const matrix& B, int mod) {
    return {
        {
            (A[0][0] * B[0][0] + A[0][1] * B[1][0]) % mod,
            (A[0][0] * B[0][1] + A[0][1] * B[1][1]) % mod
        },
        {
            (A[1][0] * B[0][0] + A[1][1] * B[1][0]) % mod,
            (A[1][0] * B[0][1] + A[1][1] * B[1][1]) % mod
        }
    };
}
matrix matrix_pow(const matrix& mat, int exp, int mod) {
    matrix res = {{1, 0}, {0, 1}};
    matrix base = mat;
    while (exp > 0) {
        if (exp % 2 == 1) {
            res = matrix_mult(res, base, mod);
        }
        base = matrix_mult(base, base, mod);
        exp /= 2;
    }
    return res;
}
int fib(int n, int mod) {
    if (n == 0) return 0;
    if (n == 1) return 1;

    matrix F = {{1, 1}, {1, 0}};
    matrix result_matrix = matrix_pow(F, n - 1, mod);

    return result_matrix[0][0]; 
}
bool compare(const string &a, const string &b) {
    if (a.length() != b.length()) {
        return a.length() < b.length();
    }
    return a < b;
}
double et=(1+sqrt(5))/2;
int calc(const string &a) {
	return (log(sqrt(5)*(a[0]-'0'))+(a.size()-1)*log(10))/log(et);
}
int trans(const string& num, int P) {
    int result = 0;
    for (char digit : num) {
        result = (result * 10 + (digit - '0')) % P;
    }
    return result;
}
int n;
string s[N];
signed main() {
	int ans=0;
	multiset<PII> st;
	cin>>n;
	for(int i=1;i<=n;i++) {
		cin>>s[i];
	}
	sort(s+1,s+n+1,compare);
	for(int i=1;i<=n;i++) {
		int m=calc(s[i]);
		int u1=trans(s[i],P1),u2=trans(s[i],P2);
		for(int j=max(1ll,m-2);j<=m+2;j++) {
			ans+=st.count(PII{g(fib(j,P1)-u1,P1),g(fib(j,P2)-u2,P2)});
		}
		
		st.emplace(trans(s[i],P1),trans(s[i],P2));
	}
	cout<<ans<<endl;
	//for(int i=1;i<=n;i++) cout<<s[i]<<endl;
    return 0;
}

詳細信息

Test #1:

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

input:

6
50
8
8
5
72
354224848179261915070

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: -100
Wrong Answer
time: 132ms
memory: 14660kb

input:

28
200878223506436882933619847964496455022155117513398820563747455993172799881403389571477889821109288771413214004090719097929400406252135763028179112130390003528046316900603668569910008417315162907579003880220844686222148696041857432602133894827753998572080650383305777912447151917272483538029469449...

output:

25

result:

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