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:
# Code for D - String Equivalence
# Use input() to fetch data from STDIN
n = int(input())
a = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']

def d(x):
    return a[:x+1]

def s(level, count):
    if level == 1:
        return d(count)

    array = []
    for z in range(count+1):
        array.extend([a[z] + y for y in s(level - 1, z + 1)])
    return array

result = s(n, 0)
result.sort()
for x in result:
    print(x)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = [[] for _ in range(10)]
d[0].append(1)
mx = 2
for i in range(1, n):
    prev = d[i-1]
    for j in range(mx):
        for ip in prev:
            sip = str(ip)
            aip = str(ip) + str(j+1)
            d[i].append(int(aip))
    mx += 1
alpa = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
for idx in d[n-1]:
    tg = list(str(idx))
    l_ans = [alpa[int(i)-1] for i in tg]
    ans = ""
    for l in l_ans:
        ans += l
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)


N = int(input())
ans = []
a = ord('a')


def f(c, A, done):
    global N, a
    if done == N:
        ans.append(''.join(A))
    else:
        B = list(A)
        idx = B.index(0, 0)
        B[idx] = c
        tdone = done + 1
        for i in range(2 ** (N - tdone) - 1, -1, -1):
            k = i
            C = B[:]
            nDone = tdone
            idx = 0
            while k > 0:
                if k & 1 == 1:
                    idx = C.index(0, idx + 1)
                    C[idx] = c
                    nDone += 1
                k >>= 1
            f(chr(ord(c) + 1), tuple(C), nDone)


A = [0] * N
f('a', tuple(A), 0)
ans.sort()
print(*ans, sep='\n')

Submission status: Wrong Answer

Solution code:
import itertools
import sys

n = int(input())
S = ['a']*n
while True:
    print("".join(S))
    for i in range(n-1,0,-1):
        if(S[i-1]>=S[i]):
            S[i] = chr(ord(S[i])+1)
            for j in range(i+1,n):
                S[j] = 'a'
            break
    else:
        break

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n=int(input())

al=[chr(ord('a') + i) for i in range(26)]

l=[0]*n

def judge(a,b):
  n=len(a)
  for i in  range(n-1):
    for j in range(i+1,n):
      if (a[i]==a[j] and b[i]==b[j]) or (a[i]!=a[j] and b[i]!=b[j]):
        pass
      else:
        return False
  return True

prev=defaultdict(list)
prev[1]=al
prev[2]=['aa','ab']
if n==1:
  print('a')
elif n==2:
  print('aa')
  print('ab')
        
else:
  for i in range(2,6):  # range(2,10)とすべきだが間に合わない
    for s in al:
      for char in prev[i]:
        new_s=char+s
        check=0
        for char2 in prev[i+1]:
          if check==1:
            break
          if judge(new_s,char2):
            check=1
            l=sorted([new_s,char2])
            if l[0] in prev[i+1]:
              pass
            else:
              prev[i+1].append(l[0])
              prev[i+1].remove(l[1])
        if check==0:
          prev[i+1].append(new_s)
  l=sorted(prev[n])
  for i in range(len(l)):
    print(l[i])

Submission status: Wrong Answer

Solution code:
n = int(input())
d = [[] for _ in range(10)]
d[0].append(1)
mx = 2
for i in range(1, n):
    prev = d[i-1]
    for j in range(mx):
        for ip in prev:
            sip = str(ip)
            aip = str(ip) + str(j+1)
            d[i].append(int(aip))
alpa = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
for idx in d[n-1]:
    tg = list(str(idx))
    l_ans = [alpa[int(i)-1] for i in tg]
    ans = ""
    for l in l_ans:
        ans += l
    print(ans)

Submission status: Wrong Answer

Solution code:
def cur(n):
    if ans[n]!=[]: return ans[n]
    for x in cur(n-1):
        tmp1=[0]+[x[i] for i in range(n-1)]
        tmp2=[0]+[x[i]+1 for i in range(n-1)]
        ans[n].append(tmp1)
        ans[n].append(tmp2)
        if sum(x)!=0:
            for k in range(1,max(x)+1):
                tmp3=[0]+[x[i] for i in range(n-1)]
                for i in range(1,n):
                    if tmp3[i]>k: tmp3[i]-=1
                    elif tmp3[i]==k: tmp3[i]=0
                    else: tmp3[i]+=1
                ans[n].append(tmp3)

    return ans[n]


