QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#649016 | #9225. Fibonacci Fusion | Arghariza | WA | 81ms | 62584kb | C++14 | 2.0kb | 2024-10-17 21:17:25 | 2024-10-17 21:17:26 |
Judging History
answer
#include <bits/stdc++.h>
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define R(i, x, y) for (int i = (x); i >= (y); i--)
#define FIO(FILE) freopen(FILE".in", "r", stdin), freopen(FILE".out", "w", stdout)
using namespace std;
typedef long long ll;
typedef __int128 lll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
bool Mbe;
const ull B = 31;
const int N = 2e5 + 5;
const ll P = 114514191981011453;
const double F = 1.67227593818;
const double G = 4.78497196678;
ll h[N];
int n, l[N], id[N];
string c[N];
vector<ull> b[N];
unordered_map<ll, int> S;
struct M {
ll s[2][2];
M () { memset(s, 0, sizeof(s)); }
M operator * (const M &r) const {
M res;
F (i, 0, 1) F (j, 0, 1) F (k, 0, 1)
(res.s[i][j] += (lll)s[i][k] * r.s[k][j] % P) %= P;
return res;
}
};
ll calc(int k) {
M a, b;
a.s[0][0] = b.s[0][0] = b.s[0][1] = b.s[1][0] = 1;
for (; k; k >>= 1, b = b * b)
if (k & 1) a = a * b;
return a.s[0][0];
}
void solve() {
cin >> n;
F (i, 1, n) {
cin >> c[i], l[i] = c[i].length(), id[i] = i, b[i].resize(l[i] + 1);
F (j, 0, l[i] - 1) {
h[i] = (h[i] * 10 + c[i][j] - '0') % P;
b[i][j + 1] = B * b[i][j] + c[i][j] - '0' + 1;
}
}
sort(id + 1, id + n + 1, [](int &x, int &y) {
if (l[x] != l[y]) return l[x] < l[y];
int L = 1, R = l[x], p = 0;
while (L <= R) {
int M = (L + R) >> 1;
if (b[x][M] == b[y][M]) p = M, L = M + 1;
else R = M - 1;
}
if (p == l[x]) return false;
return c[x][p] < c[y][p];
});
ll res = 0;
F (i, 1, n) {
int k = F + G * l[i];
F (j, max(0, k - 5), k + 5)
res += S[(calc(j) - h[i] + P) % P];
S[h[i]]++;
}
cout << res << '\n';
}
bool Med;
int main() {
// FIO("");
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cerr << (&Mbe - &Med) / 1048576.0 << " MB\n";
int T = 1;
// cin >> T;
while (T--) solve();
cerr << (int)(1e3 * clock() / CLOCKS_PER_SEC) << " ms\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 16088kb
input:
6 50 8 8 5 72 354224848179261915070
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 32ms
memory: 61408kb
input:
28 200878223506436882933619847964496455022155117513398820563747455993172799881403389571477889821109288771413214004090719097929400406252135763028179112130390003528046316900603668569910008417315162907579003880220844686222148696041857432602133894827753998572080650383305777912447151917272483538029469449...
output:
27
result:
ok 1 number(s): "27"
Test #3:
score: -100
Wrong Answer
time: 81ms
memory: 62584kb
input:
5187 2640352926124261912741724778991366987330659389621881876017670644497364093930668042530271338851702874394631009332660937266680740235862107353443518003194307853104942996827176097428402408674756368623972812842571069642405111849826172879369776309763468485788964245903781380419155348915131587410703749...
output:
4313
result:
wrong answer 1st numbers differ - expected: '6073', found: '4313'