結果
問題 | No.585 工夫のないパズル |
ユーザー | Sebastian King |
提出日時 | 2023-12-03 01:25:05 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 60 ms / 2,000 ms |
コード長 | 3,822 bytes |
コンパイル時間 | 389 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 54,912 KB |
最終ジャッジ日時 | 2024-09-26 21:53:22 |
合計ジャッジ時間 | 2,347 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 49 ms
54,656 KB |
testcase_01 | AC | 50 ms
54,784 KB |
testcase_02 | AC | 49 ms
54,784 KB |
testcase_03 | AC | 49 ms
54,400 KB |
testcase_04 | AC | 60 ms
54,528 KB |
testcase_05 | AC | 50 ms
54,912 KB |
testcase_06 | AC | 51 ms
54,784 KB |
testcase_07 | AC | 49 ms
54,528 KB |
testcase_08 | AC | 50 ms
54,528 KB |
testcase_09 | AC | 50 ms
54,656 KB |
testcase_10 | AC | 58 ms
54,656 KB |
testcase_11 | AC | 56 ms
54,400 KB |
testcase_12 | AC | 55 ms
54,016 KB |
testcase_13 | AC | 55 ms
54,272 KB |
testcase_14 | AC | 55 ms
54,528 KB |
ソースコード
import copy def flip_board(n, m, source_board): target_board = [[source_board[i][j] for i in range(n)] for j in range(m)] return target_board def loopover(mixed_up_board, solved_board): n = len(solved_board) m = len(solved_board[0]) is_flip = False if m % 2 == 1: is_flip = True mixed_up_board = flip_board(n, m, mixed_up_board) solved_board = flip_board(n, m, solved_board) n, m = m, n alpha_mapping = {} for i in range(n): for j in range(m): alpha_mapping[solved_board[i][j]] = (i, j) for i in range(n): for j in range(m): mixed_up_board[i][j] = alpha_mapping[mixed_up_board[i][j]] res = [] flip_dir = {'L': 'U', 'U': 'L', 'R': 'D', 'D': 'R'} def Move(dir, idx): if dir == 'L': mixed_up_board[idx] = mixed_up_board[idx][1:] + [mixed_up_board[idx][0]] elif dir == 'R': mixed_up_board[idx] = [mixed_up_board[idx][-1]] + mixed_up_board[idx][:-1] elif dir == 'U': tmp_v = mixed_up_board[0][idx] for o in range(1, n): mixed_up_board[o - 1][idx] = mixed_up_board[o][idx] mixed_up_board[n - 1][idx] = tmp_v else: tmp_v = mixed_up_board[n - 1][idx] for o in range(n - 1, 0, -1): mixed_up_board[o][idx] = mixed_up_board[o - 1][idx] mixed_up_board[0][idx] = tmp_v if is_flip: dir = flip_dir[dir] res.append(dir + str(idx)) def FancyMove(dir, idx): p = (idx + m - 2) % m q = (p + 1) % m r = idx invdir = 'R' if dir == 'L' else 'L' Move('U', p) Move(dir, n - 1) Move('D', p) Move(dir, n - 1) Move('U', p) Move(invdir, n - 1) Move(invdir, n - 1) Move('D', p) for i in range(n - 1): for j in range(m): x, y = i, j for k in range(i, n): for l in range(m): if mixed_up_board[k][l] == (i, j): x, y = k, l if (x, y) == (i, j): continue if x == i: Move('D', y) Move('R', x + 1) Move('U', y) x = i + 1 y = (y + 1) % m if y == j: Move('L', x) y = (y + m - 1) % m dcnt = x - i for k in range(dcnt): Move('D', j) while y != j: Move('R', x) y = (y + 1) % m for k in range(dcnt): Move('U', j) if m == 2: if mixed_up_board[n - 1][0] != (n - 1, 0): Move('R', n - 1) else: i = n - 1 for j in range(m - 2): y = j for l in range(j, m): if mixed_up_board[i][l] == (i, j): y = l break if y == j: continue while y > j + 1: FancyMove('L', y) y -= 2 if y == j + 1: FancyMove('L', (j + 2) % m) FancyMove('L', (j + 2) % m) j = m - 2 if mixed_up_board[i][j] == (i, j): pass else: if m % 2 == 1: res = None else: while j != 0: FancyMove('L', j) j -= 2 Move('L', n - 1) bres = res r2 = [] for x in res: if x[0] == 'D': r2.append(['C', int(x[1]), 1]) elif x[0] == 'U': r2.append(['C', int(x[1]), 3]) elif x[0] == 'L': r2.append(['R', int(x[1]), 3]) elif x[0] == 'R': r2.append(['R', int(x[1]), 1]) res = [copy.copy(r2[0])] for i in range(1, len(r2)): if r2[i][0] == res[-1][0] and r2[i][1] == res[-1][1]: res[-1][2] = (res[-1][2] + r2[i][2]) % 4 else: while res[-1][2] == 0: res = res[:-1] res.append(copy.copy(r2[i])) while res[-1][2] == 0: res = res[:-1] return res source_ = list(map(list, ['FHLE','MOIC','DNPB','KAGJ'])) target_ = list(map(list, ['ABCD','EFGH','IJKL','MNOP'])) source_ = [] for i in range(4): source_.append(input()) source_ = list(map(list, source_)) # print(source_) res = loopover(source_, target_) print(len(res)) for x in res: print(x[0], x[1], x[2])