QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#370990#7612. Matrix Inverseideograph_advantageWA 588ms66840kbC++204.8kb2024-03-29 20:41:552024-03-29 20:41:57

Judging History

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

  • [2024-03-29 20:41:57]
  • 评测
  • 测评结果:WA
  • 用时:588ms
  • 内存:66840kb
  • [2024-03-29 20:41:55]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0);
#define iter(a) a.begin(), a.end()
#define pb emplace_back
#define ff first
#define ss second
#define SZ(a) int(a.size())

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#ifdef zisk
void debug(){cerr << "\n";}
template<class T, class ... U> void debug(T a, U ... b){cerr << a << " ", debug(b...);}
template<class T> void pary(T l, T r) {
	while (l != r) cerr << *l << " ", l++;
	cerr << "\n";
}
#else
#define debug(...) void()
#define pary(...) void()
#endif

template<typename A, typename B>
ostream& operator<<(ostream& o, pair<A, B> p){
    return o << '(' << p.ff << ',' << p.ss << ')';
}

const ll MOD = 1000000007;
using matrix = vector<vector<ll>>;

matrix operator*(const matrix &a, const matrix &b){
    matrix c(SZ(a), vector<ll>(SZ(b[0])));
    for(int i = 0; i < SZ(a); i++)
        for(int j = 0; j < SZ(b[0]); j++)
            for(int k = 0; k < SZ(b); k++){
                c[i][j] += a[i][k] * b[k][j] % MOD;
                c[i][j] %= MOD;
            }
    return c;
}

ll inv(ll a){
    ll b = MOD - 2;
    ll ans = 1;
    while(b){
        if(b & 1) ans = ans * a % MOD;
        b >>= 1;
        a = a * a % MOD;
    }
    return ans;
}

void topos(ll &a){
    a = (a % MOD + MOD) % MOD;
}


void debug_matrix(const matrix &mat){
    debug("matrix");
    for(auto &i : mat) pary(iter(i));
}

void gauss(matrix &mat){
    //debug("gauss");
    //debug_matrix(mat);
    int n = SZ(mat);
    for(int i = 0; i < n; i++){
        for(int j = i; j < n; j++)
            if(mat[j][i] != 0){
                mat[i].swap(mat[j]);
                break;
            }
        ll t = inv(mat[i][i]);
        for(int j = i; j < SZ(mat[i]); j++)
            mat[i][j] = mat[i][j] * t % MOD;
        for(int j = 0; j < n; j++){
            if(i == j) continue;
            t = mat[j][i];
            for(int k = i; k < SZ(mat[i]); k++){
                mat[j][k] -= t * mat[i][k] % MOD;
                topos(mat[j][k]);
            }
        }
        //debug("ok row", i);
        //debug_matrix(mat);
    }
}

matrix matrix_inv(matrix a){
    int n = SZ(a);
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++)
            a[i].pb(i == j);
    }
    gauss(a);
    matrix ans(n);
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++)
            ans[i].pb(a[i][n + j]);
    }
    return ans;
}

int main(){
    StarBurstStream;
    mt19937 rng(880301);
    //mt19937 gen(123123);

    int n;
    cin >> n;
    matrix a(n, vector<ll>(n));
    matrix c(n, vector<ll>(n));
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++){
            cin >> a[i][j];
            //a[i][j] = gen() % MOD;
        }
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            cin >> c[i][j];
    /*c = matrix_inv(a);
    for(int i = 0; i < 12; i++){
        int x = gen() % n;
        int y = gen() % n;
        c[x][y] = gen() % MOD;
    }*/
    //debug_matrix(a);
    //debug_matrix(c);
    
    matrix v(n, vector<ll>(1));
    for(int i = 0; i < n; i++) v[i][0] = rng() % MOD;

    matrix tmp = c * (a * v);
    //debug_matrix(v);
    //debug_matrix(tmp);
    vector<int> bad_row, bad_col;
    vector<bool> col(n);
    for(int i = 0; i < n; i++){
        if(tmp[i][0] != v[i][0]) bad_row.pb(i);
    }

    v = matrix(1, vector<ll>(n));
    //debug_matrix(v);
    //debug_matrix(tmp);
    for(int i = 0; i < n; i++) v[0][i] = rng() % MOD;
    tmp = v * a * c;
    for(int i = 0; i < n; i++){
        if(tmp[0][i] != v[0][i]) bad_col.pb(i), col[i] = true;
    }

    //pary(iter(bad_row));
    //pary(iter(bad_col));
    
    vector<pair<pii, ll>> sol;
    for(int i : bad_row){
        //debug("bad row", i);
        vector<vector<ll>> mat;
        for(int j = 0; j < SZ(bad_col); j++){
            mat.pb();
            ll sum = 0;
            for(int k = 0; k < n; k++){
                if(col[k]) mat.back().pb(a[k][j]);
                else sum += c[i][k] * a[k][j] % MOD;
            }
            topos(sum);
            mat.back().pb(-sum + (i == j));
            //debug("ok", i, j, sum);
        }
        //debug_matrix(mat);
        gauss(mat);
        //debug_matrix(mat);
        for(int j = 0; j < SZ(bad_col); j++){
            if(mat[j].back() != c[i][bad_col[j]]){
                sol.pb(make_pair(pii(i + 1, bad_col[j] + 1), mat[j].back()));
                c[i][bad_col[j]] = mat[j].back();
            }
        }
    }
    /*matrix I(n, vector<ll>(n));
    for(int i = 0; i < n; i++) I[i][i] = 1;
    assert(a * c == I);*/

    cout << SZ(sol) << "\n";
    for(auto [p, val] : sol) cout << p.ff << " " << p.ss << " " << val << "\n";

}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3564kb

