結果

問題 No.1595 The Final Digit
ユーザー Joe75792433Joe75792433
提出日時 2021-07-09 21:44:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,386 bytes
コンパイル時間 4,470 ms
コンパイル使用メモリ 262,584 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 08:18:43
合計ジャッジ時間 7,715 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#ifdef _DEBUG
    #include <atcoder/all.h>
    #define debug(x) std::cout << #x << ": " << x << std::endl
#else
    #include <bits/stdc++.h>
    #include <atcoder/all>
    //#pragma GCC target("arch=skylake-avx512")
    #pragma GCC optimize("O3")
    #pragma GCC optimize("unroll-loops")
    #define debug(x)
#endif
using namespace std;
using namespace atcoder;
using ll = long long;
#define rep(...) _overloadrep(__VA_ARGS__, _rep4, _rep3, _rep2)(__VA_ARGS__)
#define _overloadrep(_1, _2, _3, _4, _repn, ...) _repn
#define _rep2(i, n) _rep4(i, 0, n, 1)
#define _rep3(i, a, b) _rep4(i, a, b, 1)
#define _rep4(i, a, b, s) for (auto i = (a); i < (b); i += (s))
#define repr(i, a, b) for (auto i = (b)-1; i >= (a); --i)
#define all(x) (x).begin(), (x).end()
#define siz(x) int((x).size())
template<class T1, class T2> inline bool chmax(T1 &a, const T2 &b) { if (a < b) { a = b; return true; } return false; }
template<class T1, class T2> inline bool chmin(T1 &a, const T2 &b) { if (a > b) { a = b; return true; } return false; }
constexpr char enl = '\n';
constexpr int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr long double eps = 1e-10;
constexpr int INF = 1010000000;  // 1e9
constexpr ll llINF = 3010000000000000000LL;  // 3e18
constexpr ll MOD = 1000000007LL;
//constexpr ll MOD = 998244353LL;
using mint = static_modint<MOD>;

void Main([[maybe_unused]] int testcase_i) {
    int p, q, r, k; cin >> p >> q >> r >> k;
    p %= 10;
    q %= 10;
    r %= 10;
    k -= 3;
    vector<vector<vector<int>>> dist(10, vector<vector<int>>(10, vector<int>(10, -1)));
    dist[p][q][r] = 0;
    int t1 = p, t2 = q, t3 = r;
    while (true) {
        int n = (t1 + t2 + t3) % 10;
        if (dist[t2][t3][n] != -1) {
            k %= dist[t1][t2][t3] - dist[t2][t3][n] + 1;
            break;
        }
        dist[t2][t3][n] = dist[t1][t2][t3] + 1;
        --k;
        t1 = t2; t2 = t3; t3 = n;
        if (k == 0) {
            cout << t3 << enl;
            return;
        }
    }
    while (true) {
        int n = (t1 + t2 + t3) % 10;
        --k;
        t1 = t2; t2 = t3; t3 = n;
        if (k == 0) {
            cout << t3 << enl;
            return;
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    int t = 1;
    //cin >> t;
    rep(i, t) Main(i);
}
0