QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#77221#4610. 小 Y 和恐怖的奴隶主alpha102290 872ms9360kbC++173.4kb2023-02-13 15:04:002023-02-13 15:04:04

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-13 15:04:04]
  • 评测
  • 测评结果:90
  • 用时:872ms
  • 内存:9360kb
  • [2023-02-13 15:04:00]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

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) {
      v[i] = 0;
      int id = i << 1;
      for (int j = 0; j <= id; ++j)
        if (j < q.size() && id - j < q.size())
          fam(v[i], j & 1 ? neg(q[j]) : q[j], q[id - j]);
    }
    for (int i = 0; i < u.size(); ++i) {
      u[i] = 0;
      int id = (i << 1) | (n & 1);
      for (int j = 0; j <= id; ++j)
        if (j < q.size() && id - j < p.size())
          fam(u[i], j & 1 ? neg(q[j]) : q[j], p[id - j]);
    }
    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);
  for (; T; --T) scanf("%lld", &n), printf("%d\n", bostanMori(n, f));
}

詳細信息

Test #1:

score: 3
Accepted
time: 2ms
memory: 9308kb

input:

10 1 1
3
5
10
6
10
4
5
2
1
7

output:

873463811
967049221
997269514
982646790
997269514
935854084
967049221
748683266
499122177
990445575

result:

ok 10 numbers

Test #2:

score: 8
Accepted
time: 6ms
memory: 9360kb

input:

10 2 8
9
7
3
1
8
10
4
6
8
4

output:

957797658
957988697
471393168
499122177
751114294
293461261
227146807
120778537
751114294
227146807

result:

ok 10 numbers

Test #3:

score: 7
Accepted
time: 4ms
memory: 9348kb

input:

10 2 3
738202531831392322
783619408699447923
95448256259589251
844448705450323564
624412958283331450
82254415491953115
161329806857404403
873406552855800221
579441694693039373
362343929997412473

output:

728204560
970397627
628767169
940576960
292842745
769165416
359318636
321055107
521151178
572158341

result:

ok 10 numbers

Test #4:

score: 12
Accepted
time: 5ms
memory: 9244kb

input:

10 2 7
302412104829477627
267175673759183341
180043432686593470
526090092686666014
505721208708278398
506294196055642495
389633992918104929
635697493290952378
757493234187573112
761239842356661668

output:

956147808
849708906
858020267
830680308
607733651
859659370
410667202
74957667
412240449
2988204

result:

ok 10 numbers

Test #5:

score: 30
Accepted
time: 20ms
memory: 9284kb

input:

20 3 5
852899626493760283
754069554675030848
773874428758880017
123375651672149292
556249242341531885
428470484260225591
612955822468784753
144411941571891154
869439856253804050
908146565477516347
814952754132360789
756092742572000841
820420180133712434
992274690451907092
846208580168608503
96150212...

output:

442017592
994454054
471018258
880700521
951831327
782278936
550520887
17878310
29620413
775413149
813993612
543356349
800788471
419038715
896629027
986912907
730534588
830045981
693902411
658725837

result:

ok 20 numbers

Test #6:

score: 10
Accepted
time: 872ms
memory: 9268kb

input:

500 3 6
738291794096542548
764358602831820281
563238804829926575
370603315432808748
100345531802350888
78859647115211243
811761470222990744
81127714898978520
402422318136684465
654308566563468036
169605695188757775
955311887954849077
150737338108335362
918211967525286737
351667577081940049
451234288...

output:

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
9436...

result:

ok 500 numbers

Test #7:

score: 10
Accepted
time: 736ms
memory: 9312kb

input:

200 3 7
672259869393347339
369327731126838699
64061787795877737
501816384000770596
690696325130441433
154127833833484890
576073302548020172
356224027574683716
360014439391885202
900035121039104331
620401957312455398
685627564948275461
257115887698249471
182590752506753132
795335245342655904
29229833...

output:

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
495969167
81...

result:

ok 200 numbers

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:

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
9658...

result:


Test #9:

score: 10
Accepted
time: 691ms
memory: 9288kb

input:

100 3 8
293455384739357531
67612334385116908
709127840857554827
592692648624080073
669323382975105711
481820112205801832
213938967367348923
179085811004224321
25406212354373018
202909893880406081
150981737006062413
943764734403419344
962389709289625138
630945113981699018
159258773119290193
593552184...

output:

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
704016439
7...

result:

ok 100 numbers

Test #10:

score: 0
Time Limit Exceeded

input:

500 3 8
251326191428260710
145522620174033893
610704251244187963
885592345865036062
202160400718267461
99793413045684561
740002575418552853
4684983321229405
138776151283141117
170156142094361225
197199356826770314
660871465396172439
452817036656312156
912499034370116560
811398525499262192
7660511931...

output:


result: