algoblazerEarly Access
LearnProblemsLeaderboard
Log inSign up

All problems

‹ Back to map
1 shown · 0/275 solved

Proximity Routing Commands

SilverCommunity Beta
Asked atStripe
Solve problem →
2000ms256MBAdded Sep 19, 2026

You are given a list of text commands commands that operate a registry of named regions, each at an integer latitude and longitude with a capacity. Process the commands in order. Return one output line per command.

Commands

REGISTER <name> <lat> <lon> <capacity>: add a region. The output is OK, or ERROR (with no change made) if any rule fails:

  • lat must be in [-90, 90] and lon in [-180, 180].
  • capacity must be greater than 0.
  • name must not already be registered.

A newly registered region is healthy and has capacity units of remaining capacity.

SET_HEALTHZ <name> <true|false>: mark a registered region healthy or unhealthy. The output is OK, or ERROR if the name is not registered.

DISTANCE <lat1> <lon1> <lat2> <lon2>: the output is the great-circle distance in kilometres between the two points, computed with the Haversine formula below and rounded half-up to an integer. These arguments are not range-checked.

ROUTE <lat> <lon>: route a request. The output is ERROR if lat or lon is outside the ranges above. Otherwise:

Read full statement →

Constraints

  • 1≤1 \leq1≤ commands.length ≤1000\leq 1000≤1000
  • Region names consist of lowercase letters, digits, and hyphens, with length at most 20; at most 50 distinct names appear
  • All numeric arguments are integers with absolute value at most 10410^4104; capacities of valid registrations are at most 10410^4104
  • Every command is well-formed (correct number of tokens, single spaces)

Details

Solved by1 person
Time limit2000ms
Memory256MB
AddedSep 19, 20263 hours ago