[HSBC] OA 2025 start – 19 Apr (generic)

Street Lights State Simulation

Problem Description

Mr. Woods, an electrician for Timberland city, has made some faulty connections on eight street lights. The issue causes a street light to go OFF if the street lights adjacent to it were both ON or both OFF on the previous night. Otherwise, the light will go ON as normal. The two street lights at the end of the road have only a single adjacent street light, so the light at the end can be assumed to be always OFF.

Given the current state of the street lights, simulate and return the state of the street lights after M days.

Input

  • The first line contains an integer: currentState_size — the number of street lights (always 8).
  • The second line contains 8 space-separated integers: currentState — representing the current state of each street light (either 0 or 1).
  • The third line contains a single integer: days — the number of days to simulate.

Output

Print 8 space-separated integers representing the state of the street lights after M days.

Constraints

  • 1 ≤ days ≤ 10^6

Example

Input:
8
1 1 0 1 1 1 1 1
2

Output:
0 0 0 0 1 1 1 0

Explanation

Day 1:

  • For each light, check its adjacent lights (assume light[-1] and light[8] are OFF).
  • Apply the transformation rule:
    • If both adjacent lights are the same (both 0 or both 1), then the light becomes 0.
    • Otherwise, it becomes 1.
  • After first day: 1 0 1 0 1 0 1 0

Day 2:

  • Apply the same logic to the new state.
  • Final state after 2 days: 0 0 0 0 1 1 1 0

Minimum Service Time for Zone Complaints

Problem Description

Addison is tasked with servicing complaints in different zones of a city. After resolving each complaint, Addison must return to the head office located in zone 1. He must complete all complaints within the provided time limit for each complaint.

The city is represented as N zones connected by M bidirectional roads. For each complaint, Addison must determine the maximum time spent in servicing it (from zone 1 to target zone and back). If he cannot visit and return within the limit, the time should be recorded as 0.

Input

  • The first line contains an integer: numZones — number of zones.
  • The second line contains two integers: numRoads and 3 (fixed), representing the number of roads.
  • The next numRoads lines each contain three integers: zoneA, zoneB, and travelTime representing a bidirectional road.
  • The next line contains two integers: numComplaints and 2 (fixed), representing number of complaints.
  • The next numComplaints lines each contain:
    • An integer zoneX: target zone
    • An integer timeLimit: maximum allowed time

Output

Print Q space-separated integers, where each value is the maximum service time (0 if not possible).

Constraints

  • 1 ≤ numZones, numComplaints ≤ 10^5
  • 1 ≤ numRoads ≤ 10^5
  • 1 ≤ zoneA, zoneB ≤ numZones
  • 1 ≤ travelTime ≤ 1000

Example

Input:
4
5 3
1 2 3
2 3 4
3 4 5
4 1 6
2 4 8
5 2
2 5
3 6
4 15
2 10
4 12

Output:
10 12 0 10 0

Explanation

  • Compute shortest distance from zone 1 to all other zones using Dijkstra’s algorithm.
  • For each complaint, check if 2 × shortest_path(zone1 → zoneX) ≤ timeLimit.
  • If so, record the round-trip time; otherwise, 0.

我们长期稳定承接各大科技公司如TikTok、Google、Amazon等的OA笔试代写服务,确保满分通过。如有需求,请随时联系我们。

We consistently provide professional online assessment services for major tech companies like TikTok, Google, and Amazon, guaranteeing perfect scores. Feel free to contact us if you're interested.

Leave a Reply

Your email address will not be published. Required fields are marked *