This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int nx=105, mod=1e9+7;
#define ll long long
ll n, a[nx], dp[nx][2], lst, cur, sz;
set<ll> s;
void add(ll x)
{
if (x!=1&&s.find(x-1)!=s.end()) s.erase(x-1), add(x+1);
else if (s.find(x+1)!=s.end()) s.erase(x+1), add(x+2);
else if (s.find(x)!=s.end())
{
if (x==1) s.erase(x), add(2);
else if (x==2) s.erase(x), add(1), add(3);
else s.erase(x), add(x-2), add(x+1);
}
else s.insert(x);
}
ll cost(ll x, ll y)
{
return (y-x-1)/2;
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n;
s.insert(0);
dp[0][0]=1;
for (int i=1; i<=n; i++)
{
cin>>a[i];
add(a[i]);
auto itr=s.begin();
sz=s.size()-1;
for (int j=1; j<=sz; j++)
{
lst=*(itr++);
cur=*itr;
dp[j][0]=(dp[j-1][0]+dp[j-1][1])%mod;
dp[j][1]=(dp[j-1][0]*cost(lst, cur)+dp[j-1][1]*cost(lst-1, cur))%mod;
//cout<<"cur "<<cur<<' '<<dp[j][0]<<' '<<dp[j][1]<<'\n';
}
cout<<(dp[sz][0]+dp[sz][1])%mod<<'\n';
}
}
# | 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... |