QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#114784 | #5322. Revenge of Fibonacci | PetroTarnavskyi# | ML | 0ms | 0kb | C++17 | 1.5kb | 2023-06-23 16:23:04 | 2023-06-23 16:23:06 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define MP make_pair
#define PB push_back
#define F first
#define S second
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
struct Long {
string s;
Long() {}
Long(const string& _s): s(_s) {}
Long operator+(const Long& n) {
const string& t = n.s;
string res;
int c = 0;
FOR(i, 0, max(SZ(s), SZ(t))) {
int d1 = i >= SZ(s) ? 0 : s[SZ(s) - 1 - i] - '0', d2 = i >= SZ(t) ? 0 : t[SZ(t) - 1 - i] - '0';
int cur = d1 + d2 + c;
res += char(cur % 10 + '0');
c = cur >= 10;
}
if (c) {
res += '1';
}
reverse(ALL(res));
return res;
}
};
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
Long f0("1"), f1("1");
unordered_map<string, int> ans;
ans.reserve(4000000);
ans["1"] = 0;
FOR(i, 1, 100001) {
swap(f0, f1);
f1 = f0 + f1;
if (SZ(f1.s) > 74) {
f0.s.pop_back();
f1.s.pop_back();
}
string pref;
FOR(j, 0, min(40, SZ(f1.s))) {
pref += f1.s[j];
if (!ans.count(pref)) {
ans[pref] = i + 1;
}
}
}
int tc;
cin >> tc;
FOR(t, 1, tc + 1) {
string s;
cin >> s;
cout << "Case #" << t << ": ";
if (!ans.count(s)) {
cout << "-1\n";
}
else {
cout << ans[s] << "\n";
}
}
cerr << (double)clock() / CLOCKS_PER_SEC << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Memory Limit Exceeded
input:
50000 792362991986528154794111338308492 439673290826407208 363566069103643927 617208990855375359 10923013836786367 12768656204 5278138430 3162806369255331536189 110441 228497727352029613251 7924171 56188963 71025506137142741639694 112631974340 1223041785964352220301 6132969058016461907372737549 9945...