結果

問題 No.1595 The Final Digit
ユーザー nakaken88nakaken88
提出日時 2021-07-09 22:05:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,220 bytes
コンパイル時間 1,623 ms
コンパイル使用メモリ 171,996 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 09:09:04
合計ジャッジ時間 5,366 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 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 #

#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];
  if (K >= loop) {
    K = time_stamp[pos] + ((K - time_stamp[pos]) % loop);
  }
  K += loop - 3;
  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;
}
0