QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#77222 | #4610. 小 Y 和恐怖的奴隶主 | alpha1022 | 0 | 1792ms | 9424kb | C++17 | 3.5kb | 2023-02-13 15:06:28 | 2023-02-13 15:06:29 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using L = __int128;
const int mod = 998244353;
int norm(int x) { return x >= mod ? x - mod : x; }
int reduce(int x) { return x < 0 ? x + mod : x; }
int neg(int x) { return x ? mod - x : 0; }
void add(int &x, int y) { if ((x += y - mod) < 0) x += mod; }
void sub(int &x, int y) { if ((x -= y) < 0) x += mod; }
void fam(int &x, int y, int z) { x = (x + (ll)y * z) % mod; }
int mpow(int a, int b) {
int ret = 1;
for (; b; b >>= 1) {
if (b & 1) ret = (ll)ret * a % mod;
a = (ll)a * a % mod;
}
return ret;
}
pair<vector<int>, vector<int>> berlekampMassey(int n, const vector<int> &base) {
vector<int> u(n * 2 + 1), v(n * 2), x, y(1, 1);
u[n * 2] = 1;
for (int i = 0; i < v.size(); ++i) v[i] = base[i];
while (1) {
while (!v.empty() && !v.back()) v.pop_back();
if (v.size() - 1 < n && y.size() - 1 <= n) break;
x.resize(max(x.size(), u.size() - v.size() + y.size()));
int t = neg(mpow(v.back(), mod - 2));
for (int i = u.size() - v.size(); i >= 0; --i) {
int c = (ll)t * u[i + v.size() - 1] % mod;
for (int j = 0; j < y.size(); ++j) fam(x[i + j], c, y[j]);
for (int j = 0; j < v.size(); ++j) fam(u[i + j], c, v[j]);
}
swap(u, v), swap(x, y);
}
int inv = mpow(y[0], mod - 2);
for (int i = 0; i < y.size(); ++i) y[i] = (ll)y[i] * inv % mod;
for (int i = 0; i < v.size(); ++i) v[i] = (ll)v[i] * inv % mod;
return make_pair(v, y);
}
int bostanMori(ll n, vector<int> p, vector<int> q) {
p.resize(q.size() - 1);
vector<int> u(p.size()), v(q.size());
for (; n; n >>= 1) {
for (int i = 0; i < v.size(); ++i) {
L t = 0;
int id = i << 1;
for (int j = 0; j <= id; ++j)
if (j < q.size() && id - j < q.size())
t += (ll)(j & 1 ? mod - q[j] : q[j]) * q[id - j];
v[i] = t % mod;
}
for (int i = 0; i < u.size(); ++i) {
L t = 0;
int id = (i << 1) | (n & 1);
for (int j = 0; j <= id; ++j)
if (j < q.size() && id - j < p.size())
t += (ll)(j & 1 ? mod - q[j] : q[j]) * p[id - j];
u[i] = t % mod;
}
p = u, q = v;
}
return (ll)p[0] * mpow(q[0], mod - 2) % mod;
}
int bostanMori(ll n, pair<vector<int>, vector<int>> f) {
return bostanMori(n, f.first, f.second);
}
const int K = 8;
const int B = 2e3;
int T, m, k;
ll n;
int inv[K + 2];
int f[B + 5][K + 1][K + 1][K + 1];
int main() {
scanf("%d%d%d", &T, &m, &k);
inv[1] = 1;
for (int i = 2; i <= k + 1; ++i) inv[i] = (ll)(mod - mod / i) * inv[mod % i] % mod;
for (int i = 1; i <= B; ++i)
for (int a = 0; a <= k; ++a)
for (int b = 0; a + b <= k; ++b)
for (int c = 0; a + b + c <= k; ++c) {
f[i][a][b][c] = (f[i][a][b][c] + (ll)(f[i - 1][a][b][c] + 1) * inv[a + b + c + 1]) % mod;
if (a) f[i][a][b][c] = (f[i][a][b][c] + (ll)f[i - 1][a - 1][b][c] * a % mod * inv[a + b + c + 1]) % mod;
if (b) f[i][a][b][c] = (f[i][a][b][c] + (ll)f[i - 1][a + 1][b - 1 + (a + b + c < k && m == 2)][c + (a + b + c < k && m == 3)] * b % mod * inv[a + b + c + 1]) % mod;
if (c) f[i][a][b][c] = (f[i][a][b][c] + (ll)f[i - 1][a][b + 1][c - 1 + (a + b + c < k)] * c % mod * inv[a + b + c + 1]) % mod;
}
vector<int> base(B + 1);
for (int i = 0; i <= B; ++i) base[i] = f[i][m == 1][m == 2][m == 3];
auto f = berlekampMassey(base.size() >> 1, base);
printf("%d\n", f.second.size());
for (; T; --T) scanf("%lld", &n), printf("%d\n", bostanMori(n, f));
}
详细
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 9268kb
input:
10 1 1 3 5 10 6 10 4 5 2 1 7
output:
4 873463811 967049221 997269514 982646790 997269514 935854084 967049221 748683266 499122177 990445575
result:
wrong answer 1st numbers differ - expected: '873463811', found: '4'
Test #2:
score: 0
Wrong Answer
time: 13ms
memory: 9244kb
input:
10 2 8 9 7 3 1 8 10 4 6 8 4
output:
19 957797658 957988697 471393168 499122177 751114294 293461261 227146807 120778537 751114294 227146807
result:
wrong answer 1st numbers differ - expected: '957797658', found: '19'
Test #3:
score: 0
Wrong Answer
time: 2ms
memory: 9240kb
input:
10 2 3 738202531831392322 783619408699447923 95448256259589251 844448705450323564 624412958283331450 82254415491953115 161329806857404403 873406552855800221 579441694693039373 362343929997412473
output:
9 728204560 970397627 628767169 940576960 292842745 769165416 359318636 321055107 521151178 572158341
result:
wrong answer 1st numbers differ - expected: '728204560', found: '9'
Test #4:
score: 0
Wrong Answer
time: 1ms
memory: 9344kb
input:
10 2 7 302412104829477627 267175673759183341 180043432686593470 526090092686666014 505721208708278398 506294196055642495 389633992918104929 635697493290952378 757493234187573112 761239842356661668
output:
17 956147808 849708906 858020267 830680308 607733651 859659370 410667202 74957667 412240449 2988204
result:
wrong answer 1st numbers differ - expected: '956147808', found: '17'
Test #5:
score: 0
Wrong Answer
time: 13ms
memory: 9352kb
input:
20 3 5 852899626493760283 754069554675030848 773874428758880017 123375651672149292 556249242341531885 428470484260225591 612955822468784753 144411941571891154 869439856253804050 908146565477516347 814952754132360789 756092742572000841 820420180133712434 992274690451907092 846208580168608503 96150212...
output:
51 442017592 994454054 471018258 880700521 951831327 782278936 550520887 17878310 29620413 775413149 813993612 543356349 800788471 419038715 896629027 986912907 730534588 830045981 693902411 658725837
result:
wrong answer 1st numbers differ - expected: '442017592', found: '51'
Test #6:
score: 0
Wrong Answer
time: 492ms
memory: 9352kb
input:
500 3 6 738291794096542548 764358602831820281 563238804829926575 370603315432808748 100345531802350888 78859647115211243 811761470222990744 81127714898978520 402422318136684465 654308566563468036 169605695188757775 955311887954849077 150737338108335362 918211967525286737 351667577081940049 451234288...
output:
76 405831149 171783879 776079313 103798029 898275377 20932150 975107349 853149926 888583476 582990522 505595168 671098744 8292739 317527083 444671167 313608387 465763722 130368749 301863319 64029391 893498845 647170020 375946791 381167702 445055557 852714764 583144741 587653726 388605317 261031842 9...
result:
wrong answer 1st numbers differ - expected: '405831149', found: '76'
Test #7:
score: 0
Wrong Answer
time: 408ms
memory: 9340kb
input:
200 3 7 672259869393347339 369327731126838699 64061787795877737 501816384000770596 690696325130441433 154127833833484890 576073302548020172 356224027574683716 360014439391885202 900035121039104331 620401957312455398 685627564948275461 257115887698249471 182590752506753132 795335245342655904 29229833...
output:
108 822803116 246007391 101854981 962791981 64436557 662297076 941478132 840251238 812289127 761081894 873173247 438918597 547800259 494535870 319490239 602671449 459646020 499523787 979522183 300512672 686999084 631298438 265075125 543461615 65764751 809426591 171508623 460409761 695067532 49596916...
result:
wrong answer 1st numbers differ - expected: '822803116', found: '108'
Test #8:
score: 0
Time Limit Exceeded
input:
1000 3 7 927431038590684175 532845056241370848 981420276391761817 468489151751236651 660335172832504160 565758532825355787 164153593760812135 279434702460342896 358625155725778969 633338776100569232 211963237957802180 916221369234575530 779873510288248601 289233265840477315 537317800100747277 296733...
output:
108 581533337 854140161 990664899 520403265 166891093 299581858 76208179 551023557 764068860 97699696 990197247 340479754 729738323 167993645 413761832 6811126 967548892 426463088 204296280 942438465 670196053 491275194 355126211 567659383 934348609 497517329 776379621 941483102 768168420 250403018 ...
result:
Test #9:
score: 0
Wrong Answer
time: 368ms
memory: 9372kb
input:
100 3 8 293455384739357531 67612334385116908 709127840857554827 592692648624080073 669323382975105711 481820112205801832 213938967367348923 179085811004224321 25406212354373018 202909893880406081 150981737006062413 943764734403419344 962389709289625138 630945113981699018 159258773119290193 593552184...
output:
147 599797299 452625349 141842480 784318912 848233103 613481707 395997513 657986654 477321383 85573193 480737345 398643793 356946510 308675760 576535865 990122150 471928813 466277158 503920426 587614978 151779847 305622475 623301933 338578086 828288151 710126122 538710757 535209007 696280660 7040164...
result:
wrong answer 1st numbers differ - expected: '599797299', found: '147'
Test #10:
score: 0
Wrong Answer
time: 1792ms
memory: 9424kb
input:
500 3 8 251326191428260710 145522620174033893 610704251244187963 885592345865036062 202160400718267461 99793413045684561 740002575418552853 4684983321229405 138776151283141117 170156142094361225 197199356826770314 660871465396172439 452817036656312156 912499034370116560 811398525499262192 7660511931...
output:
147 551989877 36808433 783659161 491489258 222922313 595265107 459220958 202796464 279377202 309963221 386525430 863771005 252573581 265858948 747475692 12473463 772992309 800249702 635246065 417682455 265785246 739410856 277378490 370780683 867176180 107389794 290732757 269814348 352257509 80245792...
result:
wrong answer 1st numbers differ - expected: '551989877', found: '147'