結果

問題 No.1595 The Final Digit
ユーザー yunix91201367yunix91201367
提出日時 2021-07-09 21:46:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,217 bytes
コンパイル時間 1,731 ms
コンパイル使用メモリ 177,324 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 08:24:48
合計ジャッジ時間 2,648 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 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,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
// #include <atcoder/maxflow>
#define int long long
using namespace std;
// using namespace atcoder;
using vec_int = vector<int>;
using T = tuple<int,int,int>;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

void cout_line(vector<int> &a){
    for(int i=0;i<a.size();i++){
        if(i<a.size()-1){
            cout<<a.at(i)<<" ";
        }else{
            cout<<a.at(i)<<endl;
        }
    }
}


signed main()
{
    int p, q, r, K; cin>>p>>q>>r>>K;
    vec_int vec(10000);
    vec.at(0) = p%10;
    vec.at(1) = q%10;
    vec.at(2) = r%10;
    K--;

    for(int i=3;i<10000;i++){
        vec.at(i) = (vec.at(i-1)+vec.at(i-2)+vec.at(i-3))%10;
        if(i==K){
            cout<<vec.at(i)<<endl;
            return 0;
        }
    }
    map<T, int> pos_map;
    for(int i=0;i<9998;i++){
        T temp = make_tuple(vec.at(i), vec.at(i+1), vec.at(i+2));
        if(!pos_map.count(temp)){
            pos_map[temp] = i;
        }else{
            int start = pos_map[temp];
            int loop_len = i-start;
            K-=start;
            K%=loop_len;
            cout<<vec.at(start+K)<<endl;
            return 0;
        }

    }













    return 0;
}
0