Go to diff to previous submission
#include <cstdio> int main(){ int len, ants, cnt, maxCesta, maxIndex, maxIndex2, help; char dir; bool dva; while(1){ maxCesta = cnt = maxIndex = maxIndex2 = help = 0; dva = false; if(scanf("%d %d\n", &len, &ants) != 2) return 0; int pole[len + 1]; for(int i = 0; i <= len; i++) pole[i] = 0; for(int i = 0; i < ants; i++){ scanf("%d %c\n", &help, &dir); dir == 'R' ? pole[help] = 1 : pole[help] = -1; if((maxCesta == (len - help)) && (dir == 'R')){ maxIndex2 = help; dva = true; } if((maxCesta < (len - help)) && (dir =='R')){ maxCesta = len - help; maxIndex = help; dva = false; } if((maxCesta == help) && (dir == 'l')){ maxIndex2 = help; dva = true; } if((maxCesta < help) && (dir == 'L')){ maxCesta = maxIndex = help; dva = false; } } switch(pole[maxIndex]){ case -1:{ for(int i = maxIndex; i >=0; i--){ if(pole[i] == 1) cnt++; } for(int i = maxIndex; i >=0 ; i--){ if(pole[i] != 0){ if(cnt == 0) maxIndex = i; cnt--; } } break; } case 1:{ for(int i = maxIndex; i <= len; i++){ if(pole[i] == -1) cnt++; } for(int i = maxIndex; i <= len ; i++){ if(pole[i] != 0){ if(cnt == 0) maxIndex = i; cnt--; } } break; } default:{break;} } if(dva){ cnt = 0; switch(pole[maxIndex2]){ case -1:{ for(int i = maxIndex2; i >=0; i--){ if(pole[i] == 1) cnt++; } for(int i = maxIndex2; i >=0 ; i--){ if(pole[i] != 0){ if(cnt == 0) maxIndex2 = i; cnt--; } } break; } case 1:{ for(int i = maxIndex2; i <= len; i++){ if(pole[i] == -1) cnt++; } for(int i = maxIndex2; i <= len ; i++){ if(pole[i] != 0){ if(cnt == 0) maxIndex2 = i; cnt--; } } break; } default:{break;} }} if(dva) printf("The last ant will fall down in %d seconds - started at %d and %d.\n", maxCesta, maxIndex < maxIndex2 ? maxIndex : maxIndex2, maxIndex < maxIndex2 ? maxIndex2 : maxIndex); else printf("The last ant will fall down in %d seconds - started at %d.\n", maxCesta, maxIndex); } return 0; }
--- c4.s1070.cteam037.ants.cpp.0.ants.cpp +++ c4.s1123.cteam037.ants.cpp.0.ants.cpp @@ -10,5 +10,5 @@ if(scanf("%d %d\n", &len, &ants) != 2) return 0; int pole[len + 1]; - for(int i = 0; i < len; i++) pole[i] = 0; + for(int i = 0; i <= len; i++) pole[i] = 0; for(int i = 0; i < ants; i++){ scanf("%d %c\n", &help, &dir);