Subtask 1: represent the infected set by a bitmask. For every choice of three distinct regions, clear those bits and apply the simultaneous midnight spread. Run BFS from the all-infected state to the empty state and reconstruct the path. Bit operations give time and space. The construction below guarantees a path within days, so a shortest path found by BFS also meets the limit.
Full solution: choose . At noon on day , clean regions ().
If , all regions are cleaned on the first day. Otherwise, after midnight on day , for , the clean regions are exactly . On day 1, cleaning leaves only region 2 clean after the two endpoints are reinfected. Inductively, adding to the previously clean interval makes clean at noon. At midnight only its two endpoints touch infected regions outside it, leaving clean.
On day , clean the remaining regions . No virus remains to spread. The three printed indices are distinct and in range, and .
The solution uses time for output and extra space, excluding output buffers. The checker directly simulates all days in time and space. Since , at most region updates are needed per input file.
Solution written by GPT