이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define pb push_back
#define in insert
#define F first
#define S second
#define vll vector<ll>
#define all(v) v.begin(),v.end()
#define endl '\n'
#define pii pair<ll,ll>
using namespace std;
const ll INF =1e18, mod = 1e6 + 7, N = 1e4 + 50;
int maxi,q = 1;
int n;
int cnt(int w, int e){
if(e > n){
return 0;
}
if(w == 0){
return 1;
}
return(((cnt(w - 1, e) * e ) % mod) + (cnt(w - 1, e + 1) % mod) ) % mod;
}
vector<vector<int>>dp(N, vector<int>(N,0));
int a[N];
void solve(){
cin >> n;
if(n > 14){
for(int i =1; i<= n; i++){
cin >> a[i];
}
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 += dp[n][i] % mod;
ans %= mod;
}
cout << ans % mod;
return;
}
for(int i = 1; i <= n; i++){
cin >> a[i];//1 2 2
for(int j = 1; j < a[i]; j++){
q = (q + cnt(n - i,maxi)) % mod; /// space element
}/// 1 , 2 0,2
maxi = max(a[i], maxi);
}
cout << q % mod << endl;
}
int main(){
fast;
ll t = 1;
// cin >> t;
while(t--){
solve();
}
return 0;
}
# | 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... |