Task: | Planeetat |
Sender: | ollpu |
Submission time: | 2020-09-26 18:10:46 +0300 |
Language: | C++ (C++17) |
Status: | READY |
Result: | 24 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 24 |
#2 | WRONG ANSWER | 0 |
#3 | WRONG ANSWER | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.22 s | 1, 2, 3 | details |
#2 | ACCEPTED | 0.23 s | 1, 2, 3 | details |
#3 | ACCEPTED | 0.23 s | 1, 2, 3 | details |
#4 | ACCEPTED | 0.22 s | 1, 2, 3 | details |
#5 | ACCEPTED | 0.22 s | 1, 2, 3 | details |
#6 | ACCEPTED | 0.22 s | 1, 2, 3 | details |
#7 | ACCEPTED | 0.22 s | 1, 2, 3 | details |
#8 | ACCEPTED | 0.22 s | 1, 2, 3 | details |
#9 | ACCEPTED | 0.22 s | 1, 2, 3 | details |
#10 | ACCEPTED | 0.23 s | 1, 2, 3 | details |
#11 | WRONG ANSWER | 0.22 s | 2, 3 | details |
#12 | WRONG ANSWER | 0.22 s | 2, 3 | details |
#13 | WRONG ANSWER | 0.22 s | 2, 3 | details |
#14 | WRONG ANSWER | 0.23 s | 3 | details |
#15 | WRONG ANSWER | 0.37 s | 3 | details |
#16 | WRONG ANSWER | 0.55 s | 3 | details |
#17 | WRONG ANSWER | 0.54 s | 3 | details |
#18 | WRONG ANSWER | 0.54 s | 3 | details |
#19 | WRONG ANSWER | 0.54 s | 3 | details |
#20 | WRONG ANSWER | 0.54 s | 3 | details |
#21 | WRONG ANSWER | 0.54 s | 3 | details |
#22 | WRONG ANSWER | 0.54 s | 3 | details |
#23 | WRONG ANSWER | 0.55 s | 3 | details |
#24 | WRONG ANSWER | 0.54 s | 3 | details |
#25 | WRONG ANSWER | 0.54 s | 3 | details |
Code
#include <bits/stdc++.h> using namespace std; const int N = 5010; const int M = 1e9+7; // f(n, m): kuinka monta tapaa jakaa m solmua puiksi, joiden juuret on tietyt n solmua // f(n, m) = n*(n+m)^(m-1) // todistus: // Indeksöidään solmujoukot |A| = n ja |B| = m, A1, ..., An ja B1, ..., Bm // Samaan tapaan kuin todistuksessa sille, että puita on n^(n-2), // kaikille paitsi B1 valitaan kaari mihin tahansa solmuun. // Kombinaatioita on (n+m)^(m-1). // Jokaista tälläistä vastaa n kappaletta haluttuja rakenteita (ei syklejä ja B1 lähtee kaari) // seuraalla muunnoksella: // Valitaan kaikki syklit, järjestetään ne niiden sisältämän pienimmän indeksin mukaan, // ja tehdään polku, joka lähtee B1 ja etenee syklejä suurimmasta pienimpään. // Sykliin mentäessä mennään aina ensin pienimpään indeksiin, kierretään se ympäri, // ja korvataan viimeinen kaari sellaisella, joka menee seuraavaan sykliin. // Polku loppuu johonkin A:n solmuun, ja tälle jää n vaihtoehtoa. // Halutuista puurakenteista voi päätellä yksikäsitteisesti syklejä sisältävän esityksen // tarkastelemalla polkua B1 -> ... -> Ai. Uusi sykli alkaa aina, kun indeksi on pienempi // kuin mikään aiempi. Tieto viimeisestä solmusta Ai menetetään (jälleen n vaihtoehtoa), // mutta kuvaus on muuten injektiivinen. int f[N]; // f[x] = f(x, n-x) // s(n, m, k) on sellaisten verkkojen määrä, jossa n solmua sykleissä, m muuta solmua ja k komponenttia. // Saadaan kaava s(n, m, k) = nCr(n+m, n) * g(n, k) * f(n, m), // missä g(n, k) on n:n solmun permutaatioiden määrä, joissa on k sykliä. // g(n, k) löytyy rekursio // g(n, k) = (n-1) * g(n-1, k) + g(n-1, k-1) // (uusi solmu voidaan joko lisätä olemassaolevaan sykliin, minkä tahansa // n-1 solmun jälkeen, tai se voi muodostaa uuden syklin.) int nCr[N][N]; int g[N][N]; long fpow(long b, long e) { if (e == 0) return 1; if (e%2) return fpow(b, e-1)*b%M; long t = fpow(b, e/2); return t*t%M; } int main() { ios::sync_with_stdio(0); cin.tie(0); for (int i = 0; i < N; ++i) nCr[i][0] = 1; g[0][0] = 1; for (int i = 1; i < N; ++i) { for (int j = 1; j < N; ++j) { nCr[i][j] = (nCr[i-1][j] + nCr[i-1][j-1])%M; g[i][j] = (long(i-1)*g[i-1][j]%M + g[i-1][j-1])%M; } } int n; cin >> n; for (long x = 1; x < n; ++x) { f[x] = x*fpow(n, n-x-1)%M; } f[n] = 1; for (int k = 1; k <= n; ++k) { long res = 0; for (int x = 1; x <= n; ++x) { // s(x, n-x, k) res = (res + nCr[n][x]*g[x][k]%M*f[x])%M; } cout << res << "\n"; } }
Test details
Test 1
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
1 |
correct output |
---|
1 |
user output |
---|
1 |
Test 2
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
2 |
correct output |
---|
3 1 |
user output |
---|
3 1 |
Test 3
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
3 |
correct output |
---|
17 9 1 |
user output |
---|
17 9 1 |
Test 4
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
4 |
correct output |
---|
142 95 18 1 |
user output |
---|
142 95 18 1 |
Test 5
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
5 |
correct output |
---|
1569 1220 305 30 1 |
user output |
---|
1569 1220 305 30 1 |
Test 6
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
6 |
correct output |
---|
21576 18694 5595 745 45 ... |
user output |
---|
21576 18694 5595 745 45 ... |
Test 7
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
7 |
correct output |
---|
355081 334369 113974 18515 1540 ... |
user output |
---|
355081 334369 113974 18515 1540 ... |
Test 8
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
8 |
correct output |
---|
6805296 6852460 2581964 484729 49840 ... |
user output |
---|
6805296 6852460 2581964 484729 49840 ... |
Test 9
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
9 |
correct output |
---|
148869153 158479488 64727522 13591116 1632099 ... |
user output |
---|
148869153 158479488 64727522 13591116 1632099 ... |
Test 10
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
10 |
correct output |
---|
660215659 85349908 783995053 409987640 55545735 ... |
user output |
---|
660215659 85349908 783995053 409987640 55545735 ... |
Test 11
Group: 2, 3
Verdict: WRONG ANSWER
input |
---|
20 |
correct output |
---|
8033007 474885151 998010619 720259168 345757330 ... |
user output |
---|
162705530 78046561 619220986 -238654148 653204543 ... Truncated |
Test 12
Group: 2, 3
Verdict: WRONG ANSWER
input |
---|
50 |
correct output |
---|
637699856 613177596 194234103 50828885 988168359 ... |
user output |
---|
260016497 -49924003 708955742 976908690 601121969 ... Truncated |
Test 13
Group: 2, 3
Verdict: WRONG ANSWER
input |
---|
100 |
correct output |
---|
894456323 406549429 962038245 430640330 61348310 ... |
user output |
---|
465546320 843382928 903424681 22722934 292281771 ... Truncated |
Test 14
Group: 3
Verdict: WRONG ANSWER
input |
---|
666 |
correct output |
---|
189730587 968711879 553374698 53051125 139917248 ... |
user output |
---|
515540618 770301779 456354318 307574796 6981301 ... Truncated |
Test 15
Group: 3
Verdict: WRONG ANSWER
input |
---|
3333 |
correct output |
---|
79235821 455292218 627100211 591681254 695866885 ... |
user output |
---|
163551323 552880808 -195888655 345163872 154377689 ... Truncated |
Test 16
Group: 3
Verdict: WRONG ANSWER
input |
---|
4991 |
correct output |
---|
482116496 245260697 151422537 180441123 318466624 ... |
user output |
---|
511242337 799078555 92832852 -181026034 308156328 ... Truncated |
Test 17
Group: 3
Verdict: WRONG ANSWER
input |
---|
4992 |
correct output |
---|
141010647 787351178 684701591 872974815 631476284 ... |
user output |
---|
248650168 -525892152 950745068 470606091 203354573 ... Truncated |
Test 18
Group: 3
Verdict: WRONG ANSWER
input |
---|
4993 |
correct output |
---|
504034249 588971460 281533415 928250892 416697844 ... |
user output |
---|
447700847 -434249206 683575187 19180429 243673969 ... Truncated |
Test 19
Group: 3
Verdict: WRONG ANSWER
input |
---|
4994 |
correct output |
---|
266134603 90079109 544661648 812099750 17249410 ... |
user output |
---|
724212559 596943397 17551545 80910793 501612210 ... Truncated |
Test 20
Group: 3
Verdict: WRONG ANSWER
input |
---|
4995 |
correct output |
---|
833898560 663839791 109127071 321675160 86285359 ... |
user output |
---|
479981113 187247188 -750416185 244136858 527811585 ... Truncated |
Test 21
Group: 3
Verdict: WRONG ANSWER
input |
---|
4996 |
correct output |
---|
721158645 167929822 115103278 491345159 114397872 ... |
user output |
---|
-414220343 -108405161 439538453 -168179862 431969030 ... Truncated |
Test 22
Group: 3
Verdict: WRONG ANSWER
input |
---|
4997 |
correct output |
---|
691405606 436947443 82656395 514529009 783319673 ... |
user output |
---|
524987574 680838923 209377709 38230819 588974330 ... Truncated |
Test 23
Group: 3
Verdict: WRONG ANSWER
input |
---|
4998 |
correct output |
---|
829675470 688714502 189351950 956110193 20883331 ... |
user output |
---|
55903203 142113680 420180187 -823116621 303173395 ... Truncated |
Test 24
Group: 3
Verdict: WRONG ANSWER
input |
---|
4999 |
correct output |
---|
343936737 47032567 190931571 827280581 160866637 ... |
user output |
---|
-187795978 24666726 17788516 614627523 929186155 ... Truncated |
Test 25
Group: 3
Verdict: WRONG ANSWER
input |
---|
5000 |
correct output |
---|
364064601 633559852 352848841 666954216 428009512 ... |
user output |
---|
75951175 -306737527 393133788 -99890771 425022965 ... Truncated |