이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
int n;
void solve() {
cin >> n;
vector<ll> a(n + 1);
if(n > 14) {
for(int i = 1; i <= n; i++) {
cin >> a[i];
}
vector<ll> prev(n + 1, 0), curr(n + 1, 0);
prev[0] = 1;
for(int i = 1; i <= n; i++) {
for(int j = 0; j <= n; j++) {
curr[j] = prev[j] * j % MOD;
if(j > 0) curr[j] = (curr[j] + prev[j - 1]) % MOD;
}
swap(prev, curr);
}
ll ans = 0;
for(int i = 1; i <= n; i++) {
ans = (ans + prev[i]) % MOD;
}
cout << ans << '\n';
return;
}
ll res = 1, maxi = 0;
for(int i = 1; i <= n; i++) {
cin >> a[i];
for(int j = 1; j < a[i]; j++) {
res = (res + j * res % MOD) % 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... |