10995 | 2024-05-04 20:12:28 | Taxiradio | Bástyák törött sakktáblán | cpp17 | Wrong answer 0/100 | 64ms | 31992 KiB |
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define all(a) a.begin(), a.end()
int solve();
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int t=1;
//cin>>t;
while (t--) solve();
}
const ll mod=1e9+7;
const ll maxn=2001;
//x^mod-2=1/x
ll binpow(ll a,ll b){
if (b==0) return 1;
ll res=binpow(a,b/2);
if (b%2) return res*res%mod*a%mod;
return res*res%mod;
}
vector<ll> a(maxn, 0);
vector<ll> fact(maxn*maxn, 1);
ll ncr(ll n, ll k){
return fact[n]*binpow(fact[n-k]*fact[k]%mod, mod-2)%mod;
}
ll q(ll height, ll base , ll amount){
if (height>=base) swap(height , base); //--
ll res=ncr(base, amount)*fact[height]%mod*binpow(fact[height-amount], mod-2)%mod;
return res;
}
ll spec(ll height, ll base){
if (height>base) return 0LL; //--
if (height<=0) return 1LL;
ll res=ncr(base, height)*fact[height]%mod;
return res;
}
int solve(){
ll n;
cin>>n;
ll div=0;
for (ll i=1;i<=n;i++){
cin>>a[i];
if (a[i]!=a[i-1]) div=i;
}
for (ll i=2;i<fact.size();i++) fact[i]=fact[i-1]*i%mod;
//cerr<<div<<"\n";
ll ans=0;
if (n==1){
cout<<n;
return 0;
}
if (div==1){
ans=spec(a[1],n);
cout<<ans;
return 0;
}
pair<ll,ll> top={div-1, a[div-1]};
pair<ll,ll> right={n-div+1,a[div]-a[div-1]};
pair<ll,ll> left={n-div+1,a[div-1]};
bool kill=false;
int x=max(left.first,right.first)-max(min(top.first,top.second), min(right.first,right.second));
for (ll i=0;i<=min(left.first, left.second);i++){
ll res=q(left.first,left.second , i);
res*=spec(top.second,top.first);
res=res%mod;
res*=spec(right.first,right.second);
res=res%mod;
top.second--;
right.first--;
if(x<=i) {
ans+=res;
ans=ans%mod;
}
}
cout<<ans<<"\n";
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Wrong answer | 57ms | 31716 KiB | ||||
2 | Wrong answer | 57ms | 31848 KiB | ||||
subtask2 | 0/12 | ||||||
3 | Accepted | 63ms | 31760 KiB | ||||
4 | Accepted | 57ms | 31716 KiB | ||||
5 | Accepted | 63ms | 31808 KiB | ||||
6 | Accepted | 57ms | 31656 KiB | ||||
7 | Accepted | 57ms | 31864 KiB | ||||
8 | Accepted | 57ms | 31864 KiB | ||||
9 | Accepted | 56ms | 31844 KiB | ||||
10 | Accepted | 63ms | 31684 KiB | ||||
11 | Wrong answer | 57ms | 31716 KiB | ||||
12 | Accepted | 63ms | 31716 KiB | ||||
13 | Accepted | 63ms | 31736 KiB | ||||
14 | Wrong answer | 63ms | 31736 KiB | ||||
15 | Wrong answer | 57ms | 31852 KiB | ||||
16 | Wrong answer | 63ms | 31844 KiB | ||||
17 | Wrong answer | 63ms | 31760 KiB | ||||
18 | Wrong answer | 57ms | 31644 KiB | ||||
19 | Wrong answer | 57ms | 31716 KiB | ||||
20 | Wrong answer | 57ms | 31736 KiB | ||||
21 | Wrong answer | 57ms | 31716 KiB | ||||
subtask3 | 0/17 | ||||||
22 | Accepted | 63ms | 31800 KiB | ||||
23 | Accepted | 57ms | 31684 KiB | ||||
24 | Accepted | 64ms | 31732 KiB | ||||
25 | Accepted | 64ms | 31992 KiB | ||||
26 | Accepted | 64ms | 31860 KiB | ||||
27 | Accepted | 57ms | 31716 KiB | ||||
28 | Accepted | 57ms | 31700 KiB | ||||
29 | Accepted | 64ms | 31760 KiB | ||||
30 | Accepted | 64ms | 31892 KiB | ||||
31 | Wrong answer | 61ms | 31716 KiB | ||||
32 | Wrong answer | 57ms | 31856 KiB | ||||
33 | Accepted | 61ms | 31752 KiB | ||||
34 | Accepted | 64ms | 31784 KiB | ||||
subtask4 | 0/20 | ||||||
35 | Accepted | 64ms | 31672 KiB | ||||
36 | Accepted | 63ms | 31716 KiB | ||||
37 | Accepted | 64ms | 31844 KiB | ||||
38 | Accepted | 64ms | 31736 KiB | ||||
39 | Accepted | 57ms | 31864 KiB | ||||
40 | Accepted | 64ms | 31872 KiB | ||||
41 | Accepted | 63ms | 31624 KiB | ||||
42 | Accepted | 57ms | 31716 KiB | ||||
43 | Wrong answer | 63ms | 31972 KiB | ||||
44 | Accepted | 57ms | 31644 KiB | ||||
45 | Accepted | 57ms | 31984 KiB | ||||
46 | Wrong answer | 57ms | 31852 KiB | ||||
47 | Wrong answer | 57ms | 31864 KiB | ||||
48 | Wrong answer | 64ms | 31716 KiB | ||||
49 | Wrong answer | 57ms | 31760 KiB | ||||
50 | Wrong answer | 57ms | 31864 KiB | ||||
51 | Wrong answer | 64ms | 31716 KiB | ||||
52 | Wrong answer | 64ms | 31728 KiB | ||||
53 | Wrong answer | 64ms | 31720 KiB | ||||
54 | Accepted | 64ms | 31716 KiB | ||||
55 | Accepted | 57ms | 31864 KiB | ||||
56 | Accepted | 64ms | 31716 KiB | ||||
57 | Accepted | 57ms | 31716 KiB | ||||
58 | Accepted | 56ms | 31860 KiB | ||||
59 | Accepted | 64ms | 31860 KiB | ||||
60 | Accepted | 57ms | 31716 KiB | ||||
61 | Accepted | 57ms | 31716 KiB | ||||
62 | Accepted | 61ms | 31652 KiB | ||||
63 | Wrong answer | 57ms | 31864 KiB | ||||
64 | Wrong answer | 64ms | 31904 KiB | ||||
65 | Accepted | 64ms | 31716 KiB | ||||
66 | Accepted | 64ms | 31716 KiB | ||||
67 | Wrong answer | 63ms | 31864 KiB | ||||
68 | Wrong answer | 57ms | 31716 KiB | ||||
69 | Wrong answer | 57ms | 31748 KiB | ||||
70 | Wrong answer | 64ms | 31852 KiB | ||||
71 | Wrong answer | 63ms | 31736 KiB | ||||
72 | Wrong answer | 64ms | 31660 KiB | ||||
73 | Wrong answer | 64ms | 31744 KiB | ||||
subtask5 | 0/10 | ||||||
74 | Accepted | 59ms | 31864 KiB | ||||
75 | Accepted | 57ms | 31864 KiB | ||||
76 | Accepted | 57ms | 31868 KiB | ||||
77 | Accepted | 63ms | 31716 KiB | ||||
78 | Accepted | 57ms | 31720 KiB | ||||
79 | Accepted | 63ms | 31716 KiB | ||||
80 | Accepted | 57ms | 31716 KiB | ||||
81 | Accepted | 57ms | 31716 KiB | ||||
82 | Accepted | 64ms | 31716 KiB | ||||
83 | Wrong answer | 63ms | 31716 KiB | ||||
84 | Wrong answer | 63ms | 31880 KiB | ||||
85 | Accepted | 57ms | 31760 KiB | ||||
86 | Accepted | 57ms | 31740 KiB | ||||
87 | Accepted | 57ms | 31712 KiB | ||||
88 | Accepted | 59ms | 31988 KiB | ||||
89 | Accepted | 64ms | 31888 KiB | ||||
90 | Wrong answer | 64ms | 31892 KiB | ||||
91 | Wrong answer | 64ms | 31712 KiB | ||||
92 | Accepted | 57ms | 31680 KiB | ||||
93 | Accepted | 64ms | 31848 KiB | ||||
subtask6 | 0/41 | ||||||
94 | Wrong answer | 64ms | 31716 KiB | ||||
95 | Wrong answer | 61ms | 31736 KiB | ||||
96 | Accepted | 57ms | 31780 KiB | ||||
97 | Accepted | 57ms | 31696 KiB | ||||
98 | Accepted | 64ms | 31832 KiB | ||||
99 | Accepted | 61ms | 31716 KiB | ||||
100 | Accepted | 61ms | 31864 KiB | ||||
101 | Accepted | 63ms | 31740 KiB | ||||
102 | Accepted | 57ms | 31720 KiB | ||||
103 | Accepted | 61ms | 31864 KiB | ||||
104 | Wrong answer | 63ms | 31804 KiB | ||||
105 | Accepted | 64ms | 31716 KiB | ||||
106 | Accepted | 57ms | 31716 KiB | ||||
107 | Wrong answer | 64ms | 31716 KiB | ||||
108 | Wrong answer | 64ms | 31716 KiB | ||||
109 | Wrong answer | 61ms | 31760 KiB | ||||
110 | Wrong answer | 61ms | 31844 KiB | ||||
111 | Wrong answer | 63ms | 31720 KiB | ||||
112 | Wrong answer | 57ms | 31868 KiB | ||||
113 | Wrong answer | 61ms | 31736 KiB | ||||
114 | Wrong answer | 63ms | 31588 KiB | ||||
115 | Accepted | 61ms | 31700 KiB | ||||
116 | Accepted | 63ms | 31588 KiB | ||||
117 | Accepted | 61ms | 31868 KiB | ||||
118 | Accepted | 57ms | 31720 KiB | ||||
119 | Accepted | 57ms | 31728 KiB | ||||
120 | Accepted | 61ms | 31760 KiB | ||||
121 | Accepted | 63ms | 31868 KiB | ||||
122 | Accepted | 63ms | 31588 KiB | ||||
123 | Accepted | 63ms | 31796 KiB | ||||
124 | Wrong answer | 61ms | 31760 KiB | ||||
125 | Wrong answer | 57ms | 31556 KiB | ||||
126 | Accepted | 57ms | 31716 KiB | ||||
127 | Accepted | 57ms | 31864 KiB | ||||
128 | Wrong answer | 57ms | 31716 KiB | ||||
129 | Wrong answer | 57ms | 31864 KiB | ||||
130 | Wrong answer | 57ms | 31716 KiB | ||||
131 | Wrong answer | 56ms | 31864 KiB | ||||
132 | Wrong answer | 63ms | 31844 KiB | ||||
133 | Wrong answer | 57ms | 31720 KiB | ||||
134 | Wrong answer | 57ms | 31656 KiB | ||||
135 | Accepted | 63ms | 31844 KiB | ||||
136 | Accepted | 59ms | 31764 KiB | ||||
137 | Accepted | 64ms | 31736 KiB | ||||
138 | Wrong answer | 57ms | 31844 KiB | ||||
139 | Wrong answer | 57ms | 31792 KiB | ||||
140 | Accepted | 57ms | 31716 KiB | ||||
141 | Accepted | 57ms | 31736 KiB | ||||
142 | Wrong answer | 56ms | 31716 KiB | ||||
143 | Wrong answer | 56ms | 31716 KiB | ||||
144 | Wrong answer | 56ms | 31760 KiB | ||||
145 | Wrong answer | 63ms | 31992 KiB | ||||
146 | Wrong answer | 57ms | 31864 KiB | ||||
147 | Wrong answer | 63ms | 31844 KiB | ||||
148 | Wrong answer | 56ms | 31864 KiB | ||||
149 | Wrong answer | 56ms | 31864 KiB | ||||
150 | Wrong answer | 56ms | 31716 KiB | ||||
151 | Wrong answer | 57ms | 31720 KiB | ||||
152 | Wrong answer | 61ms | 31588 KiB |