Problem:


Score : 400 points

Problem Statement

In this problem, we only consider strings consisting of lowercase English letters.

Strings s and t are said to be isomorphic when the following conditions are satisfied:

|s| = |t| holds.

For every pair i, j, one of the following holds:

s_i = s_j and t_i = t_j.

s_i \neq s_j and t_i \neq t_j.

For example, abcac and zyxzx are isomorphic, while abcac and ppppp are not.

A string s is said to be in normal form when the following condition is satisfied:

For every string t that is isomorphic to s, s \leq t holds. Here \leq denotes lexicographic comparison.

For example, abcac is in normal form, but zyxzx is not since it is isomorphic to abcac, which is lexicographically smaller than zyxzx.

You are given an integer N.
Print all strings of length N that are in normal form, in lexicographically ascending order.

Constraints

1 \leq N \leq 10

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N

Output

Assume that there are K strings of length N that are in normal form: w_1, \ldots, w_K in lexicographical order.
Output should be in the following format:

w_1
:
w_K

Sample Input 1

1

Sample Output 1

a

Sample Input 2

2

Sample Output 2

aa
ab



Sample input:
1


Sample output:
a

Submission status: Wrong Answer

Solution code:
S = "abcdefghijklmnop"


def main():

    N = int(input())

    if N == 1:
        for i in range(1):
            print(S[i])

    elif N == 2:
        for i in range(1):
            for j in range(i + 2):
                print(S[i] + S[j])

    elif N == 3:
        for i in range(1):
            for j in range(i + 2):
                for k in range(j + 2):
                    print(S[i] + S[j] + S[k])

    elif N == 4:
        for i in range(1):
            for j in range(i + 2):
                for k in range(j + 2):
                    for l in range(k + 2):
                        print(S[i] + S[j] + S[k] + S[l])

    elif N == 5:
        for i in range(1):
            for j in range(i + 2):
                for k in range(j + 2):
                    for l in range(k + 2):
                        for m in range(l + 2):
                            print(S[i] + S[j] + S[k] + S[l] + S[m])

    elif N == 6:
        for i in range(1):
            for j in range(i + 2):
                for k in range(j + 2):
                    for l in range(k + 2):
                        for m in range(l + 2):
                            for n in range(m + 2):
                                print(S[i] + S[j] + S[k] + S[l] + S[m] + S[n])

    elif N == 7:
        for i in range(1):
            for j in range(i + 2):
                for k in range(j + 2):
                    for l in range(k + 2):
                        for m in range(l + 2):
                            for n in range(m + 2):
                                for o in range(n + 2):
                                    print(S[i] + S[j] + S[k] + S[l] + S[m] +
                                          S[n] + S[o])

    elif N == 8:
        for i in range(1):
            for j in range(i + 2):
                for k in range(j + 2):
                    for l in range(k + 2):
                        for m in range(l + 2):
                            for n in range(m + 2):
                                for o in range(n + 2):
                                    for p in range(o + 2):
                                        print(S[i] + S[j] + S[k] + S[l] +
                                              S[m] + S[n] + S[o] + S[p])

    elif N == 9:
        for i in range(1):
            for j in range(i + 2):
                for k in range(j + 2):
                    for l in range(k + 2):
                        for m in range(l + 2):
                            for n in range(m + 2):
                                for o in range(n + 2):
                                    for p in range(o + 2):
                                        for q in range(p + 2):
                                            print(S[i] + S[j] + S[k] + S[l] +
                                                  S[m] + S[n] + S[o] + S[p] +
                                                  S[q])

    elif N == 10:
        for i in range(1):
            for j in range(i + 2):
                for k in range(j + 2):
                    for l in range(k + 2):
                        for m in range(l + 2):
                            for n in range(m + 2):
                                for o in range(n + 2):
                                    for p in range(o + 2):
                                        for q in range(p + 2):
                                            for r in range(q + 2):
                                                print(S[i] + S[j] + S[k] +
                                                      S[l] + S[m] + S[n] +
                                                      S[o] + S[p] + S[q] +
                                                      S[r])


main()

Submission status: Wrong Answer

Solution code:
n=int(input())
ag='aaaaaaaaaa'
ainit=ag[0:n]
alist=[]
alpha=['a','b','c','d','e','f','g','h','i','j']
if n==1:
    print(ainit)
else:
    print(ainit)
    ainit2=ainit[0:n-1]+'b'
    print(ainit2)
    alist.append(ainit2)
    for i in range(n-2):
        alistc=alist
        alist=[]
        for j in range(len(alistc)):
            s=alistc[j][1:n]
            #print(s)
            for k in range(i+2):
                sout=s+alpha[k]
                print(sout)
                alist.append(sout)

Submission status: Wrong Answer

Solution code:
N = int(input())
done = 0
res = set()
pool = list('abcdefghijklmnopqrstuvwxyz')


