QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#621890 | #9435. Welcome to NPCAPC | rikka_lyly | WA | 8ms | 3916kb | C++20 | 3.4kb | 2024-10-08 18:00:39 | 2024-10-08 18:00:40 |
Judging History
answer
//code_board
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef double db;
typedef pair<int,int> pa;
typedef vector<int> vec;
typedef string str;
const int bias = 5;
const int MOD = 998244353;
#define endl '\n'
int T;
class Matrix {
public:
int rows, cols;
// vector<vector<ll>> mat;
int mat[49][49];
Matrix(int r, int c) : rows(r), cols(c) {
// mat.resize(r, vector<ll>(c, 0));
memset(mat, 0, sizeof(mat));
}
Matrix operator*(const Matrix& other) const {
Matrix result(rows, other.cols);
for (int i = 0; i < rows; ++i) {
for (int j = 0; j < other.cols; ++j) {
for (int k = 0; k <= i; ++k) {
(result.mat[i][j] += 1ll * mat[i][k] * other.mat[k][j] % MOD) %= MOD;
}
}
}
return result;
}
Matrix operator-(const Matrix& other) const {
Matrix result(rows, other.cols);
for (int i = 0; i < rows; ++i) {
for (int j = 0; j <= i; ++j) {
for (int k = j; k <= i; ++k) {
(result.mat[i][j] += 1ll * mat[i][k] * other.mat[k][j] % MOD) %= MOD;
}
}
}
return result;
}
Matrix pow(ll exp) const {
Matrix result(rows, cols);
Matrix base = *this;
// Initialize result as identity matrix
for (int i = 0; i < rows; ++i) {
result.mat[i][i] = 1;
}
while (exp > 0) {
if (exp & 1) {
result = result * base;
}
base = base * base;
exp >>= 1;
}
return result;
}
void print() const {
for (int i = 0; i < rows; ++i) {
for (int j = 0; j < cols; ++j) {
cout << mat[i][j] << " ";
}
cout << endl;
}
}
}EX(49, 49);
vector<Matrix> EXs;
int num(int a, int b) {
return a * 7 + b;
}
void init() {
for (int a = 0; a <= 6; a++) {
for (int b = 0; b <= 6; b++) {
int k = num(a, b);
if(a){
int t = num(a - 1, b);
EX.mat[k][t] = 1;
}
if(b){
int t = num(a, b - 1);
EX.mat[k][t] = 1;
}
EX.mat[k][k] = 26 + 26 - (a != 6) - (b != 6);
}
}
// EX.print();
for(int i = 0; i < 33; i++){
// EX.print();
EXs.push_back(EX);
EX = EX - EX;
}
}
map<int, int> mans;
void solve() {
int n;
cin >> n;
if(mans.contains(n))
{
cout << n << '\n';
return;
}
Matrix ans(49, 1), adj(49, 49);
ans.mat[0][0] = 1;
int cnt = 0;
for(int i = 0; i < 49; i++){
adj.mat[i][i] = 1;
}
int nn = n;
while(n){
if(n & 1){
adj = adj - EXs[cnt];
}
cnt++;
n >>= 1;
}
ans = adj * ans;
// ans.print();
cout << ans.mat[num(6, 6)][0] << '\n';
mans[nn] = ans.mat[num(6, 6)][0];
}
int main() {
// 示例代码
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
init();
cin >> T;
while(T--) solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 4ms
memory: 3908kb
input:
4 12 6 5839 123456
output:
924 0 966252995 432934749
result:
ok 4 number(s): "924 0 966252995 432934749"
Test #2:
score: 0
Accepted
time: 6ms
memory: 3840kb
input:
3 123456789 987654321 999999999
output:
333574957 124462731 163251704
result:
ok 3 number(s): "333574957 124462731 163251704"
Test #3:
score: 0
Accepted
time: 4ms
memory: 3840kb
input:
10 19425 102461 155567 158836 113140 53389 161281 4594 30575 108615
output:
373186365 206571483 970383134 989350567 625537601 996030441 764136313 478343127 585610797 77642861
result:
ok 10 numbers
Test #4:
score: 0
Accepted
time: 8ms
memory: 3844kb
input:
10 194023 129263 48544 122512 184189 36584 109090 185910 157471 165449
output:
646584725 685247409 562517647 135100440 554171085 18276445 599247609 645458744 157353305 961701460
result:
ok 10 numbers
Test #5:
score: 0
Accepted
time: 7ms
memory: 3836kb
input:
10 62619 102803 103157 53078 141131 131278 107572 72144 3962 2993
output:
336681005 218835081 977425093 939622730 599861248 730434007 143005189 81452469 648743259 392146337
result:
ok 10 numbers
Test #6:
score: 0
Accepted
time: 8ms
memory: 3916kb
input:
10 115339 14918 142121 161511 64217 158940 60253 133675 8663 16414
output:
447424283 701409014 925899837 229615050 384906046 868361271 510779619 719867379 676960448 767190917
result:
ok 10 numbers
Test #7:
score: 0
Accepted
time: 7ms
memory: 3856kb
input:
10 85495 199819 142473 79698 166538 169504 10264 127098 60974 49524
output:
758217665 362989371 849601874 914823277 258052558 895462991 815236067 354182017 319596227 827075400
result:
ok 10 numbers
Test #8:
score: 0
Accepted
time: 7ms
memory: 3856kb
input:
10 1425 152469 89993 198158 35858 99757 121657 13600 1674 146517
output:
696406093 386918828 204106049 632497695 611949542 844728055 614167688 322636556 426859719 892745895
result:
ok 10 numbers
Test #9:
score: 0
Accepted
time: 8ms
memory: 3840kb
input:
10 54362 116337 187366 29763 59353 2441 42427 123694 39351 17442
output:
770174476 485360795 966181928 673166447 778039253 223255284 308023018 467109595 776512421 478342322
result:
ok 10 numbers
Test #10:
score: 0
Accepted
time: 8ms
memory: 3852kb
input:
10 164862 189993 197025 186958 183986 19454 195717 3595 37637 12900
output:
947618397 310127426 515768872 713650103 443160420 174103041 140536245 261888957 199480824 62935695
result:
ok 10 numbers
Test #11:
score: 0
Accepted
time: 8ms
memory: 3772kb
input:
10 28188 195373 19757 86671 172167 174607 177795 177036 12036 112202
output:
503461377 349476278 864992772 433340965 139666723 854367908 243493730 1094272 259503082 826525753
result:
ok 10 numbers
Test #12:
score: 0
Accepted
time: 8ms
memory: 3768kb
input:
10 88207 181591 178531 140277 166887 34746 6840 165413 59380 59478
output:
143757409 281674172 448638880 297367509 478750591 255032414 933878821 32023173 935444021 274623740
result:
ok 10 numbers
Test #13:
score: -100
Wrong Answer
time: 3ms
memory: 3856kb
input:
10 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000
output:
506140892 200000 200000 200000 200000 200000 200000 200000 200000 200000
result:
wrong answer 2nd numbers differ - expected: '506140892', found: '200000'