結果

問題 No.1595 The Final Digit
ユーザー nawawannawawan
提出日時 2021-07-09 21:45:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 848 bytes
コンパイル時間 1,693 ms
コンパイル使用メモリ 177,848 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 08:21:32
合計ジャッジ時間 2,563 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:13:14: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   13 |         auto [s, t, u] = v[now];
      |              ^
main.cpp:21:14: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   21 |         auto [a, b, c] = v[K - 3];
      |              ^
main.cpp:35:10: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   35 |     auto [s, t, u] = v[ind + K];
      |          ^

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
    long long p,q,r;
    cin >> p >> q >> r;
    long long K;
    cin >> K;
    vector<tuple<int, int, int>> v;
    v.push_back({r % 10, q % 10, p % 10});
    set<tuple<int, int, int>> se;
    int now = 0;
    while(true){
        auto [s, t, u] = v[now];
        tuple<int, int, int> P = {(s + t + u) % 10 ,s, t};
        v.push_back(P);
        now++;
        if(se.count(P)) break;
        se.insert(P);
    }
    if(K < 3 + (long long)v.size()){
        auto [a, b, c] = v[K - 3];
        cout << a << endl;
        return 0;
    }
    int ind = -1;
    for(int i = 0; i < v.size(); i++){
        if(v[i] == v[now]) {
            ind = i;
            break;
        }
    }
    int sz = now - ind;
    K -= ind + 3;
    K %= sz;
    auto [s, t, u] = v[ind + K];
    cout << s << endl;
}
0