|
|
back to boardMLE #7? Hi I got MLE #7. Why?
#include <cstdio> #include <algorithm> int a[250000]; int main() { int n; std::scanf("%d", &n); for (int i = 0; i < n; i++) std::scanf("%d", a + i); if (n % 2) { std::nth_element(a, a + n / 2, a + n); std::printf("%d\n", a[n / 2]); } else { std::nth_element(a, a + n / 2, a + n); std::nth_element(a, a + n / 2 - 1, a + n); std::printf("%.1f\n", (a[n / 2] + .0 + a[n / 2 - 1]) / 2); } return 0; }
Re: MLE #7? >int a[250000]; Empty helloworld already shows 100+ kb, so 250000 is not an option. The only way is to use ~200000 or so numbers. Re: MLE #7? So why I don't have MLE #1? Re: MLE #7? Because first 6 tests have a small N, and thus most of this array isn't initialized and used. Try to fill your array with random numbers in the beginning of your main() and you'll have MLE #1. Re: MLE #7? By the way. std::nth_element(a, a + n / 2, a + n); // (1) std::nth_element(a, a + n / 2 - 1, a + n); // (2) Are you sure it must work? I suppose value found on step 1 can be moved on step 2. |
|
|