結果

問題 No.1595 The Final Digit
ユーザー bayashikobayashiko
提出日時 2021-07-09 21:35:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 3,082 bytes
コンパイル時間 2,306 ms
コンパイル使用メモリ 211,352 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 07:56:35
合計ジャッジ時間 2,925 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops")
using namespace std;
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define flc(x) __builtin_popcountll(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define vec vector<lint>
#define nep(x) next_permutation(all(x))
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=3e5+5;
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;}
//vector<int> bucket[MAX_N/1000];
constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
/*#include<atcoder/all>
using namespace atcoder;
typedef __int128_t llint;*/

struct doubling{
    vector<vector<lint>> to,sum;
    doubling(vector<lint> in,int log){
        to.resize(log);
        rep(i,log) to[i].resize(in.size());
        rep(i,in.size()) to[0][i]=in[i];
        for(int i=1;i<log;i++) rep(j,in.size()) to[i][j]=to[i-1][to[i-1][j]];
        sum.resize(log);
        rep(i,log) sum[i].resize(in.size());
        rep(i,in.size()) sum[0][i]=i;
        for(int i=1;i<log;i++) rep(j,in.size()) sum[i][j]=sum[i-1][j]+sum[i-1][to[i-1][j]];
    }
    doubling(vector<lint> in,vector<lint> in2, int log){//dsumでin2の値を使うようにする
        to.resize(log);
        rep(i,log) to[i].resize(in.size());
        rep(i,in.size()) to[0][i]=in[i];
        for(int i=1;i<log;i++) rep(j,in.size()) to[i][j]=to[i-1][to[i-1][j]];
        sum.resize(log);
        rep(i,log) sum[i].resize(in.size());
        rep(i,in.size()) sum[0][i]=in2[i];
        for(int i=1;i<log;i++) rep(j,in.size()) sum[i][j]=sum[i-1][j]+sum[i-1][to[i-1][j]];
    }
    lint dest(lint now,lint k){//nowのk個先
        rep(i,to.size()){
            if(k&(1LL<<i)) now=to[i][now];
        }
        return now;
    }
    lint dsum(lint now,lint k){//Σ[i=0..k-1]
        lint res=0;
        rep(i,to.size()){
            if(k&(1LL<<i)) res+=sum[i][now],now=to[i][now];
        }
        return res;
    }
};


int main(void){
    lint p,q,r,K;
    cin >> p >> q >> r >> K;
    p%=10,q%=10,r%=10;
    vector<lint> nxt(1000);
    rep(i,1000){
        int s[3];
        int now=i;
        rep(j,3){
            s[j]=now%10;
            now/=10;
        }
        reverse(s,s+3);
        int nx=accumulate(s,s+3,0)%10;
        nxt[i]=s[1]*100+s[2]*10+nx;
    }
    doubling db(nxt,62);
    int bg=p*100+q*10+r;
    cout << db.dest(bg,K-3)%10 << endl;
}
0