Go to diff to previous submission
#include <cstdio> using namespace std; int main(void) { int count, length; while(scanf("%d%d\n", &length, &count) == 2) { int leftmost = -1, rightmost = -1; bool ants[100000]; for(int i = 0; i < 100000; ++i) ants[i] = false; int pos; char dir; int toLeft = 0; for(int a = 0; a < count; ++a) { scanf("%d %c\n", &pos, &dir); ants[pos] = true; if(dir == 'R' && (leftmost == -1 || pos < leftmost)) { leftmost = pos; } else if(dir == 'L' && (rightmost == -1 || pos > rightmost)) { rightmost = pos; } if(dir == 'L') ++toLeft; } int maxTime = 0; if(leftmost != -1) maxTime = length - leftmost; if(rightmost != -1 && rightmost > maxTime) maxTime = rightmost; printf("The last ant will fall down in %d seconds - started at ", maxTime); if(rightmost == length - leftmost) { int passed = 0; for(int a = 0; a <= length; ++a) { if(!ants[a]) continue; ++passed; if(passed == toLeft) { printf("%d and ", a); } else if(passed == toLeft + 1) { printf("%d", a); break; } } } else if(maxTime == length - leftmost) { int passed = 0; for(int a = 0; a <= length; ++a) { if(!ants[a]) continue; if(++passed == toLeft + 1) { printf("%d", a); break; } } } else { int passed = 0; for(int a = 0; a <= length; ++a) { if(!ants[a]) continue; if(++passed == toLeft) { printf("%d", a); break; } } } printf(".\n"); } return 0; }
--- c4.s1241.cteam025.ants.cpp.0.ants.cpp +++ c4.s1262.cteam025.ants.cpp.0.ants.cpp @@ -38,5 +38,5 @@ if(rightmost == length - leftmost) { int passed = 0; - for(int a = 0; a < length; ++a) { + for(int a = 0; a <= length; ++a) { if(!ants[a]) continue; ++passed; @@ -53,5 +53,5 @@ else if(maxTime == length - leftmost) { int passed = 0; - for(int a = 0; a < length; ++a) { + for(int a = 0; a <= length; ++a) { if(!ants[a]) continue; if(++passed == toLeft + 1) { @@ -63,5 +63,5 @@ else { int passed = 0; - for(int a = 0; a < length; ++a) { + for(int a = 0; a <= length; ++a) { if(!ants[a]) continue; if(++passed == toLeft) {