diff --git a/S2OJ/1898/1898.cpp b/S2OJ/1898/1898.cpp new file mode 100644 index 00000000..98be5b1e --- /dev/null +++ b/S2OJ/1898/1898.cpp @@ -0,0 +1,80 @@ +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 2005; +const int mod = 1e9 + 9; + +int n, k, inv[N], fac[N], inv_fac[N], a[N], b[N], l[N], f[N][N], g[N], ans; + +inline int C(int n, int m) { + return static_cast(fac[n]) * inv_fac[m] % mod * inv_fac[n - m] % mod; +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + fac[0] = 1; + for (int i = 1; i < N; i++) { + fac[i] = static_cast(fac[i - 1]) * i % mod; + } + + inv[0] = inv[1] = 1; + for (int i = 2; i < N; i++) { + inv[i] = static_cast(mod - (mod / i)) * inv[mod % i] % mod; + } + + inv_fac[0] = inv_fac[1] = 1; + for (int i = 2; i < N; i++) { + inv_fac[i] = static_cast(inv_fac[i - 1]) * inv[i] % mod; + } + + cin >> n >> k; + + if ((n - k) % 2 == 1) { + cout << 0 << endl; + + exit(0); + } + + std::copy_n(std::istream_iterator(cin), n, a + 1); + std::copy_n(std::istream_iterator(cin), n, b + 1); + + std::sort(a + 1, a + 1 + n); + std::sort(b + 1, b + 1 + n); + std::transform(a + 1, a + 1 + n, l + 1, [&](int x) { + return std::distance(b + 1, std::lower_bound(b + 1, b + 1 + n, x)); + }); + + f[0][0] = 1; + + for (int i = 1; i <= n; i++) { + f[i][0] = f[i - 1][0]; + + for (int j = 1; j <= i; j++) { + f[i][j] = (static_cast(f[i - 1][j]) + static_cast(f[i - 1][j - 1]) * (l[i] - j + 1) % mod) % mod; + } + } + + for (int i = 0; i <= n; i++) { + g[i] = static_cast(f[n][i]) * fac[n - i] % mod; + } + + int w = (n + k) >> 1; + for (int i = w; i <= n; i++) { + if ((i - w) & 1) { + ans = (static_cast(ans) - static_cast(C(i, w)) * g[i] % mod + mod) % mod; + } else { + ans = (static_cast(ans) + static_cast(C(i, w)) * g[i] % mod) % mod; + } + } + + cout << ans << endl; + + return 0; +} diff --git a/S2OJ/1898/data/data1.in b/S2OJ/1898/data/data1.in new file mode 100644 index 00000000..3e1af26c --- /dev/null +++ b/S2OJ/1898/data/data1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bf2a7baff49e587def237afa7246dfa980296d4b7a2ac2741ba30addb3a3c724 +size 27555 diff --git a/S2OJ/1898/data/data1.out b/S2OJ/1898/data/data1.out new file mode 100644 index 00000000..80f7c8b8 --- /dev/null +++ b/S2OJ/1898/data/data1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:17dc755c5a224a0f898091ecc38d24ef19f3f19f4918ba1f906a911cceab1150 +size 10 diff --git a/S2OJ/1898/data/data10.in b/S2OJ/1898/data/data10.in new file mode 100644 index 00000000..521c198c --- /dev/null +++ b/S2OJ/1898/data/data10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2a7b0af3edde0558a50ff5ee95c164691aee0a63e031188ca2b85f18e8ba02d8 +size 27570 diff --git a/S2OJ/1898/data/data10.out b/S2OJ/1898/data/data10.out new file mode 100644 index 00000000..394ef510 --- /dev/null +++ b/S2OJ/1898/data/data10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:53e54a5a99721bcdef4366426de890a96127b217c25543e3ef5e8fcef5a37144 +size 10 diff --git a/S2OJ/1898/data/data2.in b/S2OJ/1898/data/data2.in new file mode 100644 index 00000000..ca97ecb4 --- /dev/null +++ b/S2OJ/1898/data/data2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:63715fca85ed323c8686e1a8eca31c72de2c1b9b4503223d098e5be58e7b42bb +size 2761 diff --git a/S2OJ/1898/data/data2.out b/S2OJ/1898/data/data2.out new file mode 100644 index 00000000..35e75fec --- /dev/null +++ b/S2OJ/1898/data/data2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2382d33bb3545a4ad3a0ba17b7216aa3cb81b1bfc9b0b425c851a19b5536931f +size 10 diff --git a/S2OJ/1898/data/data3.in b/S2OJ/1898/data/data3.in new file mode 100644 index 00000000..c8274d35 --- /dev/null +++ b/S2OJ/1898/data/data3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4bb490429c7ea86341b074ee2c8b0f3f91441aa050875e95c9d29e244fc37269 +size 1381 diff --git a/S2OJ/1898/data/data3.out b/S2OJ/1898/data/data3.out new file mode 100644 index 00000000..2f794e45 --- /dev/null +++ b/S2OJ/1898/data/data3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d22547682891733166e878dceff46acd77b3e8dd9883ff508cbab772b890f73b +size 10 diff --git a/S2OJ/1898/data/data4.in b/S2OJ/1898/data/data4.in new file mode 100644 index 00000000..59c6880d --- /dev/null +++ b/S2OJ/1898/data/data4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:20770e7dbd5d8ab31e2185a1d3fcf3639ef4dcdfa4298c1c5e9bde4c42948088 +size 27543 diff --git a/S2OJ/1898/data/data4.out b/S2OJ/1898/data/data4.out new file mode 100644 index 00000000..0ae7f33c --- /dev/null +++ b/S2OJ/1898/data/data4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c8fa3c46ba4e9e09dcc99fcb0533162f6d7bd1af64e0cc133de1219019aa6d5b +size 9 diff --git a/S2OJ/1898/data/data5.in b/S2OJ/1898/data/data5.in new file mode 100644 index 00000000..a66c0177 --- /dev/null +++ b/S2OJ/1898/data/data5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3051dd96bb1847824d690a49865bf50c2faf27ed7e142e65ec0999c3900624e0 +size 27522 diff --git a/S2OJ/1898/data/data5.out b/S2OJ/1898/data/data5.out new file mode 100644 index 00000000..d4d395d2 --- /dev/null +++ b/S2OJ/1898/data/data5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5d51530d86a45ab89b877d9a60703a8b43dcad00ec6a9099fbbfa0188a294db5 +size 10 diff --git a/S2OJ/1898/data/data6.in b/S2OJ/1898/data/data6.in new file mode 100644 index 00000000..34cd0bc6 --- /dev/null +++ b/S2OJ/1898/data/data6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fd3eb462e3c46613d8237930c8faa7a58b6d1407946b1189e04a5d193c5b82cf +size 202 diff --git a/S2OJ/1898/data/data6.out b/S2OJ/1898/data/data6.out new file mode 100644 index 00000000..2282bfe6 --- /dev/null +++ b/S2OJ/1898/data/data6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:11b97ca37e6fa8083cff17d690ef686be16876caf6ab1e059df0277a3df19d05 +size 6 diff --git a/S2OJ/1898/data/data7.in b/S2OJ/1898/data/data7.in new file mode 100644 index 00000000..12985462 --- /dev/null +++ b/S2OJ/1898/data/data7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d558bf692af5c0344b692dc8663060c35a81cd200a6abaa712a3873e0e9eefe9 +size 27562 diff --git a/S2OJ/1898/data/data7.out b/S2OJ/1898/data/data7.out new file mode 100644 index 00000000..b8227cdb --- /dev/null +++ b/S2OJ/1898/data/data7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:681e479adee0ce36b2c076df45750bacb56dd5d411be0f61ececabeb3facbeea +size 9 diff --git a/S2OJ/1898/data/data8.in b/S2OJ/1898/data/data8.in new file mode 100644 index 00000000..fd1d9c86 --- /dev/null +++ b/S2OJ/1898/data/data8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d68b61860e828991f09aeb68db116bb916b976abf2ddb5ccaaadb7cec24a62b7 +size 2766 diff --git a/S2OJ/1898/data/data8.out b/S2OJ/1898/data/data8.out new file mode 100644 index 00000000..6cdd35d9 --- /dev/null +++ b/S2OJ/1898/data/data8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9d3c89bc45c917e0ef1677009dcc822bdd96b70ae90ba2550d99d3ec8b957fb7 +size 10 diff --git a/S2OJ/1898/data/data9.in b/S2OJ/1898/data/data9.in new file mode 100644 index 00000000..41cbbe05 --- /dev/null +++ b/S2OJ/1898/data/data9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b039deaed8891389c23f00429841bdbf8e7829fa1698739b4ac58d9fcbe93728 +size 27568 diff --git a/S2OJ/1898/data/data9.out b/S2OJ/1898/data/data9.out new file mode 100644 index 00000000..818790ab --- /dev/null +++ b/S2OJ/1898/data/data9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6126bde8bed85482fa0d451178491a93bc7417f7291cc8c907d517c8337a51a4 +size 10 diff --git a/S2OJ/1898/data/problem.conf b/S2OJ/1898/data/problem.conf new file mode 100644 index 00000000..bfa99af8 --- /dev/null +++ b/S2OJ/1898/data/problem.conf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:14af6f937e7343ed6065b7f1ae40f21cb514266e9af9ad52c51237646b759e35 +size 208