Show all threads Hide all threads Show all messages Hide all messages |
I've tried everything but still MLE | achvanov | 1306. Sequence Median | 9 Sep 2019 22:16 | 2 |
I've tried priority_queue and heap, but still MLE. Here's my code, can somebody help me? #include <iostream> #include <algorithm> #include <vector> int main() { int n, a; std::cin >> n; std::vector<int> v(n / 2 + 1); for (int i = 0; i < n / 2 + 1; ++i) { std::cin >> v[i]; } std::make_heap(v.begin(), v.end()); for (int i = 0; i < (n + 1) / 2 - 1; ++i) { std::cin >> a; v.push_back(a); std::push_heap(v.begin(), v.end()); std::pop_heap(v.begin(), v.end()); v.pop_back(); } std::sort_heap(v.begin(), v.end()); if (n % 2) { std::cout << v.back() << ".0"; } else { a = v.back(); v.pop_back(); std::cout << (0ll + a + v.back()) / 2 << '.'; if ((0ll + a + v.back()) % 2) { std::cout << 5; } else { std::cout << 0; } }
return 0; } It's wrong. Because the last leaf of the max heap is not necessarily minimum but you are removing it (v.pop_back();). Your code may remove the median element. And the sort_heap has no effect. |
Hint | Skeef79 | 1645. Ski Race | 9 Sep 2019 21:59 | 1 |
Hint Skeef79 9 Sep 2019 21:59 Count numbers bigger than a[i] from 0..i-1 ans smaller than a[i] from i+1..n-1 ans then try to build the answer :) |
Difficulty | Skeef79 | 1645. Ski Race | 9 Sep 2019 21:58 | 1 |
It is around 70 Edited by author 09.09.2019 22:01 |
C: murder. Help please | Georg | 1001. Reverse Root | 8 Sep 2019 11:20 | 2 |
[code deleted] Edited by author 08.09.2019 10:26 Edited by moderator 19.11.2019 23:32 Решил с грехом пополам, здесь писать не буду. Остались сомнения, что в условии(в тестах) правильно размер массива подсчитан, этот(SIZE) не катит. |
What to do? | bsu.mmf.team | 1890. Money out of Thin Air | 7 Sep 2019 22:32 | 2 |
OMG, standart interval tree gives TLE 6. It's terrible! Why?! Use Segment Trees with lazy propagation |
AC | qwertyqwe | 1124. Mosaic | 7 Sep 2019 13:54 | 1 |
AC qwertyqwe 7 Sep 2019 13:54 Please, could you send your problem(AC code) |
need some test cases please | anupam ghosh | 1960. Palindromes and Super Abilities | 7 Sep 2019 06:29 | 1 |
|
AC | qwertyqwe | 1101. Robot in the Field | 6 Sep 2019 23:30 | 1 |
AC qwertyqwe 6 Sep 2019 23:30 Please, could you send your problem(AC code) |
a | Dan | 1457. Heating Main | 6 Sep 2019 18:38 | 1 |
Edited by author 09.09.2019 23:30 |
Is the answer of second sample impossible? | Beqa Lomitashvili [Freeuni] | 1549. Another Japanese Puzzle | 6 Sep 2019 00:05 | 2 |
49 3 I mean, FRRR or FLLL or FLFLLF could return us to the base, it also doesn't violate any of two rules: 1. The total number of letters F must not exceed S and 2. the total number of letters L and R must not exceed T are there any more restrictions??? The problem asks: "What is the longest closed path that you can assemble?" Your examples are not closed loops. The first and last squares, although they are neighbours, they don't match their path endings. |
what's wrong??? C++ | inctnce | 1787. Turn for MEGA | 5 Sep 2019 23:55 | 1 |
#include <iostream> using namespace std; int main() {
int n, k; cin >> n >> k; int c = n * k; int *arr = new int[k];
for (int i = 0; i < k; i++) { cin >> arr[i]; c = c - arr[i]; }
cout << abs(c);
} |
WA 4 | M@STeR.SoBG | 1303. Minimal Coverage | 5 Sep 2019 14:45 | 9 |
WA 4 M@STeR.SoBG 15 Apr 2008 14:24 Could anybody help me? I have WA at 4th test! Re: WA 4 Vladimir Plyashkun [CSU] 3 May 2012 00:53 u may try this test: 2 1 2 0 1 0 0 so output should be: 2 0 1 1 2 when WA is 2 1 2 0 1 Re: WA 4 Smilodon_am [Obninsk INPE] 18 Sep 2012 21:54 This test helped me: 4 0 4 -5 0 3 4 -4 4 0 0 Answer is: 1 -4 4 Is the answer : 1 0 4 right? i have wa 4 too,and i am confused about the output principles. Re: WA 4 Marin Shalamanov 30 Jan 2013 21:37 This test helped me: 10 -5 1 1 14 -5 2 2 3 3 19 0 0 The answer is: 2 -5 1 1 14 Now, let's fight with WA5 :D why not this: 2 -5 2 1 14 ? Actually, what if there are several possibilites to cover? I think that it does not matter which one you choose, as long as it has a minimum number of intervals. I guess the judge just tests whether the intervals you give cover the large interval. Best regards, Erik Edited by author 25.02.2013 04:56 This test helped me too. At last got AC. My solution is similar to task 1987. Edited by author 05.09.2019 16:47 |
Proof of the result? (+) | Vedernikoff Sergey (HSE: АОП) | 1714. Mnemonics and Palindromes 2 | 5 Sep 2019 04:11 | 2 |
Ok, I've found relation between n and maximin palindrome number and several optimal patterns that depend on n mod 12. Only one question has left: how to prove all this stuff? My AC solution is using n mod 6 to determine the optimal solution. The proof is rather complicated and heavily relies on some particular pattern of length 6. Apart from that, it's just analysing lots and lots of cases. |
Cameras on starting and finish line | espr1t | 1990. Podracing | 5 Sep 2019 01:27 | 2 |
How to treat cameras, located on the starting and/or finish line? Do racers interact with them? My AC solution treats those cameras as if they interact with the racers. |
Hint For Test Case# 16 | Yuv | 1423. String Tale | 4 Sep 2019 10:49 | 2 |
Cannot break this case. Any hint? Ok I don't know what was the case# 16. But I have found some test cases: 9 abghxrfab rfabghxrf ans: -1 9 abghxabab ababghxab ans: 2 12 abcghxabcabc cabcghxabcab ans: 1 |
Algo. Hints. | IgorKoval(from Pskov) | 1894. Non-Flying Weather | 3 Sep 2019 16:47 | 4 |
What is algorithm? What formulas, theorems, equations and hints must I use? Thx Really, if we can find A-B then we must understand that [0,0] belong to A-B or not If 'yes' then answer = max{0, dist([0,0], A-B) - 60} If 'no' then answer = 0 |
Getting wrong answer for test case #3 | Aakanksha Sharma | 1146. Maximum Sum | 3 Sep 2019 16:44 | 1 |
My code is as following: #include<iostream> #include<vector> using namespace std; long getMaxSumRow(long rowArr[], int n) { long cs = 0; long ms = 0; bool positiveNumberPresent = false; for (int i = 0; i < n; i++) { if (!positiveNumberPresent && (rowArr[i] >= 0)) { positiveNumberPresent = true; } cs += rowArr[i]; if (cs < 0) { cs = 0; continue; } if (cs > ms) { ms = cs; } } if (positiveNumberPresent) { return ms; } ms = rowArr[0]; for (int i = 0; i < n; i++) { if (rowArr[i] > ms) { ms = rowArr[i]; } } return ms; } long maxSumRec(vector<vector<long> > &arr, int n) { if (n == 1) { return arr[0][0]; } /* Take an array for running rows sum */ long runningRowSum[n]; for (int r = 0; r < n; r++) { runningRowSum[r] = 0; } long maxSum = INT_MIN; /* Initialize variables for left-right and top-bottom bounds */ int left, right, top = 0, bottom = n-1; /* Iterate from all possible lefts to all possibe rights ahead of this left */ for (left = 0; left < n; left++) { for (right = 0; right < n; right++) { for (top = 0; top <= bottom; top++) { runningRowSum[top] += arr[top][right]; } /* For this left-right combination, calculate contigeous subarray with maximum sum in runningRowSum */ long currSum = getMaxSumRow(runningRowSum, n); if (currSum > maxSum) { maxSum = currSum; } } /* Reinitialize running row sum to 0 */ for (int r = 0; r < n; r++) { runningRowSum[r] = 0; } } return maxSum; } int main() { int n; cin >> n; vector<vector<long> > arr(n); for (int i = 0; i < n; i++) { arr[i] = vector<long>(n); for (int j = 0; j < n; j++) { cin >> arr[i][j]; } } cout << maxSumRec(arr, n); return 0; } But I am getting wrong answer for test case#3 . Any advice on what it might be failing at ? |
TEST | buyolitsez | 1156. Two Rounds | 3 Sep 2019 09:22 | 1 |
TEST buyolitsez 3 Sep 2019 09:22 3 4 1 2 1 3 4 5 4 6 ans: 1 5 6 2 3 4 Edited by author 03.09.2019 09:23 |
no impossible case | sonamon | 1106. Two Teams | 28 Aug 2019 23:42 | 2 |
There cannot be any impossible case as is suggested by the very first line of the problem statement yes , no impossible cases are present. |
The main task is 10^250 | Михаил | 1180. Stone Game | 26 Aug 2019 16:18 | 1 |
|