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<cstdio>
int n,a[50010],b[4],ans;
void push(int k){
if(k==3){
ans++;
return;
}
if(b[k+1]==1){
push(k+1);
}
b[k+1]=b[k];
}
void rotate(int k){
if(k){
push(0);
}
else{
if(b[3])ans++;
for(int i=3;i>1;i--)b[i]=b[i-1];
b[1]=0;
}
}
void f(){
int cnt=0;
for(int i=0;i<n;i++){
b[0]=1;
switch(a[i]){
case 1:
cnt++;
if(cnt==4){rotate(1);cnt=0;}
break;
case 2:
cnt=0;
rotate(1);
break;
default:
rotate(0);
cnt++;
if(cnt==4){rotate(1);cnt=0;}
break;
}
//for(int j=0;j<4;j++)printf("%d ",b[j]);
//printf("cnt=%d ans=%d\n",cnt,ans);
}
}
int main(){
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
}
f();
printf("%d",ans);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |