結果
| 問題 |
No.1595 The Final Digit
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-07-09 23:57:27 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 7 ms / 2,000 ms |
| コード長 | 1,522 bytes |
| コンパイル時間 | 4,959 ms |
| コンパイル使用メモリ | 260,660 KB |
| 最終ジャッジ日時 | 2025-01-22 23:01:04 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
ソースコード
#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";
}