結果
問題 | No.1595 The Final Digit |
ユーザー |
![]() |
提出日時 | 2021-07-09 22:34:23 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 2,915 bytes |
コンパイル時間 | 2,061 ms |
コンパイル使用メモリ | 196,340 KB |
最終ジャッジ日時 | 2025-01-22 22:17:19 |
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
#include<bits/stdc++.h>using namespace std;using lli = long long;#define rep(i,n) for(int i=0;i<n;i++)template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }template<class T>ostream &operator<<(ostream &os, const vector<T> &x){os << "{";for(size_t i = 0; i < x.size(); i++){if(i < x.size()-1) os << x[i] << ", ";else os << x[i];}os << "}";return os;}template< int mod >struct ModInt {int x;ModInt() : x(0) {}ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}ModInt &operator+=(const ModInt &p) {if((x += p.x) >= mod) x -= mod;return *this;}ModInt &operator-=(const ModInt &p) {if((x += mod - p.x) >= mod) x -= mod;return *this;}ModInt &operator*=(const ModInt &p) {x = (int) (1LL * x * p.x % mod);return *this;}ModInt &operator/=(const ModInt &p) {*this *= p.inverse();return *this;}ModInt operator-() const { return ModInt(-x); }ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }bool operator==(const ModInt &p) const { return x == p.x; }bool operator!=(const ModInt &p) const { return x != p.x; }ModInt inverse() const {int a = x, b = mod, u = 1, v = 0, t;while(b > 0) {t = a / b;swap(a -= t * b, b);swap(u -= t * v, v);}return ModInt(u);}ModInt pow(int64_t n) const {ModInt ret(1), mul(x);while(n > 0) {if(n & 1) ret *= mul;mul *= mul;n >>= 1;}return ret;}friend ostream &operator<<(ostream &os, const ModInt &p) {return os << p.x;}friend istream &operator>>(istream &is, ModInt &a) {int64_t t;is >> t;a = ModInt< mod >(t);return (is);}static int get_mod() { return mod; }};const int mod = 10;using modint = ModInt< mod >;int main(void){lli p, q, r, k;cin >> p >> q >> r >> k;int m = 20;vector<modint> A(2021);A[0] = p;A[1] = q;A[2] = r;k = k-3;int f[10][10][10];int L = -1, R = -1;rep(i, 10) rep(j, 10) rep(t, 10) f[i][j][t] = -1;for(int i = 3; i < 1002; i++){int s, t, u;s = A[i-1].x;t = A[i-2].x;u = A[i-3].x;if(f[s][t][u] > 0){L = f[s][t][u];R = i;break;}A[i] = A[i-1]+A[i-2]+A[i-3];f[s][t][u] = i;}int to = 3+R+(k-R)%(R-L);for(int i = R; i < to; i++){A[i] = A[i] = A[i-1]+A[i-2]+A[i-3];}cout << A[to-1] << endl;return 0;}