Task: | Kortit II |
Sender: | vgtcross |
Submission time: | 2024-10-28 03:23:26 +0200 |
Language: | C++ (C++20) |
Status: | READY |
Result: | 100 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 3 |
#2 | ACCEPTED | 5 |
#3 | ACCEPTED | 26 |
#4 | ACCEPTED | 28 |
#5 | ACCEPTED | 38 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.06 s | 1, 2, 3, 4, 5 | details |
#2 | ACCEPTED | 0.06 s | 2, 3, 4, 5 | details |
#3 | ACCEPTED | 0.07 s | 3, 4, 5 | details |
#4 | ACCEPTED | 0.07 s | 4, 5 | details |
#5 | ACCEPTED | 0.06 s | 5 | details |
#6 | ACCEPTED | 0.07 s | 5 | details |
Code
#include <bits/stdc++.h> #define MODE 1 #if MODE #define debug(x) cout << #x << ": " << (x) << endl #define log(x) cout << (x) << endl #define test(x) x #else #define debug(x) #define log(x) #define test(x) #endif #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() #define fi first #define se second #define X real() #define Y imag() using namespace std; using ll = long long; using ld = long double; using uint = unsigned int; using ull = unsigned long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using P = complex<ll>; template<typename S, typename T = S> void chmin(S &s, T t) {s = s < t ? s : t;} template<typename S, typename T = S> void chmax(S &s, T t) {s = s > t ? s : t;} const ll M = 1000000007; // 998244353 struct mint { int v; mint() {} mint(long long v) : v(0 <= v && v < M ? v : (v % M + M) % M) {} mint operator+(mint oth) { return v + oth.v < M ? v + oth.v : v + oth.v - M; } mint operator-(mint oth) { return v - oth.v >= 0 ? v - oth.v : v - oth.v + M; } mint operator*(mint oth) { return (long long) v * oth.v % M; } mint pow(ll e) { if (e == 0) return mint(1); mint a = this->pow(e/2); a *= a; if (e & 1) return a * (*this); return a; } mint inv() { return this->pow(M-2); } mint operator/(mint oth) { return (*this) * oth.inv(); } mint operator+=(mint oth) { (*this) = (*this) + oth; return *this; } mint operator-=(mint oth) { (*this) = (*this) - oth; return *this; } mint operator*=(mint oth) { (*this) = (*this) * oth; return *this; } mint operator/=(mint oth) { (*this) = (*this) / oth; return *this; } mint operator++() { return *this += 1; } mint operator++(int) { return (*this += 1) - 1; } mint operator--() { return *this -= 1; } mint operator--(int) { return (*this -= 1) + 1; } mint operator+(int oth) { return *this + mint(oth); } mint operator-(int oth) { return *this - mint(oth); } mint operator*(int oth) { return *this * mint(oth); } mint operator/(int oth) { return *this / mint(oth); } mint operator+=(int oth) { return *this += mint(oth); } mint operator-=(int oth) { return *this -= mint(oth); } mint operator*=(int oth) { return *this *= mint(oth); } mint operator/=(int oth) { return *this /= mint(oth); } }; mint inv(mint i) { return i.inv(); } mint pow(mint b, ll e) { return b.pow(e); } mint operator+(int a, mint oth) { return mint(a) + oth; } mint operator-(int a, mint oth) { return mint(a) - oth; } mint operator*(int a, mint oth) { return mint(a) * oth; } mint operator/(int a, mint oth) { return mint(a) / oth; } std::ostream &operator<<(std::ostream &os, mint i) { os << i.v; return os; } std::istream &operator>>(std::istream &is, mint &i) { is >> i.v; return is; } struct factorial { int n; vector<mint> f, i; factorial() {} factorial(int n) : n(n) { f.resize(n+1); i.resize(n+1); f[0] = 1; for (int j = 1; j <= n; ++j) f[j] = j * f[j-1]; i[n] = 1 / f[n]; for (int j = n-1; j >= 0; --j) i[j] = (j+1) * i[j+1]; } mint ncr(int n, int k) { if (0 > k || k > n) return 0; return f[n] * i[k] * i[n-k]; } mint npr(int n, int k) { if (0 > k || k > n) return 0; return f[n] * i[n-k]; } }; const int N = 2020; factorial F(N); mint dp[N][N]; void init() { dp[0][0] = 1; for (int i = 1; i < N; ++i) { for (int j = 1; j < N; ++j) { dp[i][j] = i * dp[i][j-1] + j * dp[i-1][j] + (i + j - 1) * dp[i-1][j-1]; } } } void solve() { int n, a, b; cin >> n >> a >> b; cout << dp[a][b] * F.ncr(n, a+b) * F.f[n] << '\n'; } int main() { cin.tie(0) -> sync_with_stdio(0); init(); int t = 0; if (t == 0) cin >> t; while (t--) solve(); return 0; }
Test details
Test 1
Group: 1, 2, 3, 4, 5
Verdict: ACCEPTED
input |
---|
54 4 4 0 3 1 3 3 2 2 4 0 4 ... |
correct output |
---|
0 0 0 0 0 ... |
user output |
---|
0 0 0 0 0 ... |
Test 2
Group: 2, 3, 4, 5
Verdict: ACCEPTED
input |
---|
284 6 1 0 5 0 2 7 1 5 7 7 5 ... |
correct output |
---|
0 0 35280 0 36720 ... |
user output |
---|
0 0 35280 0 36720 ... |
Test 3
Group: 3, 4, 5
Verdict: ACCEPTED
input |
---|
841 19 3 12 19 19 13 19 7 13 20 11 15 ... |
correct output |
---|
40291066 0 0 0 0 ... |
user output |
---|
40291066 0 0 0 0 ... |
Test 4
Group: 4, 5
Verdict: ACCEPTED
input |
---|
1000 15 12 6 7 1 6 44 4 26 6 6 5 ... |
correct output |
---|
0 5040 494558320 0 340694548 ... |
user output |
---|
0 5040 494558320 0 340694548 ... |
Test 5
Group: 5
Verdict: ACCEPTED
input |
---|
1000 892 638 599 966 429 655 1353 576 1140 1403 381 910 ... |
correct output |
---|
0 0 0 249098285 0 ... |
user output |
---|
0 0 0 249098285 0 ... |
Test 6
Group: 5
Verdict: ACCEPTED
input |
---|
1000 2000 1107 508 2000 1372 249 2000 588 65 2000 1739 78 ... |
correct output |
---|
750840601 678722180 744501884 159164549 868115056 ... |
user output |
---|
750840601 678722180 744501884 159164549 868115056 ... |