Submission #344976

#TimeUsernameProblemLanguageResultExecution timeMemory
344976IwanttobreakfreeMiners (IOI07_miners)C++98
34 / 100
7 ms876 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...