input:

1
953176428
107682094

output:

0

result:

ok single line: '0'

Test #2:

score: 0
Accepted
time: 563ms
memory: 66504kb

input:

1995
586309310 548144807 578573993 437893403 641164340 712256053 172321263 108058526 768610920 123320669 762746291 856047593 979279376 29067913 309867338 292286426 45124325 239705174 675003623 213743652 620561338 116308277 695369179 669459894 682522334 846995555 159510341 999359657 645579085 7499563...

output:

2
827 238 84815305
1466 499 206940592

result:

ok 3 lines

Test #3:

score: 0
Accepted
time: 570ms
memory: 66164kb

input:

1995
436890614 28924575 276129332 63568266 576410175 399540058 591733285 531509939 637241038 596750662 811926780 760228238 317196903 751498201 993802643 102539089 382116597 233386377 974332817 495280100 575832855 616941506 297856263 216480938 638907269 434126707 499611855 764625526 51141033 64624519...

output:

3
315 590 222982023
421 1912 523778307
745 1803 328256562

result:

ok 4 lines

Test #4:

score: 0
Accepted
time: 554ms
memory: 66448kb

input:

1998
583111238 684686962 60000552 833067795 399706437 80311170 511421309 126675237 578609031 629890589 4721597 505178877 965431576 488092987 110903821 856966035 934194793 831090190 93501498 982251231 221658950 561834845 801921306 125139448 771849922 610370373 625334897 671223646 927123592 441019972 ...

output:

4
21 1273 160152585
700 1573 576757184
1674 1165 958703366
1860 1550 451190886

result:

ok 5 lines

Test #5:

score: 0
Accepted
time: 567ms
memory: 66540kb

input:

2000
717395008 183448326 460843970 942614578 540060179 334668801 284127311 635920935 518435676 579369810 852254297 342132392 390366615 141010330 256825376 585810764 253867889 483289117 141421931 467578626 750184736 801127935 917825514 702243210 954747981 910219404 311930180 11494244 915417963 820983...

output:

5
30 992 620409139
585 130 391404065
910 139 921101622
1292 496 462362602
1579 1776 163902318

result:

ok 6 lines

Test #6:

score: 0
Accepted
time: 588ms
memory: 66552kb

input:

2000
620840546 358023079 309405838 45500223 855686733 508959744 51181469 968972877 537705762 129000719 720633908 884983092 862573877 806580605 252024754 680227415 839963816 519838198 171117282 55679929 677376107 529124099 733179585 20941462 208815360 171000233 981430676 830346879 857681989 863823572...

output:

6
708 1628 497911789
714 1597 924600947
1105 1248 334964897
1209 1517 696980563
1386 1495 446362422
1427 979 599811696

result:

ok 7 lines

Test #7:

score: 0
Accepted
time: 562ms
memory: 66728kb

input:

1999
199111744 347283243 902808247 73043926 77805820 474451787 854137221 262193129 508272500 493604512 479354501 851331944 65939325 676555110 301252826 583818606 235970147 545653095 120576387 825367169 249335412 365652469 200134563 609796865 481733518 594700892 34132902 906919419 939234722 888820985...

output:

7
43 586 272473841
116 1477 158203105
122 1169 761579075
477 1913 749351268
592 583 329485518
662 1400 622650552
1563 148 498180819

result:

ok 8 lines

Test #8:

score: 0
Accepted
time: 550ms
memory: 66480kb

input:

1999
95525499 999471184 616044299 270968642 734163712 806403756 187471687 954208629 738712543 303515182 65192240 341396506 976491262 49950446 564351227 957716298 984366409 189359888 6212233 992086125 956271984 926015141 961718572 628613990 96751949 438018145 639769590 234289696 391888974 135327482 5...

output:

