Task: | Planeetat |
Sender: | tykkipeli |
Submission time: | 2020-09-27 02:52:27 +0300 |
Language: | C++ (C++11) |
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.01 s | 1, 2, 3 | details |
#2 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
#3 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
#4 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
#5 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
#6 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
#7 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
#8 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
#9 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
#10 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
#11 | WRONG ANSWER | 0.01 s | 2, 3 | details |
#12 | WRONG ANSWER | 0.01 s | 2, 3 | details |
#13 | WRONG ANSWER | 0.03 s | 2, 3 | details |
#14 | WRONG ANSWER | 0.84 s | 3 | details |
#15 | TIME LIMIT EXCEEDED | -- | 3 | details |
#16 | TIME LIMIT EXCEEDED | -- | 3 | details |
#17 | TIME LIMIT EXCEEDED | -- | 3 | details |
#18 | TIME LIMIT EXCEEDED | -- | 3 | details |
#19 | TIME LIMIT EXCEEDED | -- | 3 | details |
#20 | TIME LIMIT EXCEEDED | -- | 3 | details |
#21 | TIME LIMIT EXCEEDED | -- | 3 | details |
#22 | TIME LIMIT EXCEEDED | -- | 3 | details |
#23 | TIME LIMIT EXCEEDED | -- | 3 | details |
#24 | TIME LIMIT EXCEEDED | -- | 3 | details |
#25 | TIME LIMIT EXCEEDED | -- | 3 | details |
Compiler report
input/code.cpp: In function 'std::vector<int> mull(const std::vector<int>&, const std::vector<int>&, const FFT_mod&)': input/code.cpp:62:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] for (int i = 0; i < left.size(); i++) { ~~^~~~~~~~~~~~~
Code
#include <bits/stdc++.h> #include <vector> #include <utility> #include <stdio.h> using namespace std; typedef long long ll; ll M = 1e9 + 7; ll ans[10101]; ll lol[10101]; ll fact[10101]; ll dp[5005][5005]; ll pot[5005][5005]; ll modinv[5005]; ll modinvfact[5005]; ll ncr[5005][5005]; template <typename T> T extGcd(T a, T b, T& x, T& y) { if (b == 0) { x = 1; y = 0; return a; } else { int g = extGcd(b, a % b, y, x); y -= a / b * x; return g; } } template <typename T> T modInv(T a, T m) { T x, y; extGcd(a, m, x, y); return (x % m + m) % m; } long long crt(const std::vector< std::pair<int, int> >& pp, int mod = -1); #include <algorithm> struct FFT_mod { int mod, root, root_1, root_pw; }; extern FFT_mod suggested_fft_mods[5]; void ntt_shortmod(std::vector<int>& a, bool invert, const FFT_mod& mod_data); const int mod = 1000000007; vector<int> mull(const vector<int>& left, const vector<int>& right, const FFT_mod& mod_data) { vector<int> left1 = left, right1 = right; ntt_shortmod(left1, false, mod_data); ntt_shortmod(right1, false, mod_data); for (int i = 0; i < left.size(); i++) { left1[i] = (left1[i] * 1ll * right1[i]) % mod_data.mod; } ntt_shortmod(left1, true, mod_data); return left1; } vector<int> mult(vector<int>& left, vector<int>& right) { int ssss = left.size() + right.size() - 1; int pot2; for (pot2 = 1; pot2 < ssss; pot2 <<= 1); left.resize(pot2); right.resize(pot2); vector<int> res[3]; for (int i = 0; i < 3; i++) { res[i] = mull(left, right, suggested_fft_mods[i]); } vector<int> ret(pot2); for (int i = 0; i < pot2; i++) { vector< pair<int,int> > mod_results; for (int j = 0; j < 3; j++) { mod_results.emplace_back(res[j][i], suggested_fft_mods[j].mod); } ret[i] = crt(mod_results, mod); } return ret; } long long crt(const std::vector< std::pair<int, int> >& a, int mod) { long long res = 0; long long mult = 1; int SZ = a.size(); std::vector<int> x(SZ); for (int i = 0; i<SZ; ++i) { x[i] = a[i].first; for (int j = 0; j<i; ++j) { long long cur = (x[i] - x[j]) * 1ll * modInv(a[j].second,a[i].second); x[i] = (int)(cur % a[i].second); if (x[i] < 0) x[i] += a[i].second; } res = (res + mult * 1ll * x[i]); mult = (mult * 1ll * a[i].second); if (mod != -1) { res %= mod; mult %= mod; } } return res; } FFT_mod suggested_fft_mods[] = { { 7340033, 5, 4404020, 1 << 20 }, { 415236097, 73362476, 247718523, 1<<22 }, { 463470593, 428228038, 182429, 1<<21}, { 998244353, 15311432, 469870224, 1 << 23 }, { 918552577, 86995699, 324602258, 1 << 22 } }; int FFT_w[1050000]; int FFT_w_dash[1050000]; void ntt_shortmod(std::vector<int>& a, bool invert, const FFT_mod& mod_data) { // only use if mod < 5*10^8 int n = (int)a.size(); int mod = mod_data.mod; for (int i = 1, j = 0; i<n; ++i) { int bit = n >> 1; for (; j >= bit; bit >>= 1) j -= bit; j += bit; if (i < j) std::swap(a[i], a[j]); } for (int len = 2; len <= n; len <<= 1) { int wlen = invert ? mod_data.root_1 : mod_data.root; for (int i = len; i<mod_data.root_pw; i <<= 1) wlen = int(wlen * 1ll * wlen % mod_data.mod); long long tt = wlen; for (int i = 1; i < len / 2; i++) { FFT_w[i] = tt; FFT_w_dash[i] = (tt << 31) / mod; int q = (FFT_w_dash[1] * 1ll * tt) >> 31; tt = (wlen * 1ll * tt - q * 1ll * mod) & ((1LL << 31) - 1); if (tt >= mod) tt -= mod; } for (int i = 0; i<n; i += len) { int uu = a[i], vv = a[i + len / 2] % mod; if (uu >= 2*mod) uu -= 2*mod; a[i] = uu + vv; a[i + len / 2] = uu - vv + 2 * mod; for (int j = 1; j<len / 2; ++j) { int u = a[i + j]; if (u >= 2*mod) u -= 2*mod; int q = (FFT_w_dash[j] * 1ll * a[i + j + len / 2]) >> 31; int v = (FFT_w[j] * 1ll * a[i + j + len / 2] - q * 1ll * mod) & ((1LL << 31) - 1); a[i + j] = u + v; a[i + j + len / 2] = u - v + 2*mod; } } } if (invert) { int nrev = modInv(n, mod); for (int i = 0; i<n; ++i) a[i] = int(a[i] * 1ll * nrev % mod); } } ll binpow(ll a, ll b, ll m) { if (b == -1) return binpow(a,M-2,M); ll ans = 1; while (b > 0) { if (b&1) ans = ans*a%m; a = a*a%m; b >>= 1; } return ans; } ll nCr(ll n, ll k) { ll ans = fact[n]; ans *= binpow(fact[k], M-2, M); ans %= M; ans *= binpow(fact[n-k], M-2, M); ans %= M; return ans; } void preCalcFact(int n) { fact[0] = 1; for (int i = 1; i <= n; i++) { fact[i] = fact[i-1]*i; fact[i] %= M; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; preCalcFact(n); //preCalcPot: for (int i = 1; i <= n; i++) { pot[i][0] = 1; for (int j = 1; j <= n; j++) { pot[i][j] = pot[i][j-1]*i; if (pot[i][j] <= M) pot[i][j] %= M; } } //preCalcModInv: for (int i = 1; i <= n; i++) { modinv[i] = binpow(i,M-2,M); } //preCaclModInvFact: for (int i = 1; i <= n; i++) { modinvfact[i] = binpow(fact[i],M-2,M); } modinvfact[0] = 1; //preCalcNcr: for (int i = 0; i <= n; i++) { for (int j = 0; j <= i; j++) { if (i == j) { ncr[i][j] = 1; continue; } ll ans = fact[i]; ans *= modinvfact[j]; if (ans >= M) ans %= M; ans *= modinvfact[i-j]; if (ans >= M) ans %= M; ncr[i][j] = ans; } } for (int i = 1; i <= n; i++) { for (int j = 1 ; j <= i; j++) { //lol[i] += ((nCr(i,j)*fact[j])%M)*binpow(i,i-j-1,M); if (i-j-1 >= 0) { lol[i] += ((ncr[i][j]*fact[j])%M)*pot[i][i-j-1]; } else { lol[i] += ((ncr[i][j]*fact[j])%M)*modinv[i]; } if (lol[i] >= M) lol[i] %= M; //cout << "i: " << i << "j: " << j << endl; //cout << ncr[i][j] << " " << nCr(i,j) << endl; //cout << binpow(i, i-j-1,M) << " " << pot[i][i-j-1] << endl; } } dp[0][0] = 1; for (int i = 1; i <= n; i++) dp[i][1] = lol[i]; for (int j = 2; j <= n; j++) { vector<int> f,g; for (int k = 1; k <= n-j+1; k++) { //f.push_back((binpow(fact[k-1],M-2,M)*lol[k])%M); //g.push_back((dp[j-2+k][j-1]*binpow(fact[j-2+k],M-2,M))%M); ll val = modinvfact[k-1]*lol[k]; if (val >= M) val %=M; f.push_back(val); val = dp[j-2+k][j-1]*modinvfact[j-2+k]; if (val >= M) val %= M; g.push_back(val); } auto p = mult(f,g); for (int i = j; i <= n; i++) dp[i][j] = (((ll)p[i-j])*fact[i-1])%M; } for (int i = 1; i <= n; i++) cout << dp[n][i] << "\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 |
---|
-6317764760460986853 235436048 948622621 254285490 345757330 ... Truncated |
Test 12
Group: 2, 3
Verdict: WRONG ANSWER
input |
---|
50 |
correct output |
---|
637699856 613177596 194234103 50828885 988168359 ... |
user output |
---|
343307976 606436473 955593375 686575832 98512121 ... Truncated |
Test 13
Group: 2, 3
Verdict: WRONG ANSWER
input |
---|
100 |
correct output |
---|
894456323 406549429 962038245 430640330 61348310 ... |
user output |
---|
856402209 476644574 963910053 383312774 547257490 ... Truncated |
Test 14
Group: 3
Verdict: WRONG ANSWER
input |
---|
666 |
correct output |
---|
189730587 968711879 553374698 53051125 139917248 ... |
user output |
---|
61255059 602663372 971902114 847301766 99608716 ... Truncated |
Test 15
Group: 3
Verdict: TIME LIMIT EXCEEDED
input |
---|
3333 |
correct output |
---|
79235821 455292218 627100211 591681254 695866885 ... |
user output |
---|
(empty) |
Test 16
Group: 3
Verdict: TIME LIMIT EXCEEDED
input |
---|
4991 |
correct output |
---|
482116496 245260697 151422537 180441123 318466624 ... |
user output |
---|
(empty) |
Test 17
Group: 3
Verdict: TIME LIMIT EXCEEDED
input |
---|
4992 |
correct output |
---|
141010647 787351178 684701591 872974815 631476284 ... |
user output |
---|
(empty) |
Test 18
Group: 3
Verdict: TIME LIMIT EXCEEDED
input |
---|
4993 |
correct output |
---|
504034249 588971460 281533415 928250892 416697844 ... |
user output |
---|
(empty) |
Test 19
Group: 3
Verdict: TIME LIMIT EXCEEDED
input |
---|
4994 |
correct output |
---|
266134603 90079109 544661648 812099750 17249410 ... |
user output |
---|
(empty) |
Test 20
Group: 3
Verdict: TIME LIMIT EXCEEDED
input |
---|
4995 |
correct output |
---|
833898560 663839791 109127071 321675160 86285359 ... |
user output |
---|
(empty) |
Test 21
Group: 3
Verdict: TIME LIMIT EXCEEDED
input |
---|
4996 |
correct output |
---|
721158645 167929822 115103278 491345159 114397872 ... |
user output |
---|
(empty) |
Test 22
Group: 3
Verdict: TIME LIMIT EXCEEDED
input |
---|
4997 |
correct output |
---|
691405606 436947443 82656395 514529009 783319673 ... |
user output |
---|
(empty) |
Test 23
Group: 3
Verdict: TIME LIMIT EXCEEDED
input |
---|
4998 |
correct output |
---|
829675470 688714502 189351950 956110193 20883331 ... |
user output |
---|
(empty) |
Test 24
Group: 3
Verdict: TIME LIMIT EXCEEDED
input |
---|
4999 |
correct output |
---|
343936737 47032567 190931571 827280581 160866637 ... |
user output |
---|
(empty) |
Test 25
Group: 3
Verdict: TIME LIMIT EXCEEDED
input |
---|
5000 |
correct output |
---|
364064601 633559852 352848841 666954216 428009512 ... |
user output |
---|
(empty) |