def make_string(done):
    parent = [-1] * N

    def find(x):
        if parent[x] == -1:
            return x
        else:
            res = parent[x] = find(parent[x])
            return res

    def union(x, y):
        x = find(x)
        y = find(y)
        if x != y:
            parent[x] = y
    for x in range(N ** 2 // 2 + 1):
        if done & (1 << x):
            i, j = divmod(x, N)
            union(i, j)
    string = [None] * N
    j = 0
    for i in range(N):
        if string[find(i)] is None:
            string[i] = pool[j]
            string[find(i)] = pool[j]
            j += 1
    res = []
    for s in string:
        if s:
            res.append(s)
        else:
            res.append(pool[j])
            j += 1
    return ''.join(res)


def dp(done, memo={}):
    if done in memo:
        return
    elif done == (1 << (N ** 2)) - 1:
        return
    else:
        res.add(make_string(done))
        for i in range((N ** 2) // 2 + 1):
            if done & (1 << i):
                continue
            else:
                memo[done] = True
                dp(done | (1 << i), memo)


dp(0)
for x in sorted(list(res)):
    print(x)

Submission status: Wrong Answer

Solution code:
import copy
N=int(input())
ans = [0]

if N > 1:
  ans1 = []
  a = max(ans)+1
  for i in range(a+1):
    c = copy.copy(ans)
    c.append(i)
    ans1.append(c)
    
if N > 2:
  ans2 = []
  for j in range(len(ans1)):
    a = max(ans1[j])+1
    for i in range(a+1):
      c = copy.copy(ans1[j])
      c.append(i)
      ans2.append(c)

if N > 3:
  ans3 = []
  for j in range(len(ans2)):
    a = max(ans2[j])+1
    for i in range(a+1):
      c = copy.copy(ans2[j])
      c.append(i)
      ans3.append(c)
      

if N > 4:
  ans4 = []
  for j in range(len(ans3)):
    a = max(ans3[j])+1
    for i in range(a+1):
      c = copy.copy(ans3[j])
      c.append(i)
      ans4.append(c)


if N > 5:
  ans5 = []
  for j in range(len(ans4)):
    a = max(ans4[j])+1
    for i in range(a+1):
      c = copy.copy(ans4[j])
      c.append(i)
      ans5.append(c)

      
if N > 6:
  ans6 = []
  for j in range(len(ans5)):
    a = max(ans5[j])+1
    for i in range(a+1):
      c = copy.copy(ans5[j])
      c.append(i)
      ans6.append(c)

if N > 7:
  ans7 = []
  for j in range(len(ans6)):
    a = max(ans6[j])+1
    for i in range(a+1):
      c = copy.copy(ans6[j])
      c.append(i)
      ans7.append(c)

if N > 8:
  ans8 = []
  for j in range(len(ans7)):
    a = max(ans7[j])+1
    for i in range(a+1):
      c = copy.copy(ans7[j])
      c.append(i)
      ans8.append(c)

if N > 9:
  ans9 = []
  for j in range(len(ans8)):
    a = max(ans8[j])+1
    for i in range(a+1):
      c = copy.copy(ans8[j])
      c.append(i)
      ans9.append(c)
      

aaa = "abcdefghij"
if N == 1:
  print("a")    
    
elif N ==2:
  for i in ans1:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==3:
  for i in ans2:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==4:
  for i in ans3:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==5:
  for i in ans4:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==5:
  for i in ans1:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==7:
  for i in ans6:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==8:
  for i in ans7:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==9:
  for i in ans8:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
    
elif N ==10:
  for i in ans9:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)

Submission status: Wrong Answer

Solution code:
n = int(input())
if n == 1:
  hoge = ["a"]
  for i in range(len(hoge)):
    print(i)
if n == 2:
  hoge = ["aa", "ab"]
  for i in range(len(hoge)):
    print(i)
if n == 3:
  hoge = []
  for a in ["a", "b", "c"]:
    for b in ["b", "c"]:
      for c in ["c"]:
        hoge.append(a + b + c)
  hoge.sort()
  for i in range(len(hoge)):
    print(i)

if n == 4:
  hoge = []
  for a in ["a", "b", "c", "d"]:
    for b in ["b", "c", "d"]:
      for c in ["c", "d"]:
        for d in ["d"]:
          hoge.append(a + b + c + d)
  hoge.sort()
  for i in range(len(hoge)):
    print(i)

Submission status: Wrong Answer

Solution code:
num = int(input())
base = ["a","b","c","d","e","f","g","h","j","k"]

if num == 1:
  print("a")
elif num == 2:
  print("aa")
  print("ab")
elif num == 3:
  print("aaa")
  print("aab")
  print("aba")
  print("abb")
  print("abc")
elif num == 4:
  print("aaaa")
  print("aaab")
  print("aaba")
  print("aabb")
  print("aabc")
  print("abaa")
  print("abab")
  print("abac")
  print("abba")
  print("abbb")
  print("abbc")
  print("abca")
  print("abcb")
  print("abcc")
  print("abcd")

Submission status: Wrong Answer

Solution code:
n=int(input())

A=["aa","ab"]
num2alpha = lambda c: chr(c+64)
B=[]
num2alpha(3)
if n==1:
	print("a")
	exit()
if n==2:
	print("aa")
	print("ab")
	exit()

for i in range(n-2):
	k=i+3
	for s in A:
		B.append(s+"a")
		B.append(s+"b")
		if s[-1]!= "a":
			B.append(s+chr(ord(s[-1])+1))
	A=A+B
	B=[]
for x in A:
	if len(x)==n:
		print(x)

Submission status: Wrong Answer

Solution code:
n = int(input())

L =  [[[] for i in range(10)] for j in range(10)]
#print(L)
L[0][0].append('a')
#print(L[0])
for i in range(1, n):
    for j in range(10):
        if j == 0:
            t = chr(j + ord('a'))
            for c in L[i-1][j]:
                print(i, j)
                L[i][j].append(c+t)
        else:
            t = chr(j + ord('a'))
            for c in L[i-1][j-1]:
                L[i][j].append(c+t)
            for c in L[i-1][j]:
                L[i][j].append(c+t)
#print(L)

ans = []
for i in range(10):
    for c in L[n-1][i]:
        ans.append(c)
ans.sort()
for c in ans:
    print(c)