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 <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
int ship,production=0,cont1,cont2,production1,production2;
using namespace std;
string mine1;
string mine2;
int main(){
while(cin>>ship){
char food[ship];
for(int a=0;a<ship;a++){
cin>>food[a];
}
cont1=1;
cont2=0;
mine1[0]=food[0];
production=1;
for(int b=1;b<ship;b++){
if(cont1==1&&cont2==0){
if(food[b]!=mine1[cont1-1]) mine1[cont1]=food[b],cont1++,production+=2;
else mine2[cont2]=food[b],cont2++,production++;
}
else if(cont1>=2&&cont2==0){
if(food[b]!=mine1[cont1-1]&&mine1[cont1-1]!=mine1[cont1-2]&&food[b]!=mine1[cont1-2]) mine1[cont1]=food[b],cont1++,production+=3;
else mine2[cont2]=food[b],cont2++,production++;
}
else if(cont1==1&&cont2==1){
if(food[b]!=mine1[cont1-1]) mine1[cont1]=food[b],cont1++,production+=2;
else if(food[b]!=mine2[cont2-1]) mine2[cont2]=food[b],cont2++,production+=2;
else mine1[cont1]=food[b],cont1++,production++;
}
else if(cont1>=2&&cont2==1){
if(food[b]!=mine1[cont1-1]&&mine1[cont1-1]!=mine1[cont1-2]&&food[b]!=mine1[cont1-2]) mine1[cont1]=food[b],cont1++,production+=3;
else if(food[b]!=mine2[cont2-1])mine2[cont2]=food[b],cont2++,production+=2;
else if(food[b]!=mine1[cont1-1]||food[b]!=mine1[cont1-2])mine1[cont1]=food[b],cont1++,production+=2;
else mine1[cont1]=food[b],cont1++,production++;
}
else{
if(food[b]!=mine1[cont1-1]&&mine1[cont1-1]!=mine1[cont1-2]&&food[b]!=mine1[cont1-2]) mine1[cont1]=food[b],cont1++,production+=3;
else if(food[b]!=mine2[cont2-1]&&mine2[cont2-1]!=mine2[cont2-2]&&food[b]!=mine2[cont2-2]) mine2[cont2]=food[b],cont2++,production+=3;
else if(food[b]!=mine1[cont1-1]||food[b]!=mine1[cont1-2])mine1[cont1]=food[b],cont1++,production+=2;
else if(food[b]!=mine2[cont2-1]||food[b]!=mine2[cont2-2])mine2[cont2]=food[b],cont2++,production+=2;
else mine1[cont1]=food[b],cont1++,production++;
}
}
cout<<production<<endl;
}
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... |
# | 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... |