結果
問題 |
No.3226 2×2行列累乗
|
ユーザー |
![]() |
提出日時 | 2025-08-25 15:25:50 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 922 bytes |
コンパイル時間 | 775 ms |
コンパイル使用メモリ | 79,104 KB |
実行使用メモリ | 7,720 KB |
最終ジャッジ日時 | 2025-08-25 15:25:55 |
合計ジャッジ時間 | 4,728 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
other | WA * 1 TLE * 1 -- * 25 |
ソースコード
#include<stdio.h> #include<iostream> int main(void) { int A,B,C,D,S,T,N,K,tS,n; int *vecS,*vecT; std::cin >> A >> B >> C >> D >> S >> T >> N >> K; if(N=0) { std::cout << "1 1\n"; return 0; } vecS = new int[K]; vecT = new int[K]; vecS[0] = (S%K+K)%K; vecT[0] = (T%K+K)%K; int index = 0; int cycle_len,cycle_start; bool cyclefound = false; do { vecS[index+1] = ((A*vecS[index]+B*vecT[index])%K+K)%K; vecT[index+1] = ((C*vecS[index]+D*vecT[index])%K+K)%K; //std::cout << vecS[index+1] << " " << vecT[index+1] << std::endl; index++; for(int i=index-1; i>=0; i--) { if((vecS[index] == vecS[i]) && (vecT[index] == vecT[i])) { cycle_start = i; cycle_len = index - i + 1; cyclefound = true; break; } } }while(!cyclefound); n = (N-cycle_start)%cycle_len + cycle_start; std::cout << vecS[n] << " " << vecT[n] << "\n"; delete[] vecS; delete[] vecT; return 0; }