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;
long long mod=1e9+7;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
if(n<=100){
vector<long long>now;
now.push_back(0);
vector<int>all(n);
for(int i=0;i<n;i++){
cin>>all[i];
}
for(int asd=0;asd<n;asd++){
now.push_back(all[asd]);
while(true){
sort(now.begin(),now.end());
int f=-1;
for(int i=1;i<(int)now.size()-1;i++){
if(now[i]==now[i+1]-1){
f=i;
}
}
if(f!=-1){
vector<long long>fn;
for(int i=0;i<(int)now.size();i++){
if(i==f||i==f+1){
continue;
}
fn.push_back(now[i]);
}
fn.push_back(now[f]+2);
now=fn;
}
else{
sort(now.begin(),now.end());
int f=-1;
for(int i=1;i<(int)now.size()-1;i++){
if(now[i]==now[i+1]){
f=i;
}
}
if(f!=-1){
vector<long long>fn;
for(int i=0;i<(int)now.size();i++){
if(i==f||i==f+1){
continue;
}
fn.push_back(now[i]);
}
if(now[f]==1){
fn.push_back(2);
}
else if(now[f]==2){
fn.push_back(3);
fn.push_back(1);
}
else{
fn.push_back(now[f]+1);
fn.push_back(now[f]-2);
}
now=fn;
}
else{
break;
}
}
}
while(true){
sort(now.begin(),now.end());
int f=-1;
for(int i=1;i<(int)now.size()-1;i++){
if(now[i]==now[i+1]){
f=i;
}
}
if(f!=-1){
vector<long long>fn;
for(int i=0;i<(int)now.size();i++){
if(i==f||i==f+1){
continue;
}
fn.push_back(now[i]);
}
if(now[f]==1){
fn.push_back(2);
}
else if(now[f]==2){
fn.push_back(3);
fn.push_back(1);
}
else{
fn.push_back(now[f]+1);
fn.push_back(now[f]-2);
}
now=fn;
}
else{
break;
}
}
vector<pair<long long,long long>>dp(asd+3);
long long len=0;
dp[0]=make_pair(1,0);
for(int i=1;i<(int)now.size();i++){
len=now[i]-now[i-1]-1;
if((now[i-1]%2)!=(now[i]%2)){
dp[i]=make_pair(dp[i-1].first+dp[i-1].second,(dp[i-1].first+dp[i-1].second)*(len/2));
}
else{
dp[i]=make_pair(dp[i-1].first+dp[i-1].second,(dp[i-1].first+dp[i-1].second)*(len/2)+dp[i-1].second);
}
dp[i].first%=mod;
dp[i].second%=mod;
}
long long res=dp[(int)now.size()-1].first+dp[(int)now.size()-1].second;
res%=mod;
cout<<res<<"\n";
}
}
else{
return 0;
}
}
# | 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... |