結果

問題 No.1595 The Final Digit
ユーザー SSRSSSRS
提出日時 2021-07-09 21:29:57
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,410 bytes
コンパイル時間 1,637 ms
コンパイル使用メモリ 174,396 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-14 07:51:34
合計ジャッジ時間 2,556 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,504 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,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:58:11: 警告: ‘c’ may be used uninitialized [-Wmaybe-uninitialized]
   58 |       int r2 = r + c;
      |           ^~
main.cpp:47:9: 備考: ‘c’ はここで定義されています
   47 |     int c;
      |         ^

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const int MOD = 10;
vector<vector<long long>> matmul(vector<vector<long long>> A, vector<vector<long long>> B){
	int N = A.size();
	vector<vector<long long>> ans(N, vector<long long>(N, 0));
	for (int i = 0; i < N; i++){
		for (int j = 0; j < N; j++){
			for (int k = 0; k < N; k++){
				ans[i][k] += A[i][j] * B[j][k];
				ans[i][k] %= MOD;
			}
		}
	}
	return ans;
}
vector<vector<long long>> matexp(vector<vector<long long>> A, long long b){
	int N = A.size();
	vector<vector<long long>> ans(N, vector<long long>(N, 0));
	for (int i = 0; i < N; i++){
		ans[i][i] = 1;
	}
	while (b > 0){
		if (b % 2 == 1){
			ans = matmul(ans, A);
		}
		A = matmul(A, A);
		b /= 2;
	}
	return ans;
}
int main(){
  int p, q, r;
  long long K;
  cin >> p >> q >> r >> K;
  K--;
  vector<int> A(1200);
  A[0] = p % 10;
  A[1] = q % 10;
  A[2] = r % 10;
  for (int i = 3; i < 1200; i++){
    A[i] = (A[i - 1] + A[i - 2] + A[i - 3]) % 10;
  }
  if (K < 1200){
    cout << A[K] << endl;
  } else {
    int c;
    for (int i = 1; i < 1100; i++){
      int x = A[1197] * 100 + A[1198] * 10 + A[1199];
      int y = A[1197 - i] * 100 + A[1198 - i] * 10 + A[1199 - i];
      if (x == y){
        c = i;
        break;
      }
    }
    int r = K % c;
    while (true){
      int r2 = r + c;
      if (r2 >= 1200){
        break;
      }
      r = r2;
    }
    cout << A[r] << endl;
  }
}
0