size = input().split() n = int(size[0]) m = int(size[1]) tab = [] for i in range(n): line = input() row = [] for letter in line: row.append(letter) tab.append(row) #tab.append(['A','A','P','A','A']) #tab.append(['A','P','P','A','A']) #tab.append(['A','A','P','A','A']) #tab.append(['A','A','P','A','A']) #tab.append(['A','P','P','P','A']) moves = [] iter = 0 is_all_empty = False while iter <= m + n and is_all_empty == False: #rows for i in range(n): is_all_the_same = True first_not_empty = '' for j in range(m): if tab[i][j] != '' and first_not_empty == '': first_not_empty = tab[i][j] if tab[i][j] != first_not_empty and tab[i][j] != '': is_all_the_same = False break if is_all_the_same == True and first_not_empty != '': moves.append('R ' + str(i+1) + ' ' + first_not_empty) iter += 1 for k in range(m): tab[i][k] = '' #columns for i in range(m): is_all_the_same = True first_not_empty = '' for j in range(n): if tab[j][i] != '' and first_not_empty == '': first_not_empty = tab[j][i] if tab[j][i] != first_not_empty and tab[j][i] != '': is_all_the_same = False break if is_all_the_same == True and first_not_empty != '': moves.append('K ' + str(i+1) + ' ' + first_not_empty) iter += 1 for k in range(n): tab[k][i] = '' is_all_empty = True for i in range(m): for j in range(n): if tab[j][i] != '': is_all_empty = False break print(iter) for move in range(len(moves)): print(moves[len(moves) - 1 - move])
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | size = input().split() n = int(size[0]) m = int(size[1]) tab = [] for i in range(n): line = input() row = [] for letter in line: row.append(letter) tab.append(row) #tab.append(['A','A','P','A','A']) #tab.append(['A','P','P','A','A']) #tab.append(['A','A','P','A','A']) #tab.append(['A','A','P','A','A']) #tab.append(['A','P','P','P','A']) moves = [] iter = 0 is_all_empty = False while iter <= m + n and is_all_empty == False: #rows for i in range(n): is_all_the_same = True first_not_empty = '' for j in range(m): if tab[i][j] != '' and first_not_empty == '': first_not_empty = tab[i][j] if tab[i][j] != first_not_empty and tab[i][j] != '': is_all_the_same = False break if is_all_the_same == True and first_not_empty != '': moves.append('R ' + str(i+1) + ' ' + first_not_empty) iter += 1 for k in range(m): tab[i][k] = '' #columns for i in range(m): is_all_the_same = True first_not_empty = '' for j in range(n): if tab[j][i] != '' and first_not_empty == '': first_not_empty = tab[j][i] if tab[j][i] != first_not_empty and tab[j][i] != '': is_all_the_same = False break if is_all_the_same == True and first_not_empty != '': moves.append('K ' + str(i+1) + ' ' + first_not_empty) iter += 1 for k in range(n): tab[k][i] = '' is_all_empty = True for i in range(m): for j in range(n): if tab[j][i] != '': is_all_empty = False break print(iter) for move in range(len(moves)): print(moves[len(moves) - 1 - move]) |