This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pl;
#define K first
#define V second
#define G(x) ll x; cin >> x;
#define GD(x) ld x; cin >> x;
#define GS(s) string s; cin >> s;
#define EX(x) { cout << x << '\n'; exit(0); }
#define A(a) (a).begin(), (a).end()
#define F(i, l, r) for (ll i = (l); i < r; ++i)
#define NN 1010
#define M 1000007 // 998244353
ll ncrc[NN][NN];
ll ncr(ll n, ll k) {
if (min(n, k) < 0) return 0;
if (n < k) return 0;
if (n == k || k == 0) return 1;
if (!~ncrc[n][k]) {
ncrc[n][k] = (ncr(n-1, k) + ncr(n-1, k-1))%M;
}
return ncrc[n][k];
}
ll dp[NN];
int main(){
// freopen("a.in", "r", stdin);
// freopen("a.out", "w", stdout);
ios_base::sync_with_stdio(false); cin.tie(0);
cout << fixed << setprecision(20);
memset(ncrc, -1, sizeof ncrc);
dp[0] = 1;
F(i, 1, NN) {
F(k, 1, i+1) dp[i] += dp[i-k] * ncr(i-1, k-1)%M;
dp[i]%=M;
}
// F(i, 0, 10) {
// cout << i << ": " << dp[i] << endl;
// }
ll answer = 1;
G(n) for (ll left = n; left >= 1; --left) {
G(x)
answer = (answer + (x-1) * dp[left])%M;
}
cout << answer << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |