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

Last War Z

Back to problem

Editorial

Every uppercase letter must start a new word, so the split is unique.

Compare each complete word with the five designated words and record its presence in a bitmask. Process the final word too. Answer YES exactly when at least two bits are set. Substring matches and repeated occurrences are not distinct complete words.

Each character is examined a constant number of times: O(N)O(N)O(N) time, O(N)O(N)O(N) space including the input, and O(1)O(1)O(1) auxiliary space.

There is one full-constraints subtask. The separate naive implementation stores the words and uses a set to remove duplicates. It also passes the full task in O(N)O(N)O(N) time and O(N)O(N)O(N) space.

Solution written by GPT