problem AOR Ika wants to create a strong password that consists only of lowercase…
- User
problem
AOR Ika wants to create a strong password that consists only of lowercase letters. AOR Ika-chan, who was given an example of of dangerous passwords by a friend, decided to create a password that meets all of the following conditions.
- The length is at least one character.
- Different from any contiguous substring of any dangerous password.
- This is the shortest character string that meets the conditions 1 and 2.
- This is the character string that comes to the beginning when arranged in lexicographic order while satisfying the conditions 1, 2, and 3.
Write a program to generate a strong password on behalf of AOR Ika-chan. input
Input is given from standard input in the following format.
Assistant
import sys from itertools import product def main(): n = int(sys.stdin.readline()) S = [sys.stdin.readline().strip() for _ in range(n)] # Check for missing single character chars = set() for s in S: chars.update(s) if len(chars) < 26: for c in 'abcdefghijklmnopqrstuvwxyz': if c not in chars: print(c) return # Find minimal k lengths = [len(s) for s in S] k = 2 while True: sum_k = 0 for l in lengths: if l >= k: sum_k += (l - k + 1) if 26 ** k > sum_k: break k += 1 # Collect all k-length substrings substr_set = set() for s in S: for i in range(len(s) - k + 1): substr = s[i:i+k] substr_set.add(substr) # Generate lex smallest candidate for candidate in product('abcdefghijklmnopqrstuvwxyz', repeat=k): candidate_str = ''.join(candidate) if candidate_str not in substr_set: print(candidate_str) return if __name__ == "__main__": main()
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.