結果

問題 No.1595 The Final Digit
ユーザー CJ314CJ314
提出日時 2021-07-09 23:57:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,522 bytes
コンパイル時間 4,521 ms
コンパイル使用メモリ 270,844 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 11:22:09
合計ジャッジ時間 5,462 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
using pll = std::pair<long long, long long>;
#define rep(i, n) for (long long i = 0LL; i < (long long)(n); i++)
#define rep2(i, s, n) for (long long i = (s); i < (long long)(n); i++)
#define repr(i, n) for (long long i = (long long)(n) - 1; i >= 0LL; i--)
#define repr2(i, n, s) for (long long i = (long long)(n) - 1; i >= (long long)(s); i--)
template <typename T> bool chmin(T &a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T> bool chmax(T &a, const T& b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 2e18;

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    ll p, q, r, K;
    cin >> p >> q >> r >> K;

    vector<ll> A{p % 10, q % 10, r % 10};
    map<tuple<ll, ll, ll>, ll> m;
    ll idx = 0, start = -1;
    while (true) {
        if (idx + 3 == K) {
            cout << A.at(idx + 2) << "\n";
            exit(0);
        }
        tuple<ll, ll, ll> t{A.at(idx), A.at(idx + 1), A.at(idx + 2)};
        if (m.count(t)) {
            start = m.at(t);
            break;
        }
        m[t] = idx;
        A.push_back((A.at(idx) + A.at(idx + 1) + A.at(idx + 2)) % 10);
        idx++;
    }
    ll cycle_size = m.size() - start;
    ll u = start + (K - 1 - start) % cycle_size;
    ll ans = A.at(u) % 10;
    cout << ans << "\n";
}
0