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.s1005.cteam037.ants.cpp.0.ants.cpp +++ c4.s1070.cteam037.ants.cpp.0.ants.cpp @@ -2,16 +2,13 @@ int main(){ - int len, ants; + 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]; + int pole[len + 1]; for(int i = 0; i < len; i++) pole[i] = 0; - int maxCesta = 0; - int maxIndex = 0; - int maxIndex2 = 0; - int maxCesta2 = 0; - int help = 0; - char dir; - bool dva = false; for(int i = 0; i < ants; i++){ scanf("%d %c\n", &help, &dir); @@ -19,5 +16,4 @@ if((maxCesta == (len - help)) && (dir == 'R')){ - maxCesta2 = len - help; maxIndex2 = help; dva = true; @@ -27,8 +23,7 @@ maxIndex = help; dva = false; - //printf("MINDEX:%d\n", maxIndex); } if((maxCesta == help) && (dir == 'l')){ - maxCesta2 = maxIndex2 = help; + maxIndex2 = help; dva = true; } @@ -36,8 +31,6 @@ maxCesta = maxIndex = help; dva = false; - //printf("MINDEX:%d\n", maxIndex); } } - int cnt = 0; switch(pole[maxIndex]){ case -1:{ @@ -45,5 +38,4 @@ if(pole[i] == 1) cnt++; } - //printf("CNTa:%d\n", cnt); for(int i = maxIndex; i >=0 ; i--){ if(pole[i] != 0){ @@ -55,9 +47,8 @@ } case 1:{ - for(int i = maxIndex; i < len; i++){ + for(int i = maxIndex; i <= len; i++){ if(pole[i] == -1) cnt++; } - //printf("CNTb:%d\n", cnt); - for(int i = maxIndex; i < len ; i++){ + for(int i = maxIndex; i <= len ; i++){ if(pole[i] != 0){ if(cnt == 0) maxIndex = i; @@ -67,5 +58,5 @@ break; } - default:{printf("FUCK\n");break;} + default:{break;} } @@ -77,5 +68,4 @@ if(pole[i] == 1) cnt++; } - //printf("CNTa:%d\n", cnt); for(int i = maxIndex2; i >=0 ; i--){ if(pole[i] != 0){ @@ -87,9 +77,8 @@ } case 1:{ - for(int i = maxIndex2; i < len; i++){ + for(int i = maxIndex2; i <= len; i++){ if(pole[i] == -1) cnt++; } - //printf("CNTb:%d\n", cnt); - for(int i = maxIndex2; i < len ; i++){ + for(int i = maxIndex2; i <= len ; i++){ if(pole[i] != 0){ if(cnt == 0) maxIndex2 = i; @@ -99,5 +88,5 @@ break; } - default:{printf("FUCK\n");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);