Блог пользователя Geothermal

Автор Geothermal, история, 6 лет назад, По-английски

Hi all!

Since nobody has posted about the round yet, I thought I'd open up a page to discuss GCJ Round 1A, which happened earlier this evening.

The scoreboard, problems, and editorials are available at this link. Practice mode should be open now--I'd recommend trying the problems if you didn't compete, since I thought they were generally pretty nice.

It looks like everyone with a score greater than 63 or with a score of 63 and a penalty time no greater than 2:14:05 qualifies for Round 2, assuming that nobody gets removed from the scoreboard later on. Everyone else can attempt to qualify through Rounds 1B and 1C, even if they participated in this contest but failed to qualify.

If nobody posts solutions here within the nearish future, I'll write up and share mine, but as far as I can tell, my ideas were pretty much identical to the ones explained in the official editorials.

  • Проголосовать: нравится
  • +75
  • Проголосовать: не нравится

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +7 Проголосовать: не нравится

Regretting for not getting selected within top 1500 . I solved first one fully and 2nd one for 2 test cases. My approach for 1st was fairly simple.

  • »
    »
    6 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +3 Проголосовать: не нравится

    what was your approach?

    • »
      »
      »
      6 лет назад, скрыть # ^ |
      Rev. 2  
      Проголосовать: нравится +5 Проголосовать: не нравится

      Step 1:- Select the prefix of all strings just before first *

      Step 2:- Select the suffix of all strings after last * an d store both these values in 2 new vectors

      Step 3:- Ok and store the string leaving prefix and suffix in the main part known as stem Cool…

      Step:- 4Now one thing only you need to check is that among the selected prefixes select the maximum length prefix and maximum length suffix answer it yourself why?

      Step:- 5Then after selecting maximum length prefix then match it with all other prefixes if all prefixes are a prefix of this selected string then Ok otherwise there doesn’t exist any word satisfying above strings

      Step 6:- And after maximum suffix check that all other suffixes are a part of the suffix of this string

      cool…

      Step 7:- And than after that for the main part(leaving prefix and suffix of any string ) append main part of all the strings after the maximum length prefix in the answer(ans string) and after appending maximum length prefix append all main parts and after that append maximum length suffix

      Step 8:- And output the answer string By substituting each * with any letter between A to Z as * can be anything so I assumed it common for all the strings

      Hope it makes it clear Submit and get the AC.

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +16 Проголосовать: не нравится

Am I the only one that misread problem C statement as if dancer X get removed if there is any compass dancer that has higher number than dancer X's power? I realized that I solved the wrong problem after testing the 4th sample and after a 30 minutes implementation and felt really bad the moment I realized it.

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +10 Проголосовать: не нравится

Here's the substance of my code for each of the problems:

Task A

Task B

Task C

All of these felt reasonably concise to me, but the ideas, of course, may be somewhat difficult to interpret from the code alone. If people still have questions about the problems after taking a look through these and the editorials, I can write up my solution ideas at some point later on.

»
6 лет назад, скрыть # |
Rev. 3  
Проголосовать: нравится +10 Проголосовать: не нравится

I think this was a fairly easier 1A compared to previous years (?), with all 3 of the problems being somewhat ad-hoc. In problem 2, the binary expansion observation was cute.

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Any way to filter rankings ,countrywise??

»
6 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится -19 Проголосовать: не нравится

How to prepare for round 2? Is topcoder good for it?

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +11 Проголосовать: не нравится

I just notice At least one character of Pi is an asterisk (*), for all i.

Because that I write unused and messy code for special case..

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Hi, can anyone help me explaining why am I getting MLE in this solution for B with final constraint ( N<= 1e+9):

https://ideone.com/N7miy1

Thanks in advance!

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

How to solve First Problem ?

  • »
    »
    6 лет назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится 0 Проголосовать: не нравится

    Go from left to right until you find the first * for all strings. Find a string which satisfy all strings from left to right until the first *. Let that be head of the resultant string. Do the same from right to left until you encounter first *. Find such a string which satisfy all the strings. Let that be the tail of the resultant string. You have head and tail, now take the leftover characters except * from left to right in any order after the first * and before the last *, and add them to your resultant string in between the head and tail.

    My Accepted Code: https://ideone.com/6Mn8b6

  • »
    »
    6 лет назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится 0 Проголосовать: не нравится

    What I did was store all the substrings before the first '*' in pref[n] and all the substrings after the last '*' in suff[n]. Also store all characters between first star and last star(if exists) for all strings in a single string "mid".

    sort pref[n] and suff[n] in decreasing order of length . Then check if all strings in pref is a prefix of pref[0] (largest string). Similarily all string in suff should be suffix of suff[0]. A bool variable stores if its true or false.

    If its false print '*' and if its true print "pref[0] + mid + suff[0]".

    There probably is an easier way to do this, if anyone finds their solution easier, please do share

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +8 Проголосовать: не нравится

Is there any way to give past GCJ rounds as a virtual participant?

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Please tell whether my approach was correct or wrong

Approach

Please tell me If I am wrong somewhere. I got Runtime error and passed first 2 test sets Thanks and regards

»
6 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится +104 Проголосовать: не нравится

I totally missed both approaches the editorial mentioned for Pascal Walk, and spent 45 minutes just flailing around. But in the end I actually came up with a different solution that is very efficient (and has a neat twist):

Start with the path going SW, SE, SW, SE, SW, SE, ... until you're just about to exceed N. Now, you can also easily add the numbers to the E, W, E, W of your choices to the path (the ones fitting into the crooks of the diagonal path). You now have a set of "optional" numbers 1, 1, 3, 4, 10, 15, 35, 56, ... (these are a path of knight's moves down Pascal's Triangle). Now you can probably fill in the rest of N by picking the correct set of these optional numbers — ie, you could solve the rest as a knapsack problem. But here's the surprise: the first 2k of these numbers always sums to exactly 1 less than the (2k+1)th number. So these numbers are just close enough for knapsack to work, and furthermore you can just solve it greedily, always choosing the largest value less than the remaining count!

These generated paths end up very short, using fewer than 64 steps for any N <= 10^9 (well below the limit of 500).

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +23 Проголосовать: не нравится

Another approach for B which might be interesting.

Let's consider only paths that go south (down) at least once in every two steps. Now for every cell let's denote by $$$a$$$ and $$$b$$$ the minimum and maximum value of a path of this type that end in that cell. The main observation is that for all $$$a$$$ $$$\leq$$$ $$$c$$$ $$$\leq$$$ $$$b$$$ there exists a path (again of this type) with value $$$c$$$ that ends in that cell.

Well then we can simply find these min and max values with DP and then get some random cell with $$$a$$$ $$$\leq$$$ $$$N$$$ $$$\leq$$$ $$$b$$$. Recovering the actual path is also trivial by adding the cells in reverse.

  • »
    »
    6 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +5 Проголосовать: не нравится

    I had a similar approach. I assumed path will be as follows: going through the horizontal row, then going down, then going through the horizontal row in opposite direction and so on. I also allowed each cell to have previous path cell from the left or right, and from the above row.

    In this approach each cell represents not a continuous range of values that could be achieved there, but rather a union of several continuous ranges. I maintained these unions for 30 rows of triangle, and checked that they all together cover all numbers from $$$1$$$ to $$$10^9$$$. Then similar style recovering of the answer.

»
6 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

I tried to code Task C. But not able to find where it is wrong... can anyone help with testcase...... https://ideone.com/3qyGdY

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can anyone see why I get TLE on C ? https://ideone.com/3ayUAK

I tried many random cases, non of them failed .. Thanks ..

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I got MLE error in final test case of problem 2. I used the sum of numbers from 1 to n and then adding 1 for the remaining sum to make it n. Please tell me what is wrong in this approach.

»
6 лет назад, скрыть # |
Rev. 3  
Проголосовать: нравится 0 Проголосовать: не нравится

Concerning problem B, I've got a rather ad-hoc solution:

Let's define a parameter z for our Pascal walk. That corresponds to the following:

  1. The first z positions are of the form (1, 1), (2, 1), ..., (z, 1)

  2. We move diagonally right (that is, increasing both r and k by 1, as long as we don't overstep n)

  3. If we cannot make an additional move, increase only k (our subsequent diagonal will have smaller values then), and return to step 2.

Smaller values of z correspond to smaller values in the Pascal triangle (and so more suitable for small inputs), and larger values of z — to larger values of our walk. However, this is not a linear dependence, so I check all values of z from 1 to 16 (I'm sure there is a lower limit for the given constraints, but it isn't that important).

There is a small detail — we must check somehow that we haven't overstepped the limit of queries during our algorithm. For example, if the input is large and z = 1, the algorithm will continuously walk along the rightmost diagonal, which might or might not cause RE (out-of-bounds access). When I tested locally, the values outside of the array were large garbage numbers, and so everything was okay. But when run on the GCJ system, I got RE on the hidden test set and so didn't pass on to Round 2 yet :P

(It is also possible to loop backwards, from 16 to 1, that also gets AC).

Code: https://pastebin.com/G0zSvQ4r

»
6 лет назад, скрыть # |
 
Проголосовать: нравится -16 Проголосовать: не нравится

Anyone tried Problem 1 using dp pattern matching? After I made the function that return the string that is gets matched with 2 strings, how to find such string that satisfied all the input string?

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Hey guys, anyone can help checking my code for Square Dance here? Getting WA for both test set, working fine on Sample and my own random cases.

https://ideone.com/yDdiMS

Is it possible to get the WA test case from the judge in practice mode btw?

»
6 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

Resolved.

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

interesting that problem C hard was worth 28 points... it seems so straightforward.

»
6 лет назад, скрыть # |
 
Проголосовать: нравится -6 Проголосовать: не нравится

My approach for problem 1C Square Dance:

Link to my approach

I am getting TLE on 2nd test set. Someone please help me as I had spent around 3 hrs on this question. Time complexity seems fine to me. If any clarification in my code is needed then please comment.

Thanks in advance!!