# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
217187 |
2020-03-29T08:01:20 Z |
combi1k1 |
Ruins 3 (JOI20_ruins3) |
C++14 |
|
464 ms |
3576 KB |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld double
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define pb emplace_back
#define X first
#define Y second
const int N = 1500;
const int mod = 1e9 + 7;
void add(int &a,int b) {
a += b;
if (a >= mod)
a -= mod;
}
void sub(int &a,int b) {
a -= b;
if (a < 0)
a += mod;
}
int mul(int a,int b) {
return 1ll * a * b % mod;
}
int Pow(int a,int b) {
int ans = 1;
while (b) {
if(b & 1) ans = mul(ans,a);
a = mul(a,a); b >>= 1;
}
return ans;
}
int inv(int a,int p) {
return a == 1 ? 1 : p - 1ll * p * inv(p % a,a) / a;
}
typedef pair<int,int> ii;
int Fac[N];
int Inv[N];
int Ckn(int n,int k) {
if (n < k) return 0;
if (k < 0) return 0;
return mul(Fac[n],mul(Inv[k],Inv[n - k]));
}
int a[N];
int f[N][N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
Fac[0] = Inv[0] = 1;
for(int i = 1 ; i < N ; ++i) Fac[i] = mul(Fac[i - 1],i); Inv[N - 1] = inv(Fac[N - 1],mod);
for(int i = N - 2 ; i ; --i) Inv[i] = mul(Inv[i + 1],i + 1);
int n; cin >> n;
for(int i = 0 ; i < n ; ++i) cin >> a[i];
f[0][0] = 1;
for(int i = 0 ; i < n ; ++i)
for(int j = 0 ; j <= n ; ++j) if (f[i][j])
for(int k = 0 ; k <= min(n,a[i] - i - 1) - j ; ++k) {
int nxt = f[i][j];
nxt = mul(nxt,Fac[k + k]);
nxt = mul(nxt,Inv[k]);
nxt = mul(nxt,Ckn(a[i] - i - j - 1,k));
if(!k) nxt = mul(nxt,j - i);
add(f[i + 1][j + k],nxt);
}
int ans = f[n][n];
for(int i = 0 ; i < n ; ++i)
ans = mul(ans,500000004);
cout << ans << endl;
}
Compilation message
ruins3.cpp: In function 'int main()':
ruins3.cpp:63:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
for(int i = 1 ; i < N ; ++i) Fac[i] = mul(Fac[i - 1],i); Inv[N - 1] = inv(Fac[N - 1],mod);
^~~
ruins3.cpp:63:69: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
for(int i = 1 ; i < N ; ++i) Fac[i] = mul(Fac[i - 1],i); Inv[N - 1] = inv(Fac[N - 1],mod);
^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
640 KB |
Output is correct |
12 |
Correct |
5 ms |
640 KB |
Output is correct |
13 |
Correct |
5 ms |
640 KB |
Output is correct |
14 |
Correct |
5 ms |
640 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
640 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
640 KB |
Output is correct |
19 |
Correct |
5 ms |
640 KB |
Output is correct |
20 |
Correct |
5 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
640 KB |
Output is correct |
12 |
Correct |
5 ms |
640 KB |
Output is correct |
13 |
Correct |
5 ms |
640 KB |
Output is correct |
14 |
Correct |
5 ms |
640 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
640 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
640 KB |
Output is correct |
19 |
Correct |
5 ms |
640 KB |
Output is correct |
20 |
Correct |
5 ms |
640 KB |
Output is correct |
21 |
Correct |
10 ms |
2816 KB |
Output is correct |
22 |
Correct |
8 ms |
2816 KB |
Output is correct |
23 |
Correct |
8 ms |
2816 KB |
Output is correct |
24 |
Correct |
13 ms |
2816 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
5 ms |
384 KB |
Output is correct |
28 |
Correct |
6 ms |
2816 KB |
Output is correct |
29 |
Correct |
5 ms |
384 KB |
Output is correct |
30 |
Correct |
464 ms |
3448 KB |
Output is correct |
31 |
Correct |
244 ms |
3448 KB |
Output is correct |
32 |
Correct |
349 ms |
3320 KB |
Output is correct |
33 |
Correct |
448 ms |
3448 KB |
Output is correct |
34 |
Correct |
241 ms |
3320 KB |
Output is correct |
35 |
Correct |
358 ms |
3576 KB |
Output is correct |
36 |
Correct |
435 ms |
3424 KB |
Output is correct |