이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |