3376 - I2P(I)2026_Lo_Hw7 Scoreboard

Time

2026/11/23 00:00:00 2026/11/30 18:00:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
15089 Walter White's Parking Empire
15090 Buldar's Gate
15100 Lunix File System

15089 - Walter White's Parking Empire   

Description

Walter White has decided to expand his business. After realizing that running a car wash isn't enough, he opens a parking garage in Albuquerque to help launder his money. Unfortunately, Jesse who was supposed to build the parking management system, can do nothing but to print("Yo, Mr. White!"), so Walter has now hired you to complete the job.

Your task is to implement a parking management system using Object-Oriented Programming (OOP). The system must register parking spaces, assign vehicles to suitable spaces, calculate parking fees, and track the current parking status.

The system consists of three main components:

  • Vehicle: A parent class containing common vehicle properties and methods. Motorcycle, Car, and Truck inherit from this class, each defining its own parking requirements and hourly rate. Trucks also have an additional service fee.
  • ParkingSpot: Represents an individual parking space with a unique ID, size, and occupancy status.
  • ParkingGarage: Manages all parking spaces, handles vehicle arrivals and departures, and maintains parking records.

 

Parking Rules

The garage accepts three types of vehicles:

Vehicle
Minimum Spot Size    
Hourly Rate
Motorcycle    
1
$10
Car
2
$20
Truck
3
$30

Walter insists that trucks need "special handling", so an additional $50 service fee applies to every truck departure, regardless of parking duration.

Parking spaces have three sizes:  SMALL (1), MEDIUM (2), and LARGE (3).

The system must follow these rules:

  1. A vehicle can only occupy an empty space that meets its minimum size requirement.
  2. When parking, choose the smallest available space that fits the vehicle. If multiple spaces have the same size, choose the one registered first.
  3. A vehicle cannot park twice using the same license plate.
  4. If no suitable space is available, reject the parking request.
  5. When a vehicle leaves, calculate its parking fee, free its space, and update the garage records.
  6. The garage must display the status of every parking space in registration order.

 

Your Mission

Complete all TODO sections in the provided starter code.

Use inheritance and method overriding to implement the different vehicle types. The system must correctly process parking requests, vehicle departures, and status queries according to the rules above.

Do not modify the provided main program.

 

Starter Code

class Vehicle:
    def __init__(self, plate):
       self.plate = plate

    def required_size(self):
        pass

    def hourly_rate(self):
        pass

    def fee(self, hours):
        return self.hourly_rate() * hours


class Motorcycle(Vehicle):
    def required_size(self):
        # TODO: Implement this method.
        raise NotImplementedError

    def hourly_rate(self):
        # TODO: Implement this method.
        raise NotImplementedError


class Car(Vehicle):
    def required_size(self):
        # TODO: Implement this method.
        raise NotImplementedError

    def hourly_rate(self):
        # TODO: Implement this method.
        raise NotImplementedError


class Truck(Vehicle):
    def required_size(self):
        # TODO: Implement this method.
        raise NotImplementedError

    def hourly_rate(self):
        # TODO: Implement this method.
        raise NotImplementedError

    def fee(self, hours):
        # TODO: Implement this method.
        raise NotImplementedError


class ParkingSpot:
    def __init__(self, spot_id, size):
        # TODO: Implement this method.

        # You might want to store a vehicle here
        raise NotImplementedError

    def is_free(self):
        # TODO: Implement this method.
        raise NotImplementedError

    def can_fit(self, vehicle):
        # TODO: Implement this method.
        raise NotImplementedError

    def assign_vehicle(self, vehicle):
        # TODO: Implement this method.
        raise NotImplementedError

    def remove_vehicle(self):
        # TODO: Implement this method.
        raise NotImplementedError


class ParkingGarage:
    def __init__(self):
        self.spots = []
        self.parked = {}

    def add_spot(self, spot):
        # TODO: Implement this method.
        raise NotImplementedError

    def park_vehicle(self, vehicle):
        # TODO: Implement this method.
        raise NotImplementedError

    def release_vehicle(self, plate, hours):
        # TODO: Implement this method.
        raise NotImplementedError

    def status_lines(self):
        # TODO: Implement this method.
        raise NotImplementedError


def create_vehicle(vehicle_type, plate):
    # TODO: Implement this function.
    raise NotImplementedError


if __name__ == "__main__":
    garage = ParkingGarage()
    sizes = {"SMALL": 1, "MEDIUM": 2, "LARGE": 3}

    n = int(input())

    for _ in range(n):
        spot_id, size_name = input().split()
        garage.add_spot(ParkingSpot(spot_id, sizes[size_name]))

    q = int(input())

    for _ in range(q):
        parts = input().split()
        command = parts[0]

        if command == "PARK":
            vehicle_type = parts[1]
            plate = parts[2]
            vehicle = create_vehicle(vehicle_type, plate)
            spot_id = garage.park_vehicle(vehicle)

            if spot_id is None:
                print(f"REJECTED {plate}")
            else:
                print(f"PARKED {plate} {spot_id}")

        elif command == "LEAVE":
            plate = parts[1]
            hours = int(parts[2])
            fee = garage.release_vehicle(plate, hours)

            if fee is None:
                print(f"NOT_FOUND {plate}")
            else:
                print(f"FEE {plate} {fee}")

        elif command == "STATUS":
            for line in garage.status_lines():
                print(line)

Input

The first line contains an integer N, representing the number of parking spaces.

The next N lines each contain two values:

spot_id size

  • spot_id: The unique identifier of the parking space.

  • size: The size of the parking space (SMALL, MEDIUM, or LARGE).

The next line contains an integer Q, representing the number of commands.

The following Q lines each contain one of three commands:

  • PARK type plate: Park a vehicle with the specified type (MOTORCYCLE, CAR, or TRUCK) and license plate.

  • LEAVE plate hours: Remove the vehicle with the specified license plate after hours hours and calculate its parking fee.

  • STATUS: Display the current status of every parking space.

Guarantees: All parking spaces are initially empty. Parking space IDs are unique. Vehicle types and commands are valid. Parking durations are nonnegative integers.

Output

For each command, print the corresponding result:

  • PARKED plate spot_id: The vehicle was successfully parked in the assigned parking space.

  • REJECTED plate: The vehicle could not be parked because its license plate is already registered or no suitable space is available.

  • FEE plate amount: The vehicle successfully left the garage, and amount is its total parking fee.

  • NOT_FOUND plate: The specified vehicle is not currently parked.

  • For STATUS, print spot_id plate for each occupied space or spot_id EMPTY for each empty space, in the order the spaces were registered.

Sample Input  Download

Sample Output  Download




Discuss




15090 - Buldar's Gate   

Description

A group of adventurers has entered a mysterious dungeon, where only the strongest will survive!

The dungeon is filled with warriors, mages, and healers, each possessing unique combat abilities. As battles unfold, characters attack each other, take damage, and use their special abilities to stay alive.

Your task is to implement a system that handles character creation, combat, health management, and winner detection using inheritance.

Every character has a unique name, health points (hp), and attack power (power). There are three character classes:

Class Ability
Warrior

Reduces incoming damage by armor

Mage

Deals double attack damage

Healer

Heals itself after attacking

 

Combat Rules

The following rules apply:

  • Warrior: Incoming damage is reduced by armor, but never below 0.

  • Mage: Deals power × 2 damage instead of normal damage.

  • Healer: Deals normal damage and restores heal_amount HP after attacking, without exceeding its starting HP (max_hp).

  • Health: A character's HP cannot fall below 0. Characters with 0 HP are defeated.

  • Attacks: Both characters must exist and be alive. A character cannot attack itself. Invalid attacks have no effect.

  • Winner: A winner is declared only when exactly one character remains alive.

The damage reported by an attack is the actual HP lost by the target, after armor reduction and HP limits.

 

Your Mission

Complete all TODO sections in the starter code using inheritance.

The Battle class maintains two data structures:

  • characters: A list storing characters in the order they were added.
  • by_name: A dictionary mapping character names to their corresponding objects for efficient lookup.

Both structures refer to the same character objects and must remain consistent.

Do not modify the provided main program.

 

Starter Code​

class Character:
    def __init__(self, name, hp, power):
        # TODO: Implement this method.
        raise NotImplementedError

    def is_alive(self):
        """Return True if alive, otherwise False."""
        # TODO: Implement this method.
        raise NotImplementedError

    def take_damage(self, amount):
        """Return the actual HP lost."""
        # TODO: Implement this method.
        raise NotImplementedError

    def attack(self, target):
        """Return the actual damage dealt to the target."""
        # TODO: Implement this method.
        raise NotImplementedError

 

class Warrior(Character):
    def __init__(self, name, hp, power, armor):
        # TODO: Implement this method.
        raise NotImplementedError

    def take_damage(self, amount):
        """Return the actual HP lost after armor reduction."""
        # TODO: Implement this method.
        raise NotImplementedError


class Mage(Character):
    def attack(self, target):
        """Return the actual damage dealt to the target."""
        # TODO: Implement this method.
        raise NotImplementedError


class Healer(Character):
    def __init__(self, name, hp, power, heal_amount):
        # TODO: Implement this method.
        raise NotImplementedError

    def attack(self, target):
        """Return the actual damage dealt to the target."""
        # TODO: Implement this method.
        raise NotImplementedError


class Battle:
    def __init__(self):
        self.characters = []  # Characters in insertion order.
        self.by_name = {}  # Maps character names to their objects.

    def add_character(self, character):
        # TODO: Implement this method.
        raise NotImplementedError

    def attack(self, attacker_name, target_name):
        """Return actual damage (int), or None if the attack is invalid."""
        # TODO: Implement this method.
        raise NotImplementedError

    def winner(self):
        """Return the winner's name (str), or None if there is no winner."""
        # TODO: Implement this method.
        raise NotImplementedError

    def status_lines(self):
        """Return one "<name> <hp>" or "<name> DEFEATED" string per character,
        in the order they were added."""
        # TODO: Implement this method.
        raise NotImplementedError


def create_character(character_type, name, hp, power, extra):
    """Create a Warrior (WARRIOR), Mage (MAGE), or Healer (HEALER).
    extra is armor for WARRIOR, heal_amount for HEALER, and None for MAGE."""
    # TODO: Implement this function.
    raise NotImplementedError


if __name__ == "__main__":
    battle = Battle()

    n = int(input())

    for _ in range(n):
        parts = input().split()
        character_type = parts[0]
        name = parts[1]
        hp = int(parts[2])
        power = int(parts[3])

        if character_type == "MAGE":
            extra = None
        else:
            extra = int(parts[4])

        battle.add_character(
            create_character(character_type, name, hp, power, extra)
        )

    q = int(input())

    for _ in range(q):
        parts = input().split()
        command = parts[0]

        if command == "ATTACK":
            attacker_name = parts[1]
            target_name = parts[2]
            damage = battle.attack(attacker_name, target_name)

            if damage is None:
                print("INVALID")
            else:
                print(f"HIT {target_name} {damage}")

        elif command == "WINNER":
            winner = battle.winner()

            if winner is None:
                print("NONE")
            else:
                print(winner)

        elif command == "STATUS":
            for line in battle.status_lines():
                print(line)

Input

The first line contains an integer N, representing the number of characters.

The next N lines describe the characters in one of the following formats:

WARRIOR name hp power armor,

MAGE name hp power, or

HEALER name hp power heal_amount

  • name: The unique name of the character
  • hp: The character's starting health points.
  • power: The character's base attack damage.
  • armor: The Warrior's damage reduction.
  • heal_amount: The Healer's HP recovery per attack.

The next line contains an integer Q, representing the number of commands.

The following Q lines each contain one of three commands:

ATTACK attacker target: Attacker performs an attack towards target,

WINNER: Check whether exactly one character is still alive, or

STATUS: Display the current  status of all characters.

Guarantees: All character names are unique. Initial HP and attack power are positive integers, while armor and healing amounts are nonnegative integers.

Output

For each command, print the corresponding result:

  • HIT target damage: A successful attack, showing the actual HP lost.

  • INVALID: The attack cannot be performed.

  • For WINNER, print only the winner's name if exactly one character remains alive, or NONE otherwise.

  • For STATUS, print name hp for each living character or name DEFEATED for each defeated character, in registration order.

A valid attack that deals 0 damage must still print HIT target_name 0.

Sample Input  Download

Sample Output  Download




Discuss




15100 - Lunix File System   

Description

You've decided to write your own operating system from scratch. The bootloader works, and the kernel prints "Hello, world!" without crashing (most of the time).

But there's one problem: you can't save anything.

Your OS has no file system. No folders, no files, not even somewhere to store your unfinished homework.

Time to build one.

File System Rules

Your file system is made up of nodes. Every node has a name, and there are two types:

Node
Description
Size
File
Stores text content
Number of characters in its content
Directory
Contains files and other directories
Total size of all files inside it, including nested directories

 

Both File and Directory inherit from FileSystemNode and override get_size().

All paths are absolute (starting with /). For example, /home/user/notes.txt represents a file inside two nested directories. The file system starts with an empty root directory, /.

Empty path components are ignored, so /home//user/ is equivalent to /home/user.

The following rules apply:

  • Creating directories: MKDIR creates all missing directories along the path. Existing directories remain unchanged.

  • Adding files: ADD creates a new file or appends content to an existing one. Missing parent directories are created automatically.

  • Reading: READ returns a file's content.

  • Listing: LS returns directory contents in alphabetical order. Listing a file returns its name, while an empty directory prints EMPTY.

  • Size: SIZE returns the number of characters in a file or the combined size of a directory's contents.

  • Deleting: DELETE removes a file or an entire directory, including everything inside it. The root directory cannot be deleted.

  • Moving: MOVE relocates or renames a file or directory, preserving its contents. The destination's parent must already exist, and the destination must not exist.

Additional rules for MOVE:

  1. The root directory cannot be moved.

  2. The source must exist.

  3. A directory cannot be moved into itself or one of its descendants.

  4. The destination's parent must exist and must be a directory.

  5. The destination must not already exist.

  6. If any check fails, the file system must remain unchanged.

When checking whether a directory is moved into itself, compare complete path components. For example, moving /homeinto /home/projects is invalid, but moving it to /homework/old is allowed if /homework exists.

 

Error Handling

When a command fails, print the appropriate error message and return without changing the file system. 

Situation
Error message
Path is not absolute
Error: path must be absolute: <path>
Path does not exist
Error: no such file or directory: <path>
Path passes through a file
Error: not a directory: <path>
READ or ADD targets a directory
Error: is a directory: <path>
Child already exists in Directory.add()
Error: '<name>' already exists
Deleting root
Error: cannot delete root
Moving root
Error: cannot move root
Moving directory into itself
Error: cannot move a directory into itself: <destination>
Destination already exists
Error: destination exists: <destination>

 

Your Mission

Complete all methods marked with TODO in the provided starter code.

Sample Code


class FileSystemNode:
    def __init__(self, name):
        self.name = name

    def get_size(self):
        raise NotImplementedError


class File(FileSystemNode):
    def __init__(self, name, content=""):
        # TODO: Initialize the name and store the content.
        raise NotImplementedError

    def append(self, text):
        # TODO: Append text to the file.
        raise NotImplementedError

    def read(self):
        # TODO: Return the file's content.
        raise NotImplementedError

    def get_size(self):
        # TODO: Return the content's length.
        raise NotImplementedError


class Directory(FileSystemNode):
    def __init__(self, name):
        # TODO: Initialize the name and an empty dictionary of children.
        raise NotImplementedError

    def add(self, node):
        # TODO: Add a child by name, or print an error if it already exists.
        raise NotImplementedError

    def get(self, name):
        # TODO: Return the matching child, or None.
        raise NotImplementedError

    def remove(self, name):
        # TODO: Remove and return a child, or None.
        raise NotImplementedError

    def list_contents(self):
        # TODO: Return sorted child names.
        raise NotImplementedError

    def get_size(self):
        # TODO: Return total size of all children.
        raise NotImplementedError


class FileSystem:
    def __init__(self):
        self.root = Directory("")

    def _parts(self, path):
        # TODO: Validate and split an absolute path, skipping empty parts. Then return a list of parts.
        raise NotImplementedError

    def _traverse(self, path):
        # TODO: Find and return a node, or print an error and return None.

        # HINT: If a child does not exist, print:
        # Error: no such file or directory: <path>
        # If the path passes through a File, print:
        # Error: not a directory: <path>
        # Return None on error.
        # You can reuse _parts().
        raise NotImplementedError

    def mkdir(self, path):
        # TODO: Create missing directories and return the final directory.
        # If the path passes through a File, print:
        # Error: not a directory: <path>
        raise NotImplementedError

    def add_file(self, path, content):
        # TODO:
        # Create a file if it does not exist.
        # If it already exists, append the new content.
        # Create any missing parent directories automatically.
        #
        # If the path refers to a directory, print:
        # Error: is a directory: <path>
        raise NotImplementedError

    def read_file(self, path):
        # TODO:
        # Create a file if it does not exist.
        # If it already exists, append the new content.
        # Create any missing parent directories automatically.
        #
        # If the path refers to a directory, print:
        # Error: is a directory: <path>
        #
        # Hint: mkdir() can help create the parent directory.

        raise NotImplementedError

    def ls(self, path):
        # TODO:
        # If the node is a Directory, return its sorted child names.
        # If the node is a File, return [node.name].
        # Return None on error.
        raise NotImplementedError

    def get_size(self, path):
        # TODO:
        # Find the node and return its size.
        # Return None on error.
        #
        # Hint: Every node implements get_size().
        raise NotImplementedError

    def delete(self, path):
        # TODO:
        # Remove a file or an entire directory.
        #
        # Rules:
        # 1. The path must be absolute.
        # 2. The root directory "/" cannot be deleted.
        # 3. The target must exist.
        #
        # Hint: Find the target's parent directory.
        # Removing a directory also removes its entire subtree.
        raise NotImplementedError

    def move(self, source, destination):
        # TODO: 
        # Move or rename a file or directory.
        # Preserve the node and everything inside it.
        # Hints:
        # - Compare path components to detect invalid moves.
        # - The destination does not create missing directories.
        # - Update the node's name if it changes.
        # - If any check fails, the file system must remain unchanged.
        raise NotImplementedError


# MAIN PROGRAM — DO NOT MODIFY

if __name__ == "__main__":
    fs = FileSystem()

    q = int(input())

    for _ in range(q):
        line = input()
        parts = line.split(maxsplit=2)

        if not parts:
            continue

        command = parts[0]
        path = parts[1] if len(parts) > 1 else "/"

        if command == "MKDIR":
            fs.mkdir(path)

        elif command == "ADD":
            # Take everything after "ADD <path> " verbatim, keeping inner/leading spaces.
            rest = line.lstrip()[len(command):].lstrip()
            content = rest[len(path) + 1:] if len(rest) > len(path) else ""
            fs.add_file(path, content)

        elif command == "READ":
            text = fs.read_file(path)
            if text is not None:
                print(text)

        elif command == "LS":
            names = fs.ls(path)

            if names is not None:
                print(" ".join(names) if names else "EMPTY")

        elif command == "SIZE":
            size = fs.get_size(path)
            if size is not None:
                print(size)

        elif command == "DELETE":
            fs.delete(path)

        elif command == "MOVE":
            destination = parts[2] if len(parts) > 2 else ""
            fs.move(path, destination

Input

The first line contains an integer Q, representing the number of commands.

The following Q lines each contain one of seven commands:

Command
Description
MKDIR path
Create directories
ADD path content
Create or append to a file
READ path
Read a file
LS path
List contents
SIZE path
Get a node's size
DELETE path
Delete a file or directory
MOVE source destination
Move or rename a node

Output

For each command, print the corresponding result:

  • MKDIR, ADD, DELETE, MOVE: No output on success.

  • READ: Print the file's content.

  • LS: Print names separated by spaces, or EMPTY.

  • SIZE: Print the file or directory's size.

  • Errors: Print exactly one matching error message. Do not print an additional result.

Sample Input  Download

Sample Output  Download




Discuss