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

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

I couldn't find a blog post about Round 1C. So let's discuss the solutions! :)

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

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

Auto comment: topic has been updated by adhoc_king (previous revision, new revision, compare).

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

At the end of the contest my submissions for problem "Power Arrangers" were being checked for quite long time and were getting TLE verdict. But I am sure that my latest solutions work in the given time limit(they do approximately $$$50*5*5!=30000$$$ operations, which should certainly fit in the time limit, also it works OK on my computer). Can it be some technical issue? Has anyone else had similiar issues?

UPD: As Adhami told, my solution was wrong and should get WA. But because I didn't handle 'N' I got TLE.

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

    Did you handle "N"?

    If you didn't terminate the program after reading "N" you will get TLE.

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

      No, I did not.

      I'll check if it is the problem in the practice mode. Thanks for your help.

      UPD: Yes, you were right. I changed my solution so that it terminates after reading 'N', and it got WA.

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

      But even if it is a TLE without handling N, it does not guarantee the correctness of solution even if you handle 'N'. If your solution is correct you don't need to handle 'N'.

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

        Yes, TLE in GCJ interactive problems are misleading. Most of TLEs are actually wrong answers not an actual TLE. None of TLEs are AC, since "N" is only sent if the solution did something wrong.

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

        Maybe my solution was wrong(though it worked on many random test cases on my computer) and should get WA. But because I didn't handle 'N' I got TLE.

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

    I couldn't get the interaction working, my C++ code TLE's both with the provided local grader and on the server. If somebody has a working C++ code, I would like to see it.

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

