QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#114793#5322. Revenge of FibonacciPetroTarnavskyi#AC ✓218ms10856kbC++171.6kb2023-06-23 16:35:492023-06-23 16:35:51

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-23 16:35:51]
  • 评测
  • 测评结果:AC
  • 用时:218ms
  • 内存:10856kb
  • [2023-06-23 16:35:49]
  • 提交

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, vector<int>> queries;
	int tc;
	cin >> tc;
	FOR(t, 0, tc) {
		string s;
		cin >> s;
		queries[s].push_back(t);
	}
	vector<int> ans(tc, -1);
	FOR(i, 1, 100000) {
		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(f0.s))) {
			pref += f0.s[j];
			if (queries.count(pref)) {
				for (int idx : queries[pref]) {
					ans[idx] = i;
				}
				queries.erase(pref);
			}
		}
	}
	FOR(t, 0, tc) {
		cout << "Case #" << t + 1 << ": " << (ans[t] == 1 ? 0 : ans[t]) << "\n";
	}
	cerr << (double)clock() / CLOCKS_PER_SEC << endl;
	return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 218ms
memory: 10856kb

input:

50000
792362991986528154794111338308492
439673290826407208
363566069103643927
617208990855375359
10923013836786367
12768656204
5278138430
3162806369255331536189
110441
228497727352029613251
7924171
56188963
71025506137142741639694
112631974340
1223041785964352220301
6132969058016461907372737549
9945...

output:

Case #1: -1
Case #2: -1
Case #3: 46030
Case #4: 37466
Case #5: 36826
Case #6: 96471
Case #7: -1
Case #8: 99875
Case #9: 82556
Case #10: 19549
Case #11: -1
Case #12: -1
Case #13: -1
Case #14: 86963
Case #15: 99117
Case #16: -1
Case #17: -1
Case #18: 46650
Case #19: -1
Case #20: 27342
Case #21: -1
Cas...

result:

ok 50000 lines