結果

問題 No.1569 Nixoracci's Number
ユーザー SSRSSSRS
提出日時 2021-06-27 13:07:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 485 ms / 2,000 ms
コード長 1,296 bytes
コンパイル時間 1,589 ms
コンパイル使用メモリ 173,996 KB
実行使用メモリ 4,484 KB
最終ジャッジ日時 2023-09-09 20:51:59
合計ジャッジ時間 5,669 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 347 ms
4,380 KB
testcase_05 AC 20 ms
4,376 KB
testcase_06 AC 485 ms
4,484 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 43 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 20 ms
4,380 KB
testcase_11 AC 73 ms
4,380 KB
testcase_12 AC 179 ms
4,376 KB
testcase_13 AC 243 ms
4,376 KB
testcase_14 AC 31 ms
4,380 KB
testcase_15 AC 336 ms
4,380 KB
testcase_16 AC 52 ms
4,376 KB
testcase_17 AC 25 ms
4,380 KB
testcase_18 AC 78 ms
4,380 KB
testcase_19 AC 22 ms
4,380 KB
testcase_20 AC 434 ms
4,376 KB
testcase_21 AC 201 ms
4,380 KB
testcase_22 AC 46 ms
4,376 KB
testcase_23 AC 454 ms
4,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> matrix_multiplication(vector<vector<int>> A, vector<vector<int>> B){
  int N = A.size();
  vector<vector<int>> ans(N, vector<int>(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];
      }
    }
  }
  return ans;
}
vector<vector<int>> matrix_exponentiation(vector<vector<int>> A, long long n){
  int N = A.size();
  vector<vector<int>> ans(N, vector<int>(N, 0));
  for (int i = 0; i < N; i++){
    ans[i][i] = 1;
  }
  while (n > 0){
    if (n % 2 == 1){
      ans = matrix_multiplication(ans, A);
    }
    A = matrix_multiplication(A, A);
    n /= 2;
  }
  return ans;
}
int main(){
  int N;
  long long K;
  cin >> N >> K;
  K--;
  vector<long long> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  if (K < N){
    cout << A[K] << endl;
  } else {
    vector<vector<int>> B(N, vector<int>(N, 0));
    for (int i = 0; i < N; i++){
      B[i][0] = 1;
    }
    for (int i = 0; i < N - 1; i++){
      B[i][i + 1] = 1;
    }
    B = matrix_exponentiation(B, K - N + 1);
    long long ans = 0;
    for (int i = 0; i < N; i++){
      if (B[i][0] == 1){
        ans ^= A[N - 1 - i];
      }
    }
    cout << ans << endl;
  }
}
0