Solving easy — 20 min
Solving hard — 20 min
Solving med — 20 min
Figuring out how tf do I use these stupid interactive runnners and testers and noting that judge returns "Y" or "N", not "1" and "0" — 30 min

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

    I can't manage to make the script provided to work. Can some explain that ;-; ?

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

      You have to use the interactive_runner.py as mentioned in the problem too. You have to run it as

      python interactive_runner.py python testing_tool.py 0 -- your_binary

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

    I can't make interactive runner work if the solution is Python, does anyone have an idea?

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

    I dropped their runners as soon as I took a glance at it.

    It turned way too easier to test and debug a solution with a handwritten runner, with using a bit of OOP. You would just change a line in the code before sending the solution. I guess it saved me a real amount of time. It looked like this — https://gist.github.com/Izaron/b5ccd047d69d315d005557791bdea9ca

    (But anyway I've got 2 TLE because of printing "Case #" and not reading F)

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

    Haha, true!

    Luckily, there's a reminder on how to run it in the comments in interactive_runner.py, right at the top.

    P.S: Congrats on making it into top50!

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

    40 min for me

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

I must say I was very excited when I first read problem 2: "interactive problem, answer chosen uniformly at random? Must be some clever and cool elegant solution!".

Then I noticed that 119 + 23 + 5 + 1 < 150.

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

I got TLE in B because I was reading F for each testcase, maybe that helps some of you

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

    Also don't print "Case" stuff and read a char after printing the answer, maybe that helps some of you

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

    Same. Was able to debug this just 3/4minutes after the end.

    Rank would have been around ~1K. :|

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

Bonjour everyone! ;(

Can someone please help me with the first problem :(

I got a WA but i am missing some corner case maybe.

My solution is similar to the one in editorial.

Thanks in advance!

Code = https://ideone.com/hq1PC9

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

    So I am ruling out 2 cases before creating the string and they are:

    1: When the count of unique characters in an index i for all the strings is not 1 for any index then answer is impossible. 2: If this index whose count is 1 (first 1 we get) occurs after an index with 3 different characters then answer is again impossible.

    Now other than this, i will iterate till the first 1 and create string accordingly (mp2 in my code) and for the last 1 (mp1 is used in my code)

    s'il vous plaît! :(

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

      I'm bad at debugging but I can give you a hint.

      When the count of unique characters in an index i for all the strings is not 1 for any index then answer is impossible.

      Is this true? Think about when the count is 2.

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

      Your idea is wrong. Don't bother debugging your code. It fails on this test case:
      $$$1$$$

      $$$2$$$
      $$$RP$$$
      $$$PR$$$

      Your output: $$$Case #1: IMPOSSIBLE$$$
      Example answer: $$$Case #1: PP$$$

      $$$PP$$$ wins $$$RP$$$ after the first move.
      $$$PP$$$ wins $$$PR$$$ after the second move.
      There is no number $$$i$$$ such, that $$$PP$$$ wins both $$$PR$$$ and $$$RP$$$ after the $$$i^{th}$$$ move. Your outputted strategy doesn't have to win his opponents after the same move. Remember, the matches are played independantly.

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

        Ah!! Damn! Thank you for taking the time out to help! :

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

          My pleasure :)

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

            Hey my solution was handling this case. Like after every round I was eliminating weaker robot . Like for above test case after 1st round I will eliminate 1st robot i.e. RP. In second round I am left with only one robot i.e. PR and hence PP would be the answer. I am still not able to find out where m I failing. https://ideone.com/zuLpnB

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

              Hello. I think I have found couple of bugs in your code. I am in computer lab of my school, and the lesson has nothing to do with computer science, so I'll type your bugs here in a while :D

              You should change lines 32, 33 of your code from this:

                if (ch.size() == 0)
                  return 0;
              

              to this:

                if (ch.size() == 0)
                  return 1;
              
              • »
                »
                »
                »
                »
                »
                »
                »
                6 лет назад, # ^ |
                  Проголосовать: нравится 0 Проголосовать: не нравится

                Still not working. I tried downloading working solution of others and trying random test cases but it is working fine with them.

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

                  You have another bug in your code. I have added it in my previous answer. I was mislead. I don't understand whats the problem in your solution :(

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

                  Damn me. Got my mistake. The mistake is in conversion of array of character into string.

                  set ch;
                  char curr[501];
                  int i = 0;
                  for (auto xx : ch) {
                  curr[i++] = xx;
                  }
                  //curr[i] = ‘\0’; Missed to introduce this terminater.
                  string cur(curr);
                  

                  Learning : We should always take care of basics.

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

                  ======================================

                  set<char> ch;
                  string s(ch.begin(), ch.end());
                  

                  Your main mistake is not learning the language you use.

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

Do they still publish official analysis after the round? I can't find it anywhere!!

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

Are there statistics for this round?

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

In the second problem. Inputs & outputs are huge. I don't have any idea about this except typing 148 numbers from my solution to the running test_tool.py and type the result back by hand. Any way easier?

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится
    mkfifo input
    mkfifo output
    python testing_tool.py > input < output
    ./your_binary < input > output
    
  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится +5 Проголосовать: не нравится

    You can use interactive_runner.py provided in the problem (Testing Tool):

    python interactive_runner.py python testing_tool.py 0 -- ./program.o
    
»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Can someone explain the solution for the 2nd subtask of last problem?

I have read the analysis but didn't get the part where they tell that our problem gets divided into 2 sub-problems?

Can someone please explain that or any other approach?

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

    Try looking for any good introductory text to game theory. Look for Sprague-Grundy theorem.

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

Can anyone explain the solution of Problem 1(Robot Programming Strategy).

I have done exactly mentioned in analysis. First stored all the program of other robots in vector . Then accessed i-th character of all robot and put it in a set. Then I have checked for 3 cases.

If set size is 3 (R,P,S) it mean there cannot be any solution with our program can win.

If size of set is 1 it means that iteration only have 1 value and we can choose corresponding winning value and return the solution

If size of set is 2 then choose the stronger character (like "R" in "RS") and proceed till we get size of set 3 or 1 , or our program length reaches 500 .

Here is my solution https://ideone.com/KJ8ovE It would be so grateful if anyone can help me debugging the solution.I have tried downloading working solution of other and tried random test cases but it is working fine.

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

    I didn't read the code fully but this might be one possible mistake, suppose you defeated player 1 in the first move then you don't need to include its other characters in the subsequent moves. If you include it then you might get all the characters (PRS) at some position which would result in a false impossible result.

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

      Actually he does not include them.

      for (int i = 0; i < a; i++) {
       
          // Here.
          if(skip.find(i) != skip.end())
              continue;
       
          if (idx < robot[i].length()) {
            ch.insert(robot[i][idx]);
          } else {
            ch.insert(robot[i][idx % robot[i].length()]);
          }
        }
      
    • »
      »
      »
      6 лет назад, # ^ |
        Проголосовать: нравится +6 Проголосовать: не нравится

      Damn me. Got my mistake. The mistake is in conversion of array of character into string.

      set ch;
      char curr[501];
      int i = 0;
      for (auto xx : ch) {
      curr[i++] = xx;
      }
      //curr[i] = ‘\0’; Missed to introduce this terminater.
      string cur(curr);
      

      Learning : We should always take care of basics.