結果

問題 No.1595 The Final Digit
ユーザー ytft
提出日時 2021-12-30 12:51:19
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 497 bytes
コンパイル時間 1,687 ms
コンパイル使用メモリ 167,648 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-06 00:50:45
合計ジャッジ時間 2,429 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main(){
    long long p,q,r,i,next,mod;
    long long K;
    cin>>p>>q>>r>>K;
    vector<long long> memo(1000,0);
    i=(p%10)*100+(q%10)*10+(r%10);
    memo[i]=1;
    while(memo[i]!=K){
       	next=(i*10)%1000+(i/100+i/10+i)%10;
      	if(memo[next]){
          	mod=memo[i]+1-memo[next];
          	memo[next]+=mod*((K-memo[next])/mod);
        }else{
          	memo[next]=memo[i]+1;
        }
      	i=next;
    }
    cout<<(i/100)<<endl;
}
0