Go to diff to previous submission
#include <iostream> #include <algorithm> #include <climits> using namespace std; int main(){ int length, ants, minR=INT_MAX, maxL=INT_MIN, pos, timeR, size=100000, lenR=0, lenL=0, medL, medR; char dir; int left[size]; int right[size]; bool wasRight=false, wasLeft=false; while(cin>> length >> ants) { for(int i=0; i<ants; i++) { cin >> pos >> dir; if(dir=='R') { wasRight=true; if(pos<minR) minR=pos; right[lenR]=pos; lenR++; } else { wasLeft=true; if(pos>maxL) maxL=pos; left[lenL]=pos; lenL++; } } timeR=length-minR; //cas if(wasLeft && !wasRight) { cout << "The last ant will fall down in " << maxL << " seconds - started at " << maxL << "." << endl; } else if(!wasLeft && wasRight) { cout << "The last ant will fall down in " << timeR << " seconds - started at " << minR << "." << endl; } else { if(timeR<maxL) { //cout << maxL << " " << minR << endl; sort(&left[0], &left[lenL]); if(lenL==0) medL=0; else if(!(lenL%2)) medL=(lenL/2)-1; else medL=lenL/2; cout << "The last ant will fall down in " << maxL << " seconds - started at " << left[medL] << "." << endl; } else if(timeR>maxL) { //cout << maxL << " " << minR << endl; sort(&right[0], &right[lenR]); if(lenR==0) medR=0; else if(!(lenR%2)) medR=lenR/2; else medR=lenR/2; cout << "The last ant will fall down in " << minR << " seconds - started at " << right[medR] << "." << endl; } else if(timeR==maxL) { //cout << maxL << " " << timeR << endl; sort(&left[0], &left[lenL]); sort(&right[0], &right[lenR]); if(lenL==0) medL=0; else if(!(lenL%2)) medL=(lenL/2)-1; else medL=lenL/2; if(lenR==0) medR=0; else if(!(lenR%2)) medR=lenR/2; else medR=lenR/2; cout << "The last ant will fall down in " << maxL << " seconds - started at " << left[medL] << " and " << right[medR] << "." << endl; } } lenL = lenR = 0; minR=INT_MAX; maxL=INT_MIN; wasLeft = wasRight = false; } return 0; }
--- c4.s1073.cteam042.ants.cpp.0.ants.cpp +++ c4.s1092.cteam042.ants.cpp.0.ants.cpp @@ -52,5 +52,5 @@ medL=0; else if(!(lenL%2)) - medL=((lenL-1)/2 + (lenL-1)/2 + 1)/2; + medL=(lenL/2)-1; else medL=lenL/2; @@ -80,5 +80,5 @@ medL=0; else if(!(lenL%2)) - medL=((lenL-1)/2 + (lenL-1)/2 + 1)/2; + medL=(lenL/2)-1; else medL=lenL/2;