QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#317101 | #7307. Matrix Recurrence | ckiseki# | AC ✓ | 1551ms | 210432kb | C++20 | 3.0kb | 2024-01-28 15:13:31 | 2024-01-28 15:13:31 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define all(x) begin(x), end(x)
#ifdef CKISEKI
#define safe cerr << __PRETTY_FUNCTION__ << " line " << __LINE__ << " safe\n"
#define debug(a...) debug_(#a, a)
#define orange(a...) orange_(#a, a)
#include <experimental/iterator>
void debug_(auto s, auto ...a) {
cerr << "\e[1;32m(" << s << ") = (";
int f = 0;
(..., (cerr << (f++ ? ", " : "") << a));
cerr << ")\e[0m\n";
}
void orange_(auto s, auto L, auto R) {
cerr << "\e[1;33m[ " << s << " ] = [ ";
using namespace experimental;
copy(L, R, make_ostream_joiner(cerr, ", "));
cerr << " ]\e[0m\n";
}
#else
#define safe ((void)0)
#define debug(...) safe
#define orange(...) safe
#endif
using lld = int64_t;
int mod;
int add(int a, int b) {
assert(0 <= a and a < mod);
assert(0 <= b and b < mod);
return a + b >= mod ? a + b - mod : a + b;
}
int mul(lld a, lld b) {
assert(0 <= a and a < mod);
assert(0 <= b and b < mod);
return static_cast<int>(a * b % mod);
}
using Mat = array<array<int, 5>, 5>;
Mat mul(const Mat &a, const Mat &b) {
Mat c = {};
for (int i = 0; i < 5; i++)
for (int k = 0; k < 5; k++)
for (int j = 0; j < 5; j++) {
c[i][j] = add(c[i][j], mul(a[i][k], b[k][j]));
}
return c;
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
Mat I = {};
for (int i = 0; i < 5; i++)
I[i][i] = 1;
for (int i = 0; i < 5; i++)
orange(all(I[i]));
int n, m;
while (cin >> n >> m >> mod) {
Mat A = {}, B = {};
for (int i = 0; i < m; i++) {
for (int j = 0; j < m; j++)
cin >> A[i][j];
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < m; j++)
cin >> B[i][j];
}
vector<Mat> lef, rig;
Mat rigprod = I;
auto push = [&](const Mat &mat) {
rigprod = mul(rigprod, mat);
rig.emplace_back(mat);
};
auto pop = [&] {
if (lef.empty()) {
Mat p = I;
for (const auto &mat : rig | views::reverse) {
p = mul(mat, p);
lef.push_back(p);
}
rig.clear();
rigprod = I;
}
assert(!lef.empty());
lef.pop_back();
};
auto getprod = [&] {
if (lef.empty())
return rigprod;
return mul(lef.back(), rigprod);
};
vector<int> c(n + 1);
for (int i = 1; i <= n; i++)
cin >> c[i];
push(A);
for (int i = 1; i <= n; i++) {
debug(i);
for (auto &l : lef)
debug(l[0][0]);
for (auto &r : rig)
debug(r[0][0]);
debug(rigprod[0][0]);
while (lef.size() + rig.size() > i - c[i])
pop();
assert(lef.size() + rig.size() == i - c[i]);
debug(i);
for (auto &l : lef)
debug(l[0][0]);
for (auto &r : rig)
debug(r[0][0]);
debug(rigprod[0][0]);
auto M = mul(getprod(), B);
push(M);
if (i == n) {
for (int a = 0; a < m; a++)
for (int b = 0; b < m; b++)
cout << M[a][b] << (b+1==m ? '\n' : ' ');
}
}
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3648kb
input:
2 2 1000000000 1 1 0 1 1 0 0 1 0 0 2 2 2 1 1 0 1 1 0 0 1 0 0 5 2 1000000000 1 1 0 1 1 0 0 1 0 1 2 3 4
output:
1 2 0 1 1 0 0 1 1 1 0 1
result:
ok 12 numbers
Test #2:
score: 0
Accepted
time: 1376ms
memory: 3708kb
input:
466 2 435552779 31265764 7236363 35007475 90917701 282773567 208988195 426333035 139951817 0 1 1 1 2 4 6 6 6 8 10 11 11 11 14 15 15 17 18 18 19 21 22 23 24 25 25 25 27 28 29 31 31 31 34 34 34 35 37 38 40 41 41 43 43 45 45 47 47 48 48 51 51 53 54 55 56 56 58 59 59 60 60 63 64 65 65 67 68 69 69 70 70 ...
output:
354138416 399054365 368439278 263545176 241193065 290466096 324761468 89516749 9220346 83008146 81207367 31675361 12736395 2963430 89820225 144665640 331960427 45887611 19512846 133824115 801650 25105311 68866145 55982276 339469419 405018574 325692763 410799118 27360841 12212385 106210905 83767241 1...
result:
ok 4000 numbers
Test #3:
score: 0
Accepted
time: 1373ms
memory: 3708kb
input:
6000 3 616081378 470026658 21569884 414779748 435781264 288033654 266600280 365603064 81705470 513811687 531647864 49353197 566771659 566418979 388210189 337815453 336928977 35107315 339381743 0 1 2 2 4 5 5 7 7 7 7 8 11 11 13 14 15 16 16 17 18 19 19 22 24 24 24 27 27 28 28 28 28 29 32 35 36 36 38 39...
output:
68461100 303845432 597581534 337561856 30187388 101122610 428789290 304385558 140384440 63624722 35329394 22439183 66483706 46988334 44916497 31338148 39613456 6833583 658990001 63560673 164448123 519972633 568168920 451013188 9831684 67404546 290394662 820222031 653139159 22024385 640046518 7088876...
result:
ok 9000 numbers
Test #4:
score: 0
Accepted
time: 1376ms
memory: 3860kb
input:
353 5 940188332 148056052 770560589 653861472 21032956 887294434 878976016 781463575 645942973 852956875 221593359 285956414 351785917 486139257 608028340 19035013 730459748 300266294 427314550 923034032 675995951 767744741 533306557 799763622 933321700 269699467 930140536 679425721 845809117 518591...
output:
312487682 517808184 224770578 75558409 355267641 157622276 156671101 213811824 154909076 557763160 713906599 162043694 646308309 357124623 139739628 293348808 302808132 611319928 338565709 884983408 805086216 612740804 402152923 194843952 89243710 908075816 971483066 784581402 899503026 955202429 31...
result:
ok 25000 numbers
Test #5:
score: 0
Accepted
time: 1380ms
memory: 6956kb
input:
1000000 5 821498257 793425154 190604990 217667534 332716787 793069173 38542261 341339250 265283754 750671198 433322871 16801049 319567984 617751711 209467383 573367267 195737013 742032012 352423273 2259534 762050206 380086220 506257184 633086777 284465914 345347037 689440824 486017207 524113226 6989...
output:
584318306 132455044 292160779 205680006 820335505 356714418 604064849 465182552 422197335 588348896 24917284 130165025 171730498 95562218 566168216 205347352 520756331 42094819 30053287 278582589 90210194 304805554 698255466 419756418 426659659
result:
ok 25 numbers
Test #6:
score: 0
Accepted
time: 1505ms
memory: 7576kb
input:
1000000 5 894048470 375326733 463219648 733455458 882844116 585233284 843062980 220785987 103168014 63028632 639982217 70893803 16719818 473572201 444970416 154150917 755108930 129122902 333740310 500072238 207983186 634363435 862369862 746252810 834381292 250984118 19728821 197792715 418291620 1852...
output:
79255910 678899040 847539390 769278750 333524640 831147660 66341340 523822810 707221940 290266200 824677600 782108880 345189630 606868320 558408490 401172830 721653340 549279780 143430690 406139190 29981000 420393980 519647770 582157800 711588250
result:
ok 25 numbers
Test #7:
score: 0
Accepted
time: 1458ms
memory: 210432kb
input:
1000000 5 252298101 212653274 59014614 236114423 127025308 40110099 66469369 127470574 138147384 2912182 187575618 98811526 46737749 136530208 177740906 82717832 81374692 247159278 81721630 250767495 27598723 164548155 191007784 64513552 105206585 179606249 146582438 94750818 161791263 15509544 6689...
output:
126492059 32800995 79653823 190748065 169210176 111917282 130236638 155878382 158283954 160859621 133646590 29670897 228489997 207068620 179006960 135795578 55330240 12111986 80684329 188229182 5546790 108422727 25899235 250514988 166287761
result:
ok 25 numbers
Test #8:
score: 0
Accepted
time: 1551ms
memory: 100540kb
input:
1000000 5 329084188 304720308 23481912 232291150 126719089 163000893 101162277 170061797 230918178 259262978 60922970 111525112 174202921 174654564 260066594 148236684 73842226 210920978 293381986 68845410 78674017 199331437 60072341 288778584 31194135 310682170 168161376 95316166 245571431 10097737...
output:
161538964 285905480 325271784 254316120 97099684 109844220 108527592 197897188 63728828 94506800 9258448 81660300 95068072 68894872 29275292 86237968 224349416 46679040 54324348 110281960 295223748 57460040 177833736 180697416 244208764
result:
ok 25 numbers
Extra Test:
score: 0
Extra Test Passed