ants.cpp
#include<stdio.h>
int main(){
int l, ant;
scanf("%d %d", &l, &ant);
char pole[l];
for(int i = 0;i < l;i++){
pole[i] = '0';
}
int poz;
char index;
for(int x = 0; x < ant ;x++){
scanf("%d %c", &poz, &index);
pole[poz]=index;
}
int left = 0;
int right = 0;
int v = 0;
int pozright = 0;
int y = l;
while ((left == 0)){
if (pole[y] == 'L'){
left = y + 1;
break;
}
if (y == 0) {break;}
y--;
}
while(right == 0) {
if (pole[v] == 'R'){
right = v;
pozright = right;
right = l - right + 1;
}
if(v == l) {break;}
v++;
}
if (right > left){
printf("The last ant will fall down in %d seconds - started at %d\n", right - 1, pozright);
}else if (left > right){
printf("The last ant will fall down in %d seconds - started at %d\n", left - 1, left - 1);
}else{
int a, b;
for (int i = l / 2; i < l; i++){
if (pole[i] != '0'){
b = i;
break;
}
}
for(int i = (l / 2) - 1; i > 0; i-- ){
if (pole[i] != '0'){
a = i;
break;
}
}
printf("The last ant will fall down in %d seconds - started at %d and %d\n", right - 1, a, b);
}
return 0;
}