n=int(input())
ans=[[] for i in range(11)]
ans[1]=[[0]]
ans[2]=[[0,0],[0,1]]
cur(n)
ans[n].sort()

for x in ans[n]:
    s=""
    for i in range(n):
        s+=chr( ord("a")+x[i] )
    print(s)

Submission status: Wrong Answer

Solution code:
import string
alphabet=string.ascii_lowercase

N=int(input())

S=[[] for i in range(N+1)]

S[1].append("a")
for n in range(2,N+1):
    for i in range(len(S[n-1])):
        ikkomae=S[n-1][i]
        #あるものをたす
        list_mozi=list(ikkomae)
        list_mozi=list(dict.fromkeys(list_mozi))
        # print(list_mozi)
        tmp1=ikkomae
        for j in range(len(list_mozi)):
            tmp1=ikkomae+list_mozi[j]
            # print(tmp1)
            S[n].append(tmp1)
        #ないものを足す
        tmp2=ikkomae
        tmp2=tmp2+alphabet[len(list_mozi)]
        # print(tmp2)
        S[n].append(tmp2)

for i in range(len(S[N])):
    print(S[N][i])

Submission status: Wrong Answer

Solution code:
def resolve():
    n = int(input())
    alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
    strlist =[[]*10 for _ in range(n)]
    strlist[0] = ["0"]
    for i in range(1,n):
        for j in range(int(len(strlist[i-1]))):
            test = str(strlist[i-1][j])
            add = 0
            while add <= int(test[-1])+1:
                strlist[i].append(test + str(add))
                add += 1
    ans = strlist[n-1]
    for i in range(len(ans)):
        output = []
        for j in range(len(ans[0])):
            output.append(alphabet[int(ans[i][j])])
        print("".join(output))
resolve()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
def solv1():
    n=int(input())
    
    a=[[]for i in range(n)]
    a[0]=[[0]]
    
    for i in range(n-1):
        b=[]
        for pa in a[i]:
    #        print(pa)
            el=[j for j in set(pa)]
    #        print(el)
            el.append(max(pa)+1)
            for l in el:
                b+=[pa+[l]]
    #    print(i,b)
        a[i+1]=b
    ans=[]
    for i in a:
        ans+=i
        #print(i)
    ans=sorted(ans)
    for i in ans:
        print(''.join([chr(j+97) for j in i]))

solv1()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n = int(input())
k = n
D = {}
a ,b , c, d, e, f, g, h, i, j = 'a','b','c','d','e','f','g','h','i','j'
D[1] = [a]
D[2]= [a,b]
D[3] = [a,b,c]
D[4] = [a,b,c,d]
D[5] = [a,b,c,d,e]
D[6] = [a,b,c,d,e,f]
D[7] = [a,b,c,d,e,f,g]
D[8] = [a,b,c,d,e,f,g,h]
D[9] = [a,b,c,d,e,f,g,h,i]
D[10] = [a,b,c,d,e,f,g,h,i,j]

dic = defaultdict(list)
for i in range(n):
    if i+1 == 1:
        s = 'a'
        dic[i+1] = s
    else:
        for j in dic[i]:
            for k in D[i+1]:
                dic[i+1].append(j+k)

    for i in dic[n]:
        print(i)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**9)
l = []
def calc3(s, N):
    if len(s) == N:
        print(s)
        l.append(s)
        return
    if len(s) > 0:
        c = s[-1]
        s2 = s[:]
        z = ord(c) - ord('a') + 2
        for i in range(z):
            st = s[:]
            st += chr(ord('a')+i)
            calc3(st[:], N)
    else:
        c = 'a'
        s += chr(ord(c))
        calc3(s[:], N)
def main():
    N = int(input())
    s = ''
    calc3(s[:], N)
main()