109952024-05-04 20:12:28TaxiradioBástyák törött sakktábláncpp17Wrong answer 0/10064ms31992 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; 
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Wrong answer57ms31716 KiB
2Wrong answer57ms31848 KiB
subtask20/12
3Accepted63ms31760 KiB
4Accepted57ms31716 KiB
5Accepted63ms31808 KiB
6Accepted57ms31656 KiB
7Accepted57ms31864 KiB
8Accepted57ms31864 KiB
9Accepted56ms31844 KiB
10Accepted63ms31684 KiB
11Wrong answer57ms31716 KiB
12Accepted63ms31716 KiB
13Accepted63ms31736 KiB
14Wrong answer63ms31736 KiB
15Wrong answer57ms31852 KiB
16Wrong answer63ms31844 KiB
17Wrong answer63ms31760 KiB
18Wrong answer57ms31644 KiB
19Wrong answer57ms31716 KiB
20Wrong answer57ms31736 KiB
21Wrong answer57ms31716 KiB
subtask30/17
22Accepted63ms31800 KiB
23Accepted57ms31684 KiB
24Accepted64ms31732 KiB
25Accepted64ms31992 KiB
26Accepted64ms31860 KiB
27Accepted57ms31716 KiB
28Accepted57ms31700 KiB
29Accepted64ms31760 KiB
30Accepted64ms31892 KiB
31Wrong answer61ms31716 KiB
32Wrong answer57ms31856 KiB
33Accepted61ms31752 KiB
34Accepted64ms31784 KiB
subtask40/20
35Accepted64ms31672 KiB
36Accepted63ms31716 KiB
37Accepted64ms31844 KiB
38Accepted64ms31736 KiB
39Accepted57ms31864 KiB
40Accepted64ms31872 KiB
41Accepted63ms31624 KiB
42Accepted57ms31716 KiB
43Wrong answer63ms31972 KiB
44Accepted57ms31644 KiB
45Accepted57ms31984 KiB
46Wrong answer57ms31852 KiB
47Wrong answer57ms31864 KiB
48Wrong answer64ms31716 KiB
49Wrong answer57ms31760 KiB
50Wrong answer57ms31864 KiB
51Wrong answer64ms31716 KiB
52Wrong answer64ms31728 KiB
53Wrong answer64ms31720 KiB
54Accepted64ms31716 KiB
55Accepted57ms31864 KiB
56Accepted64ms31716 KiB
57Accepted57ms31716 KiB
58Accepted56ms31860 KiB
59Accepted64ms31860 KiB
60Accepted57ms31716 KiB
61Accepted57ms31716 KiB
62Accepted61ms31652 KiB
63Wrong answer57ms31864 KiB
64Wrong answer64ms31904 KiB
65Accepted64ms31716 KiB
66Accepted64ms31716 KiB
67Wrong answer63ms31864 KiB
68Wrong answer57ms31716 KiB
69Wrong answer57ms31748 KiB
70Wrong answer64ms31852 KiB
71Wrong answer63ms31736 KiB
72Wrong answer64ms31660 KiB
73Wrong answer64ms31744 KiB
subtask50/10
74Accepted59ms31864 KiB
75Accepted57ms31864 KiB
76Accepted57ms31868 KiB
77Accepted63ms31716 KiB
78Accepted57ms31720 KiB
79Accepted63ms31716 KiB
80Accepted57ms31716 KiB
81Accepted57ms31716 KiB
82Accepted64ms31716 KiB
83Wrong answer63ms31716 KiB
84Wrong answer63ms31880 KiB
85Accepted57ms31760 KiB
86Accepted57ms31740 KiB
87Accepted57ms31712 KiB
88Accepted59ms31988 KiB
89Accepted64ms31888 KiB
90Wrong answer64ms31892 KiB
91Wrong answer64ms31712 KiB
92Accepted57ms31680 KiB
93Accepted64ms31848 KiB
subtask60/41
94Wrong answer64ms31716 KiB
95Wrong answer61ms31736 KiB
96Accepted57ms31780 KiB
97Accepted57ms31696 KiB
98Accepted64ms31832 KiB
99Accepted61ms31716 KiB
100Accepted61ms31864 KiB
101Accepted63ms31740 KiB
102Accepted57ms31720 KiB
103Accepted61ms31864 KiB
104Wrong answer63ms31804 KiB
105Accepted64ms31716 KiB
106Accepted57ms31716 KiB
107Wrong answer64ms31716 KiB
108Wrong answer64ms31716 KiB
109Wrong answer61ms31760 KiB
110Wrong answer61ms31844 KiB
111Wrong answer63ms31720 KiB
112Wrong answer57ms31868 KiB
113Wrong answer61ms31736 KiB
114Wrong answer63ms31588 KiB
115Accepted61ms31700 KiB
116Accepted63ms31588 KiB
117Accepted61ms31868 KiB
118Accepted57ms31720 KiB
119Accepted57ms31728 KiB
120Accepted61ms31760 KiB
121Accepted63ms31868 KiB
122Accepted63ms31588 KiB
123Accepted63ms31796 KiB
124Wrong answer61ms31760 KiB
125Wrong answer57ms31556 KiB
126Accepted57ms31716 KiB
127Accepted57ms31864 KiB
128Wrong answer57ms31716 KiB
129Wrong answer57ms31864 KiB
130Wrong answer57ms31716 KiB
131Wrong answer56ms31864 KiB
132Wrong answer63ms31844 KiB
133Wrong answer57ms31720 KiB
134Wrong answer57ms31656 KiB
135Accepted63ms31844 KiB
136Accepted59ms31764 KiB
137Accepted64ms31736 KiB
138Wrong answer57ms31844 KiB
139Wrong answer57ms31792 KiB
140Accepted57ms31716 KiB
141Accepted57ms31736 KiB
142Wrong answer56ms31716 KiB
143Wrong answer56ms31716 KiB
144Wrong answer56ms31760 KiB
145Wrong answer63ms31992 KiB
146Wrong answer57ms31864 KiB
147Wrong answer63ms31844 KiB
148Wrong answer56ms31864 KiB
149Wrong answer56ms31864 KiB
150Wrong answer56ms31716 KiB
151Wrong answer57ms31720 KiB
152Wrong answer61ms31588 KiB