DOJ logoDOJ
Problems
Recently added problemsSaved problemsWorkbooks
CategoriesDLCContestsGroupsTeamsBoard
Ranking
Solved Problem RankingStreak rankingDOJ Power ranking
Status
Call for TasksLoginRegister
DOJ logoDOJ

Community online judge with OI-style subtask scoring, Elo ratings, and Discord-backed certification.

Problems
ProblemsCategories
Community
ContestsRankingBoardNoticesHost an external contestGuide
Account
LoginRegisterJudge Status
Policy
Terms of ServiceDLC RulesPrivacyAPI documentationLanguage runtimesContest rank rewardsRating and performance
© 2026 DOJ
All rights reserved
Editorial

Virus Removal

Back to problem

Editorial

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 O(2NN3)O(2^N N^3)O(2NN3) time and O(2N)O(2^N)O(2N) space. The construction below guarantees a path within NNN days, so a shortest path found by BFS also meets the limit.

Full solution: choose X=N−2X=N-2X=N−2. At noon on day kkk, clean regions 1,k+1,k+21,k+1,k+21,k+1,k+ ().

If N=3N=3N=3, all regions are cleaned on the first day. Otherwise, after midnight on day kkk, for 1≤k≤N−31 \leq k \leq N-31≤k≤N−3, the clean regions are exactly [2,. 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 N−2N-2N−2, clean the remaining regions 1,N−1,N1,N-1,N1,N−1,N. No virus remains to spread. The three printed indices are distinct and in range, and N−2≤NN-2 \leq NN−2≤.

The solution uses O(N)O(N)O(N) time for output and O(1)O(1)O(1) extra space, excluding output buffers. The checker directly simulates all days in O(NX)O(NX)O(NX) time and O(N)O(N)O(N) space. Since , at most region updates are needed per input file.

Solution written by GPT

2
1≤k≤N−21 \leq k \leq N-21≤k≤N−2
k+1][2,k+1]
[2,k+1]
[1,3][1,3][1,3]
1,k+1,k+21,k+1,k+21,k+1,k+2
[2,k][2,k][2,k]
[1,k+2][1,k+2][1,k+2]
[2,k+1][2,k+1][2,k+1]
N
∑N≤5 000\sum N \leq 5\,000
∑N≤5000
25 000 00025\,000\,00025000000