結果
| 問題 | No.658 テトラナッチ数列 Hard |
| コンテスト | |
| ユーザー |
kichirb3
|
| 提出日時 | 2018-03-06 22:23:39 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,824 bytes |
| 記録 | |
| コンパイル時間 | 1,277 ms |
| コンパイル使用メモリ | 110,568 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-21 22:11:53 |
| 合計ジャッジ時間 | 1,750 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 6 WA * 2 |
ソースコード
// No.658 テトラナッチ数列 Hard
// https://yukicoder.me/problems/no/658
//
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <unordered_map>
#include <iomanip>
#include <sstream>
#include <numeric>
using namespace std;
pair<vector<int>, int> solve(int limit);
int main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
unsigned int Q;
cin >> Q;
vector<long long> queries(Q);
for (auto i = 0; i < Q; ++i)
cin >> queries[i];
pair<vector<int>, int>res = solve(*max_element(queries.begin(), queries.end()));
vector<int> tetra = res.first;
int loop_start = res.second;
vector<int> tetra_mod = tetra;
for (auto i = 0; i < loop_start; ++i)
tetra_mod.erase(tetra_mod.begin());
int orikaeshi = tetra.size();
int cycle = orikaeshi - loop_start;
for (auto q: queries) {
if (q >= orikaeshi)
cout << tetra_mod[(q-loop_start)%cycle] << endl;
else
cout << tetra[q] << endl;
}
}
pair<vector<int>, int> solve(int limit) {
vector<int> res {-1, 0, 0, 0, 1};
unordered_map<string, int> loop_check;
int loop_start = -1;
for (auto i = 5; i <= limit; ++i ) {
stringstream ss;
ss << setw(2) << setfill('0') << res[i-4];
ss << setw(2) << setfill('0') << res[i-3];
ss << setw(2) << setfill('0') << res[i-2];
ss << setw(2) << setfill('0') << res[i-1];
// cout << ss.str() << endl;
if (loop_check.find(ss.str()) != loop_check.end()) {
loop_start = loop_check[ss.str()];
break;
}
loop_check[ss.str()] = i;
int tmp = accumulate(res.end()-4, res.end(), 0);
res.push_back(tmp % 17);
}
return make_pair(res, loop_start);
}
kichirb3