이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// Author: RufatM
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000007
#define INF 1e9+7
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define pb push_back
#define pii pair<ll,int>
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
const int N = 9000;
ll dp[N][N];
int n;
ll maxi = 0;
ll count(ll pos, ll max_team) {
if(pos > n) return 0;
if(pos == 0) return 1;
return ((count(pos - 1, max_team) * max_team) % MOD +
count(pos - 1, max_team + 1) % MOD) % MOD;
}
void solve() {
cin >> n;
vector<ll> a(n + 1);
if(n > 14) {
for(int i = 1; i <= n; i++) {
cin >> a[i];
}
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
dp[i][j] = ((dp[i-1][j] * j % MOD) + dp[i-1][j-1]) % MOD;
}
}
ll ans = 0;
for(int i = 1; i <= n; i++) {
ans = (ans + dp[n][i]) % MOD;
}
cout << ans << '\n';
return;
}
ll res = 1;
for(int i = 1; i <= n; i++) {
cin >> a[i];
for(int j = 1; j < a[i]; j++) {
res = (res + count(n - i, maxi)) % MOD;
}
maxi = max(maxi, a[i]);
}
cout << res << '\n';
}
signed main() {
fastio;
int t = 1;
//cin >> t;
while(t--) {
solve();
}
}
# | 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... |