結果
| 問題 |
No.3310 mod998
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-10-24 23:12:47 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 3,704 bytes |
| コンパイル時間 | 2,952 ms |
| コンパイル使用メモリ | 286,420 KB |
| 実行使用メモリ | 15,940 KB |
| 最終ジャッジ日時 | 2025-10-24 23:13:02 |
| 合計ジャッジ時間 | 14,314 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 20 TLE * 1 -- * 12 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, t) for (ll i = (ll)s; i < (ll)(t); i++)
#define rrep(i, s, t) for (ll i = (ll)(t) - 1; i >= (ll)(s); i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define TT template <typename T>
template <class T1, class T2>
bool chmin(T1& x, T2 y) { return x > y ? (x = y, true) : false; }
template <class T1, class T2>
bool chmax(T1& x, T2 y) { return x < y ? (x = y, true) : false; }
struct io_setup {
io_setup() {
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
cout << fixed << setprecision(15);
srand(time(NULL));
}
} io_setup;
const ll MOD = 998;
template <class T>
struct Matrix {
vector<vector<T>> A;
Matrix(int n, int m) : A(n, vector<T>(m, 0)) {}
Matrix(int n) : A(n, vector<T>(n, 0)) {}
int height() const {
return (A.size());
}
int width() const {
return (A[0].size());
}
const vector<T>& operator[](int k) const {
return (A[k]);
}
vector<T>& operator[](int k) {
return (A[k]);
}
static Matrix I(int n) {
Matrix mat(n);
for (int i = 0; i < n; i++) mat[i][i] = 1;
return mat;
}
Matrix& operator+=(const Matrix& B) {
int n = height(), m = width();
assert(n == B.height() && m == B.width());
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
(*this)[i][j] += B[i][j];
}
}
return (*this);
}
Matrix& operator-=(const Matrix& B) {
int n = height(), m = width();
assert(n == B.height() && m == B.width());
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
(*this)[i][j] -= B[i][j];
}
}
return (*this);
}
Matrix& operator*=(const Matrix& B) {
int n = height(), m = B.width(), p = width();
assert(p == B.height());
vector<vector<T>> C(n, vector<T>(m, 0));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
for (int k = 0; k < p; k++) {
C[i][j] += (*this)[i][k] * B[k][j];
}
}
}
A.swap(C);
return (*this);
}
Matrix& operator^=(long long k) {
int n = height();
assert(n == width());
Matrix B = Matrix::I(n);
while (k > 0) {
if (k & 1) B *= *this;
*this *= *this;
k >>= 1LL;
}
A.swap(B.A);
return (*this);
}
Matrix operator+(const Matrix& B) const {
return (Matrix(*this) += B);
}
Matrix operator-(const Matrix& B) const {
return (Matrix(*this) -= B);
}
Matrix operator*(const Matrix& B) const {
return (Matrix(*this) *= B);
}
Matrix operator^(const long long k) const {
return (Matrix(*this) ^= k);
}
};
#include <atcoder/modint>
using mint = atcoder::modint;
void solve() {
ll N, M;
cin >> N >> M;
while (M--) {
string K;
cin >> K;
Matrix<mint> mt(2);
mt[0][0] = N, mt[0][1] = 1, mt[1][0] = 0, mt[1][1] = 1;
Matrix<mint> I(2);
rep(i, 0, 2) I[i][i] = 1;
rrep(i, 0, (int)K.size()) {
rep(t, 0, K[i] - '0') I *= mt;
Matrix<mint> nxt(2);
rep(t, 0, 2) nxt[t][t] = 1;
rep(t, 0, 10) nxt *= mt;
swap(mt, nxt);
}
mint ans = I[0][0] + I[0][1];
cout << ans.val() << "\n";
}
}
int main() {
atcoder::modint::set_mod(998);
int T;
cin >> T;
while (T--) {
solve();
}
}