QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#673496 | #9225. Fibonacci Fusion | ucup-team191# | WA | 105ms | 125916kb | C++23 | 1.7kb | 2024-10-24 23:00:53 | 2024-10-24 23:00:54 |
Judging History
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.78518086;
int lo = max(0, (int)(dulj - 5));
int hi = (int)(dulj + 6);
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: 81ms
memory: 120812kb
input:
6 50 8 8 5 72 354224848179261915070
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: -100
Wrong Answer
time: 105ms
memory: 125916kb
input:
28 200878223506436882933619847964496455022155117513398820563747455993172799881403389571477889821109288771413214004090719097929400406252135763028179112130390003528046316900603668569910008417315162907579003880220844686222148696041857432602133894827753998572080650383305777912447151917272483538029469449...
output:
0
result:
wrong answer 1st numbers differ - expected: '27', found: '0'