結果
問題 |
No.1595 The Final Digit
|
ユーザー |
|
提出日時 | 2021-07-09 23:18:01 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,213 bytes |
コンパイル時間 | 1,627 ms |
コンパイル使用メモリ | 174,080 KB |
実行使用メモリ | 10,624 KB |
最終ジャッジ日時 | 2024-07-01 18:19:08 |
合計ジャッジ時間 | 5,158 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 3 |
other | AC * 2 TLE * 1 -- * 14 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; #ifdef LOCAL #include "debug.hpp" #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) #endif ll f (ll a, ll b, ll c) { return (a + b + c) % 10; } int main() { ios::sync_with_stdio(false); cin.tie(0); ll p; cin >> p; ll q; cin >> q; ll r; cin >> r; ll K; cin >> K; vector<vector<vector<ll>>> memo(10, vector<vector<ll>>(10, vector<ll>(10, -1))); vector<ll> time_stamp(1000, -1); ll a1 = p % 10, a2 = q % 10, a3 = r % 10; ll pos = a1 * 100 + a2 * 10 + a3, cnt = 0; while (time_stamp[pos] == -1) { time_stamp[pos] = cnt; ll a4 = f(a1, a2, a3); a1 = a2; a2 = a3; a3 = a4; pos = a1 * 100 + a2 * 10 + a3; cnt++; debug(cnt, a4); } debug(pos); ll loop = cnt - time_stamp[pos]; K -= 3; if (K >= loop) { K = time_stamp[pos] + ((K - time_stamp[pos]) % loop); } debug(K); a1 = p % 10, a2 = q % 10, a3 = r % 10; cnt = 1; while (true) { if (cnt == K) { break; } ll a4 = f(a1, a2, a3); a1 = a2; a2 = a3; a3 = a4; cnt++; } ll ans = f(a1, a2, a3); cout << ans << '\n'; return 0; }