Latest PCS Online Judge Commentshttps://pcs.org.au/2020-01-06T14:27:50.504098+00:00The latest comments on the PCS Online Judge websiteManstie -> Gozz's Prank2020-01-06T14:27:50.504098+00:002020-01-06T14:27:50.504098+00:00https://pcs.org.au/problem/gozzprank#comment-30<p>I spent way too much time on this.</p> Manstie -> PCS Standard Contest 92019-08-28T14:51:08.636147+00:002019-08-28T14:51:08.636147+00:00https://pcs.org.au/contest/standardpcs9#comment-29<p>Yay I did one...</p> Ccamm -> Editorial for Cutting Cake2019-03-13T14:15:32.389469+00:002019-03-13T14:15:32.389469+00:00https://pcs.org.au/problem/cuttingcake/editorial#comment-28<p>Any advice on making this answer even shorter?</p> <pre><code>for test in [list(map(int, l.split())) for l in stdin.read().split('\n')[1:-1]]: print(math.pi*(math.pow(test,2)-1/4*math.pow(test,2)))</code></pre> emma -> Editorial for Sharing Chocolate2018-12-01T07:09:08.315409+00:002018-12-01T07:09:08.315409+00:00https://pcs.org.au/problem/sharingchocolate/editorial#comment-26<p>Thank you, it worked!</p> maxward -> Editorial for Sharing Chocolate2018-12-01T00:43:11.105315+00:002018-12-01T00:43:11.105315+00:00https://pcs.org.au/problem/sharingchocolate/editorial#comment-24<p>The reason your solution is getting TLE is because it uses slow I/O methods. Read the discussion here: <a href="https://pcs.ucc.asn.au/problem/aplusb" rel="nofollow">https://pcs.ucc.asn.au/problem/aplusb</a></p> emma -> Editorial for Sharing Chocolate2018-11-30T15:26:08.954809+00:002018-11-30T15:26:08.954809+00:00https://pcs.org.au/problem/sharingchocolate/editorial#comment-23<p>clever! After reading the editorial, I've changed my program according to your solution yet I still get TLE error using c++, why would that be?</p> <p>the generating part</p> <p>" ...</p> <pre><code>n=1000001; for (i=2; i&lt;=n; i++) { for (j=i; j&lt;=n; j+=i) tot[j]++; }</code></pre> <p>.. "</p> emma -> Multiples2018-11-22T16:28:30.762493+00:002018-11-22T16:28:30.762493+00:00https://pcs.org.au/problem/multiples#comment-22<p>"If there is no valid multiple, display -1" shouldn't test(99 1) have -1 output vs. 0 in the sample output?</p> <p>EDIT: apparently, zero is a multiple of every integer</p> max -> GCD Queries2018-11-10T03:29:08.256265+00:002018-11-10T03:29:08.256265+00:00https://pcs.org.au/problem/gcdqueries#comment-21<p><strong>No judge available</strong></p> <p>I am getting a message saying, "No judge is available for this problem" when I go to submit my solution.</p> <p>Edit: All fixed now! Thanks!</p> Tommoa -> Purple Lights2018-08-30T13:52:22.853479+00:002018-08-30T13:52:22.853479+00:00https://pcs.org.au/problem/purplelights#comment-20<p>I can't see any problem with the sample input/output. I'll quickly go through it line by line:</p> <pre><code>2</code></pre> <p>This is $$t$$. This means that the number of test cases is two.</p> <pre><code>2 10 20 20 10</code></pre> <p>This is the first sample test case. The two at the top ($$n$$) indicates the number of lines that follow. Each row below that has $$b_i$$ and $$r_i$$.</p> <pre><code>3 4 0 0 1 0 1</code></pre> <p>This is second sample test case. Here we can see that $$n$$ is $$3$$, and as such there are three lines following it, each containing $$b_i$$ and $$r_i$$.</p> Milker88 -> Purple Lights2018-08-30T04:41:30.093173+00:002018-08-30T04:41:30.093173+00:00https://pcs.org.au/problem/purplelights#comment-19<p>I'm confused. It says n is 3 in the sample input but there are 4 lines following the 3. Help plz.</p> Levi -> Minutemen2018-06-04T14:18:30.895562+00:002018-06-04T14:18:30.895562+00:00https://pcs.org.au/problem/minutemen#comment-18<p>Nvm got it</p> Levi -> Minutemen2018-06-04T12:36:13.688479+00:002018-06-04T12:36:13.688479+00:00https://pcs.org.au/problem/minutemen#comment-17<p>Any hints as to why my incredibly fragile code is failing the last test case? ( ͡ಥ ͜ʖ ͡ಥ)</p> maxward -> Editorial for Removal Sorting2018-03-30T07:10:58.218441+00:002018-03-30T07:10:58.218441+00:00https://pcs.org.au/problem/removalsorting/editorial#comment-16<p>Nice solution, and thanks for sharing!</p> <p>I came up with something very similar when writing this question. However, it is a little different in some ways. I think yours is a bit more elegant, but I will share mine anyway.</p> <p>We can keep two monotonically increasing pointers. One into $$A$$, and one into $$D$$. Say that the pointer into $$A$$ points to $$A_i$$, and $$A_{i+1}$$ is the first not-deleted element to its right. Also, say that the current pointer into $$D$$ points to $$D_j$$. While $$A_i$$ is in order ($$A_{i} \leq A_{i+1}$$), increment $$i$$. If it is not in order, delete the element at $$D_j$$, then increment $$j$$. Keep doing this until $$A_i$$ is in order again. Once $$i = |A|-1$$, we've found the solution: it is just $$j$$. We can do all of this using the same doubly linked list method explained well above.</p> <p>This is also $$O(n)$$ using a similar complexity analysis as above.</p> 1021839 -> Editorial for Removal Sorting2018-03-30T04:38:22.186697+00:002018-03-30T04:38:22.186697+00:00https://pcs.org.au/problem/removalsorting/editorial#comment-15<p>There is an $$O(n)$$ solution to this question, which is worth mentioning because it's interesting (and the solution method we used in contest.)</p> <p>Let's define the <em>partial inversion count</em> of an array as the number of pairs of adjacent elements that are in the wrong order for it to be sorted. For instance, the partial inversion count of <code>[2, 1, 4, 3]</code> would be 2, since the adjacent pairs <code>(2, 1)</code> and <code>(4, 3)</code> are in the wrong order. Clearly we can compute the partial inversion count of any array in $$O(n)$$, and we can compute it for the array $$A$$ at the start.</p> <p>We make the following observation: an array is sorted iff the partial inversion count of the array is zero, since this means that all pairs of adjacent elements are sorted, and therefore the overall array is sorted.</p> <p>Now, we process deletions as they come. For each index that we wish to delete, we want to maintain any changes in the partial inversion count as a result of this deletion. For instance, suppose that the array is currently <code>[5, 1, 2, _, 4, 3, 6, 7]</code> and we wish to delete the element at index 4. Our partial inversion count is currently 2.</p> <p>We note that deleting an element will only change any of the pairs of adjacent elements that contain this element, i.e. all of the other pairs will be unaffected. For instance, the deletion of index 4 from the above array will only have the following effects:</p> <ul> <li>the pair <code>(2, 4)</code> of adjacent elements no longer exists (since the element 4 is no longer in the array)</li> <li>the pair <code>(4, 3)</code> of adjacent elements no longer exists</li> <li><code>(2, 3)</code> is now a pair of adjacent elements.</li> </ul> <p>So, the first two pairs will no longer contribute to the partial inversion count, and the last pair will begin to contribute to the partial inversion count. Thus, we decrement the partial inversion count if the first pair was out of order, and decrement if the second pair was out of order; then, we increment if the third pair was out of order. Therefore we can handle element deletions and the changes to the partial inversion count in $$O(1)$$ per deletion, and check after each deletion if the partial inversion count is 0 (at which point the array is sorted, and we are done).</p> <p>Note that we have not yet described the method with which we determine the first undeleted element before and after the element which we wish to delete. For instance, in the above example, we need to be able to determine the first element still in the array before and after index 4. We can do this by maintaining a <em>doubly linked list</em>, in which we store, for each element, the closest element before which is undeleted, and the closest element after which is undeleted. Let's suppose that we store these in arrays named <code>prev</code> and <code>next</code>, where <code>prev[i]</code> is the index of the first undeleted element before index <code>i</code>, and similarly for <code>next[i]</code>. Deleting index <code>i</code> can be performed in the following way:</p> <pre><code>prev[next[i]] = prev[i] next[prev[i]] = next[i]</code></pre> <p>(If you look over that a few times, you should be able to understand intuitively why it works.) Note that special considerations must be made for the first and last undeleted elements in the array.</p> <p>Maintaining the doubly linked list clearly only takes $$O(1)$$ operations for each deletion, and we can look up the previous and next elements in the array which are still in the array in $$O(1)$$ by a simple lookup in <code>prev</code> and <code>next</code>, so each deletion takes overall $$O(1) + O(1) + O(1) = O(1)$$ time. We process at most $$n$$ deletions, so overall our complexity for handling deletions is $$O(1) \cdot O(n) = O(n)$$. We add to this the complexity of the initial calculation of the partial inversion count, which is $$O(n)$$, so overall the complexity is $$O(n) + O(n) = O(n)$$.</p> maxward -> Gozz's Prank2018-03-06T01:22:35.860020+00:002018-03-06T01:22:35.860020+00:00https://pcs.org.au/problem/gozzprank#comment-14<p>The statement has been updated!</p> TheoVickery -> Gozz's Prank2018-03-04T04:16:57.258632+00:002018-03-04T04:16:57.258632+00:00https://pcs.org.au/problem/gozzprank#comment-13<p>Would you count [1,2,2,4] as an Ascending Sorted Array? Or are repeated elements not allowed?</p> mvhv -> A plus B2018-01-01T05:39:44.276771+00:002018-01-01T05:39:44.276771+00:00https://pcs.org.au/problem/aplusb#comment-12<p>Ha, that's fantastic! I knew you can overload std::function::operator() to create first-class functions, but I never really considered how Python functions are obviously first-class by definition.</p> 1021839 -> A plus B2017-12-27T08:13:03.932575+00:002017-12-27T08:13:03.932575+00:00https://pcs.org.au/problem/aplusb#comment-11<p>I suppose you could take advantage of the fact that Python functions are first-class objects:</p> <pre><code>for i in[input]*int(input()):print(sum(map(int,i().split())))</code></pre> gozzarda -> A plus B2017-08-14T05:23:19.623404+00:002017-08-14T05:23:19.623404+00:00https://pcs.org.au/problem/aplusb#comment-10<p>A couple of minutes in Haskell gets me this:</p> <pre><code>main=interact\$unlines.map(show.sum.(map read).words).tail.lines</code></pre> <p>Forgive the lack of whitespace. Readable Haskell would have between 4 and 16 extra spaces depending on your tastes.</p> mvhv -> A plus B2017-08-13T19:53:21.524202+00:002017-08-13T19:53:21.524202+00:00https://pcs.org.au/problem/aplusb#comment-9<p>I spent far too long trying to cram this into one gross line.</p> <p><code>for _ in range(int(input())): print(sum(map(int, input().split())))</code></p> <p>Can anything think of something shorter? I feel like this could be much worse but I/O makes it hard to obfuscate.</p> mvhv -> Standard PCS Contest 12017-08-03T07:16:21.037738+00:002017-08-03T07:16:21.037738+00:00https://pcs.org.au/contest/standardpcs1#comment-8<p>I think the time limit is 1 second per-test-case, and the times shown on the submissions page are the total time the solution took to complete all ~10 test cases.</p> lymiah -> Standard PCS Contest 12017-08-03T07:11:10.643455+00:002017-08-03T07:11:10.643455+00:00https://pcs.org.au/contest/standardpcs1#comment-7<p>For the Stacking Cows problem, the time limit says 1 second but the best submitted answers take longer than 1 second.</p> maxward -> A plus B2017-08-03T06:57:26.796938+00:002017-08-03T06:57:26.796938+00:00https://pcs.org.au/problem/aplusb#comment-6<p>It is because you are using endl, which causes a buffer flush, and thus is variable.</p> lymiah -> A plus B2017-08-02T22:45:10.373813+00:002017-08-02T22:45:10.373813+00:00https://pcs.org.au/problem/aplusb#comment-5<p>The time seems to vary quite a lot between runs. Something I posted took about a second, then I resubmitted the same code later and it took about 4 seconds..</p> Tommoa -> A plus B2017-07-27T07:17:57.679396+00:002017-07-27T07:17:57.679396+00:00https://pcs.org.au/problem/aplusb#comment-4<p>Awesome, I'll make sure to use it in the future then. Thanks</p>