| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 14785 | Potato's Class |
|
| 14790 | Potato's Adventure |
|
Description
It's again the time when Tr.Potato changes students' seats and adjust their scores, help Potato find where the best scored student seats after score and seat adjustments.
When Tr.Potato says:
rotate <i> <j> <width>
means that Potato wants to rotate students seats in a matrix starting from top left at(i, j)with a width ofwidthclockwise
it's guaranteed thatwidth >= 2score <name> <score>
means that Potato wants to adjust student's score toscorewho's name isname
note that you have to cap<score>inside the range of[0,100]
a.k.a ifscore > 100make it100, ifscore < 0make it0
class Student:
instances = {}
def __init__(self, name, score, i, j):
self.name = name
self.score = score
self.i = i
self.j = j
def set_score(self, score:int) -> None:
pass # TODO set the new score for this student, and make sure the score is in valid range
def get_message(self) -> str:
pass # TODO get the message by the required format
class PotatosClass:
students = dict()
def __init__(self, n, m):
self.seats = [[None]*m for _ in range(n)]
def record_students(self):
for i in range(n*m):
name, score, i, j = input().split()
score, i, j = int(score), int(i), int(j)
student = Student(name, score, i, j)
self.students[name] = self.seats[i][j] = student
def command_score(self, stu_name:str, new_score:int) -> None:
self.students[stu_name].set_score(new_score)
def command_rotate(self, i:int, j:int, width:int) -> None:
pass # TODO rotate the student's seats
def get_best_student(self) -> Student:
pass # TODO get the best scored student
n, m, k = map(int, input().split())
course = PotatosClass(n, m)
course.record_students()
for i in range(k):
commands = input().split()
if(commands[0] == "score"):
course.command_score(commands[1], int(commands[2]))
elif(commands[0] == "rotate"):
course.command_rotate(int(commands[1]), int(commands[2]), int(commands[3]))
print(course.get_best_student().get_message())
Potato's Whisper: It's highly recommanded to use the above code, since it saves you alots of time.
Potato judges your code by the following limitations:
- Testcase 1:
n = m = 3,0 < k, only <rotate> command - Testcase 2 ~ 3:
0 < n,m < 9,0 < k, only <rotate> command - Testcase 4 ~ 5:
0 < n,m < 16,0 < k - Testcase 6:
0 < n,m,0 < k
Input
The first line contains 3 integer n,m,k, representing the classroom's size is nxm and Tr.Potato will be doing k actions.
Following by n*m lines, each contains 4 elements (name, score, i, j):
name: the student's namescore: the student's initial scorei: which row the student initially seats onj: which column the student initially seats on
Than the final k lines, each contains a action of what Tr.Potato wants to do.
Output
Describe the best scored student in the following format:
"<name> at (<i>, <j>) scored <score>"
Check sample output for examples.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Potato went on an adventure to a magical maze, which rotates a rectangle part on certain timestamps, and brings any cute little potatos within the area along with the rotation.
Potato is having a hard time walking out the maze, and he's getting a bit dizzy since the maze is going round and round.
So you, as a kind and generous student, wanted to help Potato escape the maze.
The rule of the maze goes:
In every second:
- If there's a rotating event, rotate first, and if Potato is in the area, Potato rotates along with it.
- Potato picks up the treasure, and thus the score increases by the number where Potato's standing, and after that, the number is subtracted by
1. (note that a cell of0can become stone) - Potato picks and goes forward in the direction by the priority of
[Right, Down, Left, Up], if one is block, pick the next direction. (a cell containing negative number is a stone that you can't step on)
Note that:
- It is not guaranteed that all rotating events happen before Potato arrives at the bottom right of the maze.
- It is guaranteed that Potato can make it to the bottom right of the maze.
- It is guaranteed that all
krotating events happen on different time.


class Potato:
def __init__(self) -> None:
self.i = 0
self.j = 0
self.score = 0
def play(self, time:int, maze:"Maze") -> None:
# Update maze (if there's any event, do the event first)
maze.update_time(time, self)
# TODO
# utilize functions in maze
# 1. pick up the points where you're standing on (take a look in 'class Maze')
# 2. move Potato by checking if next cell is a stone by the priority of [Right, Down, Left, Up]
def get_location_message(self, time:int) -> str:
# TODO
# return the formated the message by the required format
# >> the message printed each second
return f"Where's Potato!!"
def get_summary_message(self, time:int) -> str:
# TODO
# return the formated the message by the required format
# >> the message printed when Potato arrived at bottom right
return f"How much time and score did Potato spend and get!!"
class MazeRotatingEvent:
def __init__(self, t, i, j, w, d) -> None:
self.t = t
self.i = i
self.j = j
self.w = w
self.d = d
class Maze:
def __init__(self, n, m) -> None:
self.n = n
self.m = m
def read_grid(self) -> None:
self.grid = [list(map(int, input().split())) for i in range(self.n)]
def read_k_events(self, k:int) -> None:
self.events = None # TODO replace this with how you want to store MazeRotatingEvents
for i in range(k):
t, i, j, w, d = map(int, input().split())
rotatingEvent = MazeRotatingEvent(t, i, j, w, d)
# TODO store this new MazeRotatingEvent <rotatingEvent>
def is_cell_the_end(self, i:int, j:int) -> bool:
# TODO
# return True if (i, j) is the bottom-right
# return False if (i, j) is not the bottom-right
return
def is_cell_walkable(self, i:int, j:int) -> bool:
# TODO
# return False if (i, j) is out of map or is a stone (negative number)
# return True if (i, j) is in the map and is not a stone (positive number or 0)
return
def pick_up_treasure_at(self, i:int, j:int) -> int:
# TODO
# return the points on (i, j), and because it's picked up, subtract by 1
return
def update_time(self, time:int, potato:Potato) -> None:
# TODO
# check if there's a rotating event on time <time>
# if there's a rotating event, rotate the area, and also move potato's position
pass
n, m, k = map(int, input().split())
magic_maze = Maze(n, m)
magic_maze.read_grid()
magic_maze.read_k_events(k)
cute_potato = Potato()
time = 0
while(True):
old_i, old_j = cute_potato.i, cute_potato.j
cute_potato.play(time, magic_maze)
print(cute_potato.get_location_message(time))
if(magic_maze.is_cell_the_end(cute_potato.i, cute_potato.j)):
print(cute_potato.get_summary_message(time))
break
time += 1
Potato judges your code by the following limitations:
- Testcase 1:
n = m = 4,k = 0 - Testcase 2~3:
n = m < 16,k = 0 - Testcase 4~5:
n,m < 32,k > 0,events[i].d = 0 - Testcase 6~7:
n,m < 32,k > 0,events[i].d = 1 - Testcase 8:
n,m < 64,k > 0
Potato's Whisper 1: It's highly recommanded to use the above code, since it saves you alots of time.
Potato's Whisper 2: The template code is actually runnable, you can run it first then edit it.
Potato's Whisper 3: Potato is one of the loveliest food/person, since hashbrowns and fries are made out of it.
Potato's Whisper 4: I'm soo happy you read the question sooo detailed, but you should start coding NOW.
Input
The first line contains 3 integer n,m,k, representing the maze's size is nxm and there will be k rotating events in the future.
Following by n lines, each contains m integers, forming the maze.
Than the final k lines, each contains 5 integers t,i,j,w,d representing:
- There is a rotating event happening on time
t - The rotating area's center is at
(i,j) - The rotating area's width is
w - The rotation goes
ddirection (clockwise whend=0, counter-clockwise whend=1)
Limitations:
- All
kevents happen on different timet - All
kevents' rotating area will not exceed the map - All
n*mnumbers initially on the map are less than10
Output
When every second ends, print where Potato's at by the following format:
<i>, <j>) when t=<t>Where i,j is where Potato ends at on time t.
And finally when he arrives at the bottom right, print a message by the following format:
<t> seconds and got <score> pointsWhich means that Potato arrived at the bottom right corner on time t, and collected score points along the way.