8
279 1620 990329039
882 1321 138573187
1060 836 505053059
1155 214 213425345
1525 906 706361973
1553 569 257967325
1601 1141 127915131
1898 738 215879720

result:

ok 9 lines

Test #9:

score: 0
Accepted
time: 564ms
memory: 66344kb

input:

1996
283446729 904496697 172085277 783069511 818458698 756950687 658910284 99042559 674918562 839616643 448339652 245867480 780073469 684157018 540143866 106204044 613514272 978909042 463995202 654242309 233752461 442383227 477386126 286799884 347610798 141921338 587706626 348419066 962374154 132965...

output:

9
309 1146 916944155
993 1418 998808956
1136 629 476558426
1232 181 439191299
1268 169 491439673
1314 1282 443126632
1415 447 825877434
1541 1779 159693126
1971 1624 228388510

result:

ok 10 lines

Test #10:

score: 0
Accepted
time: 569ms
memory: 66624kb

input:

2000
805314295 257118023 408649013 403270425 561279436 651061472 951531903 607216144 450523182 22974988 674008912 524751540 430060765 578271056 821812595 450493650 896882866 256881145 794394659 634756412 525452196 456872277 895856586 30892092 953830689 157566519 434684214 457301058 431434093 3366527...

output:

10
86 1649 33550286
277 1565 703044124
280 410 767223588
1104 2000 542808584
1165 1837 79761216
1198 360 199585712
1555 178 236137043
1785 1339 983174708
1869 827 135692552
1905 106 851820078

result:

ok 11 lines

Test #11:

score: 0
Accepted
time: 568ms
memory: 66504kb

input:

2000
817831410 837938066 689510456 728988871 925783369 338613646 248460715 797908768 377220868 479079342 718258246 570192472 123025052 702404754 46773852 774152140 719909131 276906493 812767887 453766159 835272763 672918600 773064126 85235335 702812671 696620460 835547337 762745753 759411320 8083624...

output:

11
1 1476 149884243
374 1642 562186259
561 1959 143239748
631 973 100680542
888 1538 726522334
977 526 154377214
1252 262 533011147
1327 1409 392931391
1516 1778 182730233
1782 369 67351156
1855 441 263735571

result:

ok 12 lines

Test #12:

score: 0
Accepted
time: 1ms
memory: 3564kb

input:

1
320856661
676593229

output:

1
1 1 914973852

result:

ok 2 lines

Test #13:

score: 0
Accepted
time: 578ms
memory: 66772kb

input:

2000
518876875 70744495 932244095 614062954 626814336 829150893 998680280 234000933 386686857 577640648 274534113 991968823 338694676 262803592 479224937 248407688 347367787 652722556 999864985 89935946 408575273 342878274 571453557 392556701 38963300 523278627 865830573 710529656 364067377 62819930...

output:

12
268 1341 872543861
301 670 83707290
404 923 771911145
515 915 315878115
531 1675 222526996
546 1464 698683617
667 1134 328997403
785 1886 372491749
1122 279 94873268
1178 1415 973999117
1868 1621 302520255
1969 339 658284571

result:

ok 13 lines

Test #14:

score: 0
Accepted
time: 547ms
memory: 66496kb

input:

1999
126132375 800032351 262637151 998840174 328383619 204918469 536208333 513995901 829164057 538609601 377089892 540716849 41937614 354466066 523585800 195798378 326644387 4751170 678657258 271678980 62983734 10852818 684364703 373677368 25240334 568320119 962133095 18314188 863238520 867505712 18...

output:

12
317 534 317967235
317 1221 672781882
317 1395 757051682
317 1533 223265150
663 534 107325986
663 1221 501079553
663 1395 352817739
663 1533 961065190
924 534 339954283
924 1221 188373539
924 1395 39691647
924 1533 854538181

result:

ok 13 lines

Test #15:

score: 0
Accepted
time: 558ms
memory: 66496kb

input:

1999
370828093 828933278 920173220 740771905 268813966 910479507 392970052 847922924 19573719 825413514 991590471 856671077 993900741 952892873 394675610 837428479 238861594 63756696 803502792 305104791 697054451 370933149 158939288 892700051 963947171 577946344 905348316 23696678 792096181 44575458...

output:

12
131 126 316849219
131 435 745757250
131 670 188997514
430 126 30755629
430 435 28926874
430 670 270564257
834 126 382641538
834 435 524485184
834 670 585102542
1613 126 932907865
1613 435 998975232
1613 670 263273055

result:

ok 13 lines

Test #16:

score: 0
Accepted
time: 547ms
memory: 66732kb

input:

1999
903591810 198238634 684298812 164105032 256956039 672861757 471025345 821182495 883470818 901728280 532295261 767968738 320294286 700772290 169700509 727112521 564257857 364791286 338836071 302817382 904614053 865507136 894734659 779655445 983613621 316690977 857375656 6451093 698119294 1598481...

