Created
March 15, 2026 01:44
-
-
Save maehrm/6f65ab9b013a75b37b1d75419d3d74d5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def get_lcp(str1, str2): | |
| ret = 0 | |
| for s1, s2 in zip(str1, str2): | |
| if s1 != s2: | |
| break | |
| ret += 1 | |
| return ret | |
| N = int(input()) | |
| S = [[input()] + [i] for i in range(N)] | |
| S.sort() # ソートして似た文字列で比較する | |
| ans = [0] * N | |
| for i in range(N - 1): | |
| s1, idx1 = S[i] | |
| s2, idx2 = S[i + 1] | |
| lcp = get_lcp(s1, s2) | |
| ans[idx1] = max(ans[idx1], lcp) | |
| ans[idx2] = max(ans[idx2], lcp) | |
| print("\n".join(map(str, ans))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment