結果

問題 No.1595 The Final Digit
ユーザー kuc_jacksonkuc_jackson
提出日時 2021-07-10 10:59:08
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,386 bytes
コンパイル時間 2,177 ms
コンパイル使用メモリ 206,384 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 18:48:37
合計ジャッジ時間 3,131 ms
ジャッジサーバーID
(参考情報)
judge14 / 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 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 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,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:49:13: 警告: ‘ans’ may be used uninitialized [-Wmaybe-uninitialized]
   49 |     cout << ans << endl;
      |             ^~~
main.cpp:38:9: 備考: ‘ans’ はここで定義されています
   38 |     int ans;
      |         ^~~

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

vector<vector<vector<int>>> cyc(10, vector<vector<int>>(10, vector<int>(10)));

void init_cyc(){
    for(int i = 0; i < 10; i++){
        for(int j = 0; j < 10; j++){
            for(int k = 0; k < 10; k++){
                cyc[i][j][k] = (i + j + k) % 10;
            }
        }
    }
}

int main(){
    ll p, q, r, K; cin >> p >> q >> r >> K;
    p %= 10LL; q %= 10LL; r %= 10LL; K -= 4LL;
    init_cyc();
    vector<vector<vector<int>>> time_stamp(10, vector<vector<int>>(10, vector<int>(10, -1)));
    time_stamp[p][q][r] = 0;
    int temp;
    temp = p; p = q; q = r; r = cyc[temp][p][q];
    while(time_stamp[p][q][r] == -1){
        time_stamp[p][q][r] = time_stamp[temp][p][q] + 1;
        temp = p; p = q; q = r; r = cyc[temp][p][q];
    }
    ll dist = time_stamp[p][q][r], cyc_len = time_stamp[temp][p][q] - time_stamp[p][q][r] + 1;
    if(K > dist){
        K -= dist;
        K %= cyc_len;
        K += dist;
    }
    int ans;
    for(int i = 0; i < 10; i++){
        for(int j = 0; j < 10; j++){
            for(int k= 0; k < 10; k++){
                if(K == time_stamp[i][j][k]){
                    ans = cyc[i][j][k];
                    break;
                }
            }
        }
    }
    cout << ans << endl;
}
0