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 account linking.

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

Dadas Predictor

Back to problem

Editorial

Store the given words, then read SSS. Compare each word WiW_iWi​ with SSS. Print YES if any comparison succeeds, or NO if no word is equal to SSS.

Two words are equal exactly when their lengths are equal and their characters agree at every position. First compare the lengths, then compare the characters only when the lengths match. A string equality operator checks the same condition. Repeated words do not affect the result.

Including the time to read and store the words, the time complexity is O(∑i=1NLi+N+K)O(\sum_{i=1}^{N}L_i+N+K)O(∑i=1N​Li​+N+, and the space complexity is .

Proof

If the algorithm prints YES, it has found an index iii for which WiW_iWi​ and SSS have the same length and the same character at every position. Hence, SSS is one of the words dadas08 can say.

Conversely, if dadas08 can say , then for some index . Comparing all the words necessarily finds this equality and prints . Therefore, printing when every comparison fails is also correct.

Solution written by GPT6

K)
O(∑i=1NLi+K)O(\sum_{i=1}^{N}L_i+K)O(∑i=1N​Li​+K)
SS
S
Wi=SW_i=SWi​=S
iii
YES
NO