output:

12
13 1960 424168931
194 234 227222514
615 234 273154103
615 1371 325633047
810 234 876520078
946 234 238602556
954 216 547623002
954 702 476976153
954 1960 503560106
1192 1960 698806771
1958 1371 631940104
1958 1960 388266681

result:

ok 13 lines

Test #17:

score: 0
Accepted
time: 534ms
memory: 66524kb

input:

1999
627118247 935982489 885954228 517473796 44083930 484518245 499676210 738332092 874151437 95535844 559086957 309113085 299789365 906919230 945098985 769325973 628282677 597797906 124653793 521055644 245063580 630252005 183949846 564672468 527964623 231388808 285012487 29386288 757802849 38889177...

output:

12
49 1793 921631393
705 1908 417596430
871 1908 961357700
1030 1908 283031921
1093 542 121661519
1093 1522 87579226
1093 1908 716167634
1489 542 612583557
1652 1793 909132547
1806 1522 282067170
1806 1596 984560360
1806 1793 852911378

result:

ok 13 lines

Test #18:

score: 0
Accepted
time: 571ms
memory: 66588kb

input:

2000
336477725 344614810 759723031 897668323 29157694 440949784 139315818 764784549 810466017 684155405 81843033 609608717 400540490 571611798 657357357 828338500 798932134 436045646 875622403 714290029 862194717 983729486 243849052 578156290 19156078 721842687 818890234 196674335 844235821 57639912...

output:

12
411 1126 501383645
411 1251 578770760
411 1407 428879799
766 1126 442413143
766 1251 682670649
766 1407 7221951
1138 1126 43277264
1138 1251 846615881
1138 1407 232292075
1717 1126 371996778
1717 1251 334914683
1717 1407 779537286

result:

ok 13 lines

Test #19:

score: 0
Accepted
time: 560ms
memory: 66464kb

input:

1999
192143667 846231509 374951421 282340579 992130213 32439194 730155201 452719071 682420232 674225452 10653359 409359680 584185410 580015389 475820282 736404188 394896233 352719251 492674608 141301951 784236812 373162646 188532420 708356143 183745168 192423076 442781368 484354809 697193908 9915016...

output:

12
81 1155 826104455
615 258 7345693
959 258 636752307
1016 942 774880182
1107 1155 541482380
1107 1816 176901086
1162 942 853261047
1162 1816 829575006
1717 942 377271277
1875 1816 48625384
1912 258 968957956
1912 1155 364003817

result:

ok 13 lines

Test #20:

score: 0
Accepted
time: 585ms
memory: 66536kb

input:

2000
470636580 899273352 350166464 523111928 812258536 899903901 71571732 842738863 987895689 136327554 652942779 650349069 335395341 460415467 955302064 348295085 286354455 812853909 922090473 915200207 803195822 135934405 428703857 262895139 319784332 63252432 866823736 388274158 204051575 1469072...

output:

12
360 1036 129892106
360 1767 994523999
623 327 215625787
623 750 412972732
623 928 893735116
623 1036 683799411
623 1918 186544232
1182 750 486642534
1182 929 532047060
1518 750 873084392
1578 78 186357954
1578 929 109060959

result:

ok 13 lines

Test #21:

score: 0
Accepted
time: 545ms
memory: 66480kb

input:

1999
720655701 977467852 885343236 88349312 14863630 100255901 925544428 452701056 132254633 821794681 439447077 100482626 494053817 810464371 280009501 782468062 626866283 523055497 380621157 48086399 954319042 651987710 916345938 67641818 363318266 921485607 561322272 333500586 711059456 941774238...

output:

12
276 246 501071414
276 301 135529322
276 411 310731045
276 415 702953806
276 524 457201176
276 864 980692702
276 1169 575959748
276 1474 25695168
276 1639 529621448
276 1664 385359528
276 1744 973257319
276 1917 707229662

result:

ok 13 lines

Test #22:

score: -100
Wrong Answer
time: 567ms
memory: 66840kb

input:

2000
216228525 575319605 599895437 852292022 804282911 156399371 35939181 635345055 827829679 845342493 81147843 958100184 321410579 449849844 58967802 842945624 686219787 313017814 483472081 606773500 829761709 322450699 961455771 617304724 942667942 657778472 896729841 495800788 812068579 87926518...

output:

12
104 80 -252171586
132 80 -351682502
253 80 -519115333
329 80 -688824195
410 80 -705353258
456 80 -378545934
736 80 -459054305
984 80 -944849260
1142 80 -612924344
1347 80 -738358228
1417 80 -341544757
1832 80 -426705107

result:

wrong answer 2nd lines differ - expected: '104 80 747828421', found: '104 80 -252171586'