結果

問題 No.1595 The Final Digit
ユーザー NanashimaNanashima
提出日時 2021-07-09 22:42:01
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 697 bytes
コンパイル時間 1,513 ms
コンパイル使用メモリ 167,204 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 10:00:17
合計ジャッジ時間 2,493 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0; i<(n); i++)
#define INF ((1LL<<62)-(1LL<<31))
#define all(a)  (a).begin(),(a).end()
#define rall(a)  (a).rbegin(),(a).rend()
typedef long long ll;
typedef pair<ll,ll> pl;
typedef tuple<ll,ll,ll> tupl;

int main()
{
    ll p,q,r,k;
    cin >> p >> q >> r >> k;
    p%=10; q%=10; r%=10;
    vector<int> v(100010);
    v[0]=p; v[1]=q; v[2]=r;
    ll ni=0;
    for(int i=3;i<=100000;i++) {
        v[i]=v[i-1]+v[i-2]+v[i-3];
        v[i]%=10;
        if(v[i]==r&&v[i-1]==q&&v[i-2]==p) {
            ni=i;
            break;
        }
    }
    cout << v[k%(ni-2)-1] << endl;
    return 0;
}
0