10991 | 2024-05-02 20:12:35 | szil | Bástyák törött sakktáblán | cpp17 | Wrong answer 27/100 | 4ms | 764 KiB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const int MAXN = 2001;
int v[MAXN];
ll fact[MAXN];
ll bpow(ll a, ll k) {
if (k == 0) return 1;
if (k & 1) return (a*bpow(a, k-1))%MOD;
ll x = bpow(a, k/2);
return (x*x)%MOD;
}
ll inv(ll x) {
return bpow(x, MOD-2);
}
ll nck(ll a, ll b) {
return (fact[a] * inv((fact[b] * fact[a-b]) % MOD)) % MOD;
}
/*
5
1 2 2 3 4
*/
ll calc(ll a, ll b) {
if (a < b) swap(a, b);
return (nck(a, b) * fact[b])%MOD;
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int n; cin >> n;
fact[0] = fact[1] = 1;
for (ll i = 2; i < MAXN; i++) {
fact[i] = (fact[i-1] * i) % MOD;
}
for (int i = 1; i <= n; i++) cin >> v[i];
int cnt = 1;
for (int i = 2; i <= n; i++) {
if (v[i] == v[1]) cnt++;
else break;
}
if (v[1] == v[n]) {
cout << calc(v[1], n);
return 0;
}
ll ans = 0;
for (int i = 0; i <= min(n-cnt, v[1]); i++) {
ll x = ((calc(v[1]-i, cnt) * calc(n-cnt-i, v[n]-v[1])) % MOD);
if (v[1]-i > cnt && n-cnt-i > v[n]-v[1]) continue;
x *= (((nck(v[1], i) * nck(n-cnt, i)) % MOD) * fact[i]) % MOD;
x %= MOD;
ans += x;
ans %= MOD;
}
cout << ans << "\n";
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Wrong answer | 2ms | 356 KiB | ||||
2 | Wrong answer | 3ms | 356 KiB | ||||
subtask2 | 0/12 | ||||||
3 | Accepted | 3ms | 356 KiB | ||||
4 | Accepted | 3ms | 228 KiB | ||||
5 | Accepted | 3ms | 356 KiB | ||||
6 | Accepted | 3ms | 376 KiB | ||||
7 | Accepted | 3ms | 504 KiB | ||||
8 | Accepted | 2ms | 356 KiB | ||||
9 | Accepted | 3ms | 228 KiB | ||||
10 | Accepted | 3ms | 504 KiB | ||||
11 | Accepted | 3ms | 356 KiB | ||||
12 | Accepted | 3ms | 496 KiB | ||||
13 | Accepted | 3ms | 228 KiB | ||||
14 | Accepted | 3ms | 636 KiB | ||||
15 | Wrong answer | 3ms | 508 KiB | ||||
16 | Wrong answer | 3ms | 632 KiB | ||||
17 | Wrong answer | 2ms | 376 KiB | ||||
18 | Wrong answer | 3ms | 684 KiB | ||||
19 | Wrong answer | 2ms | 228 KiB | ||||
20 | Wrong answer | 3ms | 504 KiB | ||||
21 | Wrong answer | 2ms | 376 KiB | ||||
subtask3 | 17/17 | ||||||
22 | Accepted | 3ms | 376 KiB | ||||
23 | Accepted | 3ms | 356 KiB | ||||
24 | Accepted | 3ms | 492 KiB | ||||
25 | Accepted | 3ms | 620 KiB | ||||
26 | Accepted | 3ms | 484 KiB | ||||
27 | Accepted | 3ms | 356 KiB | ||||
28 | Accepted | 3ms | 504 KiB | ||||
29 | Accepted | 3ms | 228 KiB | ||||
30 | Accepted | 3ms | 496 KiB | ||||
31 | Accepted | 3ms | 504 KiB | ||||
32 | Accepted | 3ms | 504 KiB | ||||
33 | Accepted | 3ms | 504 KiB | ||||
34 | Accepted | 3ms | 524 KiB | ||||
subtask4 | 0/20 | ||||||
35 | Accepted | 3ms | 508 KiB | ||||
36 | Accepted | 3ms | 392 KiB | ||||
37 | Accepted | 3ms | 536 KiB | ||||
38 | Accepted | 3ms | 496 KiB | ||||
39 | Accepted | 3ms | 504 KiB | ||||
40 | Accepted | 4ms | 408 KiB | ||||
41 | Accepted | 3ms | 504 KiB | ||||
42 | Accepted | 3ms | 504 KiB | ||||
43 | Accepted | 3ms | 360 KiB | ||||
44 | Accepted | 2ms | 356 KiB | ||||
45 | Accepted | 3ms | 492 KiB | ||||
46 | Accepted | 3ms | 492 KiB | ||||
47 | Wrong answer | 3ms | 356 KiB | ||||
48 | Wrong answer | 3ms | 376 KiB | ||||
49 | Wrong answer | 2ms | 372 KiB | ||||
50 | Wrong answer | 3ms | 360 KiB | ||||
51 | Wrong answer | 3ms | 500 KiB | ||||
52 | Wrong answer | 3ms | 504 KiB | ||||
53 | Wrong answer | 3ms | 484 KiB | ||||
54 | Accepted | 2ms | 228 KiB | ||||
55 | Accepted | 3ms | 400 KiB | ||||
56 | Accepted | 3ms | 360 KiB | ||||
57 | Accepted | 3ms | 376 KiB | ||||
58 | Accepted | 3ms | 376 KiB | ||||
59 | Accepted | 3ms | 504 KiB | ||||
60 | Accepted | 3ms | 504 KiB | ||||
61 | Accepted | 3ms | 504 KiB | ||||
62 | Accepted | 3ms | 504 KiB | ||||
63 | Accepted | 3ms | 368 KiB | ||||
64 | Accepted | 3ms | 484 KiB | ||||
65 | Accepted | 4ms | 508 KiB | ||||
66 | Accepted | 3ms | 504 KiB | ||||
67 | Wrong answer | 3ms | 356 KiB | ||||
68 | Wrong answer | 3ms | 356 KiB | ||||
69 | Wrong answer | 3ms | 504 KiB | ||||
70 | Wrong answer | 3ms | 752 KiB | ||||
71 | Wrong answer | 3ms | 368 KiB | ||||
72 | Wrong answer | 3ms | 360 KiB | ||||
73 | Wrong answer | 3ms | 360 KiB | ||||
subtask5 | 10/10 | ||||||
74 | Accepted | 3ms | 228 KiB | ||||
75 | Accepted | 3ms | 496 KiB | ||||
76 | Accepted | 3ms | 504 KiB | ||||
77 | Accepted | 3ms | 632 KiB | ||||
78 | Accepted | 2ms | 412 KiB | ||||
79 | Accepted | 2ms | 380 KiB | ||||
80 | Accepted | 4ms | 504 KiB | ||||
81 | Accepted | 3ms | 356 KiB | ||||
82 | Accepted | 3ms | 528 KiB | ||||
83 | Accepted | 3ms | 228 KiB | ||||
84 | Accepted | 3ms | 232 KiB | ||||
85 | Accepted | 3ms | 376 KiB | ||||
86 | Accepted | 3ms | 504 KiB | ||||
87 | Accepted | 3ms | 376 KiB | ||||
88 | Accepted | 3ms | 504 KiB | ||||
89 | Accepted | 4ms | 364 KiB | ||||
90 | Accepted | 4ms | 376 KiB | ||||
91 | Accepted | 4ms | 356 KiB | ||||
92 | Accepted | 3ms | 228 KiB | ||||
93 | Accepted | 4ms | 484 KiB | ||||
subtask6 | 0/41 | ||||||
94 | Wrong answer | 3ms | 372 KiB | ||||
95 | Wrong answer | 3ms | 508 KiB | ||||
96 | Accepted | 3ms | 356 KiB | ||||
97 | Accepted | 3ms | 228 KiB | ||||
98 | Accepted | 3ms | 648 KiB | ||||
99 | Accepted | 2ms | 228 KiB | ||||
100 | Accepted | 3ms | 372 KiB | ||||
101 | Accepted | 3ms | 632 KiB | ||||
102 | Accepted | 3ms | 356 KiB | ||||
103 | Accepted | 4ms | 228 KiB | ||||
104 | Accepted | 3ms | 404 KiB | ||||
105 | Accepted | 3ms | 356 KiB | ||||
106 | Accepted | 3ms | 632 KiB | ||||
107 | Accepted | 3ms | 360 KiB | ||||
108 | Wrong answer | 2ms | 356 KiB | ||||
109 | Wrong answer | 3ms | 504 KiB | ||||
110 | Wrong answer | 3ms | 504 KiB | ||||
111 | Wrong answer | 2ms | 356 KiB | ||||
112 | Wrong answer | 3ms | 508 KiB | ||||
113 | Wrong answer | 3ms | 504 KiB | ||||
114 | Wrong answer | 3ms | 504 KiB | ||||
115 | Accepted | 3ms | 632 KiB | ||||
116 | Accepted | 3ms | 764 KiB | ||||
117 | Accepted | 3ms | 360 KiB | ||||
118 | Accepted | 2ms | 356 KiB | ||||
119 | Accepted | 3ms | 356 KiB | ||||
120 | Accepted | 3ms | 504 KiB | ||||
121 | Accepted | 3ms | 356 KiB | ||||
122 | Accepted | 3ms | 536 KiB | ||||
123 | Accepted | 3ms | 484 KiB | ||||
124 | Accepted | 3ms | 504 KiB | ||||
125 | Accepted | 3ms | 504 KiB | ||||
126 | Accepted | 3ms | 376 KiB | ||||
127 | Accepted | 3ms | 380 KiB | ||||
128 | Wrong answer | 3ms | 228 KiB | ||||
129 | Wrong answer | 3ms | 356 KiB | ||||
130 | Wrong answer | 4ms | 504 KiB | ||||
131 | Wrong answer | 3ms | 376 KiB | ||||
132 | Wrong answer | 3ms | 376 KiB | ||||
133 | Wrong answer | 3ms | 356 KiB | ||||
134 | Wrong answer | 3ms | 356 KiB | ||||
135 | Accepted | 3ms | 376 KiB | ||||
136 | Accepted | 3ms | 356 KiB | ||||
137 | Accepted | 4ms | 484 KiB | ||||
138 | Accepted | 4ms | 356 KiB | ||||
139 | Accepted | 4ms | 308 KiB | ||||
140 | Accepted | 3ms | 356 KiB | ||||
141 | Accepted | 3ms | 504 KiB | ||||
142 | Wrong answer | 3ms | 376 KiB | ||||
143 | Wrong answer | 3ms | 504 KiB | ||||
144 | Wrong answer | 3ms | 356 KiB | ||||
145 | Wrong answer | 3ms | 356 KiB | ||||
146 | Wrong answer | 3ms | 356 KiB | ||||
147 | Wrong answer | 4ms | 504 KiB | ||||
148 | Wrong answer | 3ms | 264 KiB | ||||
149 | Wrong answer | 3ms | 504 KiB | ||||
150 | Wrong answer | 3ms | 372 KiB | ||||
151 | Wrong answer | 3ms | 368 KiB | ||||
152 | Wrong answer | 3ms | 376 KiB |