結果

問題 No.658 テトラナッチ数列 Hard
ユーザー ミドリムシミドリムシ
提出日時 2017-12-03 15:12:57
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 812 bytes
コンパイル時間 520 ms
コンパイル使用メモリ 73,088 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-19 01:11:13
合計ジャッジ時間 1,432 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 15 ms
4,376 KB
testcase_05 AC 16 ms
4,380 KB
testcase_06 AC 16 ms
4,376 KB
testcase_07 AC 16 ms
4,376 KB
testcase_08 AC 16 ms
4,384 KB
testcase_09 AC 18 ms
4,380 KB
testcase_10 AC 19 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
    int Q;
    cin >> Q;
    long n[Q];
    for (int i = 0; i < Q; i++){
        cin >> n[i];
    }
    vector<int> tetranatti = {0, 0, 0, 1};
    for (int i = 4; true; i++){
        if (tetranatti[i - 1] == 1 && tetranatti[i - 2] == 0 && tetranatti[i - 3] == 0 && tetranatti[i - 4] == 0 && i != 4){
            tetranatti.pop_back();
            tetranatti.pop_back();
            tetranatti.pop_back();
            tetranatti.pop_back();
            break;
        }else{
            tetranatti.push_back((tetranatti[i - 1] + tetranatti[i - 2] + tetranatti[i - 3] + tetranatti[i - 4]) % 17);
        }
    }
    for (int i = 0; i < Q; i++){
        cout << tetranatti[(n[i] - 1) % tetranatti.size()] << endl;
    }
}
0