ECOO '13 R1 P1 - Take a Number

View as PDF

Submit solution


Points: 5 (partial)
Time limit: 30.0s
Memory limit: 256M

Problem type

Due to overwhelming demand, the principal has installed one of those "take a number" dispensers to help the attendance secretary manage the line for late slips. The dispenser is filled with slips of paper numbered in order from 1 to 999. The principal has made sure to order lots of refills! The attendance desk opens at 8:00 am every morning and closes at 3:00 pm. When a late student arrives they take the next number from the machine, and when the attendance secretary is ready, he calls the next number in order. When a student takes the last number, the secretary immediately refills the machine with a new set of numbers from 1 to 999. At 3:00 pm, he removes the dispenser and stores it for the next day, then serves any students who are still waiting with numbers in their hands before closing for the day.

You will be given detailed data for a number of days in the late slip lineup. The first line contains an integer N (0 < N < 1\,000) representing the next number in the take a number machine. This will be followed by some number of lines (up to 1\,000\,000) representing the activity at the attendance desk. If a line contains the word TAKE, it means a student has arrived and taken the next number (when a student takes the last number available, the machine is immediately refilled). If a line contains the word SERVE it means that the attendance secretary has served the next student in line (this word will only appear in the file when there is at least one student waiting). If a line contains the word CLOSE it means that the desk has closed for the day and the attendance secretary will serve the students remaining in line and then go home. The very last line will contain the string EOF. At no time will there be more than 999 students waiting in line to be served.

Your job is to keep track of the line. Each time you encounter the word CLOSE, you must print three integers on a single line, each separated by a single space. The first integer represents the number of students who were late that day, the second integer represents the number of students who remained in line after the desk was closed, and the third integer represents the next number in the take a number machine for the next day.

Sample Input

23
TAKE
TAKE
SERVE
TAKE
SERVE
SERVE
CLOSE
TAKE
TAKE
TAKE
SERVE
CLOSE
TAKE
SERVE
TAKE
SERVE
TAKE
TAKE
TAKE
TAKE
TAKE
TAKE
SERVE
CLOSE
EOF

Sample Output

3 0 26
3 2 29
8 5 37

Educational Computing Organization of Ontario - statements, test data and other materials can be found at ecoocs.org


Comments


  • 0
    Omace  commented on Jan. 27, 2023, 5:55 p.m.

    I've tried different ways of formatting my output: passing the variables as arguments through the print function, f-string formatting and converting each integer variable to a string and concatenating spaces, but it still results in clipping could someone please help me understand what causes output clipping? Am I misusing the print function, or is something else going on?


    • 0
      dnialh_  commented on Jan. 27, 2023, 6:08 p.m. edited

      Clipped just means that dmoj isn't showing you the full output that your program printed.

      Your solution was still judged on its full output.


      • 0
        Omace  commented on Jan. 27, 2023, 7:26 p.m.

        If that is the case then is my math wrong? It's very difficult for me to parse the feedback when dmoj isn't telling me if my answer is expected. I'll go back and try to refactor regardless. Thank you for responding.


        • 0
          dnialh_  commented on Jan. 28, 2023, 10:19 p.m.

          The purpose of the sample is for you to run the code locally and see the result. The sample is often very useful for debugging :)


  • 0
    petrosians  commented on Dec. 8, 2022, 4:55 p.m.

    i can't find my error. Can someone take a look at my different submissions please? Im really lost.


    • 0
      Hackerman_567  commented on Jan. 3, 2023, 4:38 p.m.

      How about you append your inputs to a list and then set the while loop to keep running while "EOF" is not in list. Make sure to reset 1 to one when the value is greater than or equal to 999.


  • -1
    Payne  commented on Nov. 24, 2022, 7:15 p.m.

    I'm very curious to know, what is the longest submission time on this problem?

    I managed to get a solution that took 63 seconds -> https://dmoj.ca/submission/5062652

    But I'm sure it is possible to get a higher time.


  • 1
    vishanell  commented on Oct. 8, 2022, 3:49 a.m.

    Be careful when naming your variables


  • 1
    maxcruickshanks  commented on Oct. 2, 2022, 6:29 p.m.

    Since the original data were weak, an additional test case was added, and all submissions were rejudged.


  • 0
    johnmagee  commented on June 28, 2022, 11:18 p.m.

    So far I've done all these using input instead of readline, so maybe that's the problem, but this works when I run the test sample manually I get the right output but I get 2 WA errors when I try to run my submission but I can't figure what I"m missing...any help would be appreciated

    Can't figure out how or if i'm supposed to post the full code here so I created a gist For people to read

    Hope someone can help...been pretty aggravating


  • 0
    Natuyuki  commented on June 18, 2022, 7:21 a.m.

    Hi, its my first time trying to submit a solution on DMOJ where data needs to be read as input. I can get my code to work reading a sample input via txt file locally, but I am not sure how am I supposed to read the sample input from the website, keep getting errors...


    • 0
      KmiloKun  commented on June 28, 2022, 8:16 p.m.

      Sometimes the example of input is too small and it's don't let us see where is the problem when we test our code.


      • 0
        johnmagee  commented on June 29, 2022, 9:21 p.m.

        Yes but they're asking how to actually get the input into the file, that's kind of where I'm stuck too...


  • -1
    Wimfke  commented on June 17, 2022, 7:58 a.m.

    can you use i % 999? It turns up correct but if 999 is the ticket number remaining it prints 0, which isn't correct, no?


  • 0
    YouKnowMe  commented on May 5, 2022, 10:10 a.m.

    i cant find the error in my code, it works locally but as soon as i run it through the judge it fails. can anyone take a look?


  • -3
    DRankin  commented on March 17, 2022, 4:56 p.m.

    I don't understand why my code is outputting less than three integers separated by spaces when my output should be three separate variables separated by a space. Can somebody help me understand what's going on? I'm really having trouble recreating this on my end.


    • 0
      sushi  commented on April 12, 2022, 10:40 a.m.

      The output is most likely clipped, meaning only a portion of your program's output is shown as feedback.


  • 2
    rocpix  commented on Jan. 2, 2022, 10:20 p.m.

    I'm grading the grader on this one... I've looked at a few of the other submissions (PY3) and noticed they allow ticket number 0 and do not allow ticket number 999!! I'm not sure of the tests used but may have been over looked or just not tested for that.


    • -1
      pyhead42  commented on Sept. 27, 2022, 2:30 a.m.

      Yeah agreed, failed the judge first time. Went back and changed 1000 to 999 and passed it. Don't know why they bother saying 0 < N < 1000; it's just confusing since N can be 0 and can't be 999. All we really need to do is count from 0 up to, but not including, 999.


  • 1
    sankeeth_ganeswaran  commented on April 3, 2019, 12:31 p.m.

    My code works on an online compiler but it fails when I submit it. Can someone take a look?


    • 7
      Beautiful_Times  commented on April 3, 2019, 1:29 p.m.

      I dont think you took in the case where the secretary refills the machine. If your output is more than 1000, you have to reset the machine and the counter goes from 1.


      • 1
        solverbot  commented on April 12, 2022, 9:40 a.m.

        That point, the machine number goes to 1 was my catch... Thnx


      • 1
        sankeeth_ganeswaran  commented on April 3, 2019, 1:33 p.m.

        Thank you I didn't see that