Submission #48406875
Source Code Expand
import itertools
import os
import sys
from typing import List
sys.setrecursionlimit(210000)
if os.getenv('TEST'):
def eprint(*args, **kwargs):
print('[\033[31mEPRINT\033[0m]', *args, file=sys.stderr, **kwargs)
else:
def eprint(*args, **kwargs):
pass
def main() -> None:
H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
B = [list(map(int, input().split())) for _ in range(H)]
candidates = []
for r in itertools.permutations(range(H)):
for c in itertools.permutations(range(W)):
if all(A[r[i]][c[j]] == B[i][j] for i in range(H) for j in range(W)):
candidates.append((r, c))
for r, c in candidates:
eprint(r, c)
if len(candidates) == 0:
print(-1)
return
min_move = 1_000_000_000
for r, c in candidates:
move = sum(int(r[i] > r[j]) for i in range(H) for j in range(i + 1, H))
move += sum(int(c[i] > c[j]) for i in range(W) for j in range(i + 1, W))
min_move = min(min_move, move)
print(min_move)
if __name__ == '__main__':
main()
Submission Info
| Submission Time | |
|---|---|
| Task | D - Swapping Puzzle |
| User | takedarts |
| Language | Python (PyPy 3.10-v7.3.12) |
| Score | 425 |
| Code Size | 1131 Byte |
| Status | AC |
| Exec Time | 211 ms |
| Memory | 90272 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 425 / 425 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | example0.txt, example1.txt, example2.txt, example3.txt |
| All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, example0.txt, example1.txt, example2.txt, example3.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 000.txt | AC | 114 ms | 84588 KiB |
| 001.txt | AC | 117 ms | 84864 KiB |
| 002.txt | AC | 146 ms | 87568 KiB |
| 003.txt | AC | 116 ms | 84504 KiB |
| 004.txt | AC | 116 ms | 84688 KiB |
| 005.txt | AC | 116 ms | 84700 KiB |
| 006.txt | AC | 209 ms | 90164 KiB |
| 007.txt | AC | 208 ms | 90256 KiB |
| 008.txt | AC | 209 ms | 90132 KiB |
| 009.txt | AC | 114 ms | 84628 KiB |
| 010.txt | AC | 131 ms | 86756 KiB |
| 011.txt | AC | 136 ms | 86744 KiB |
| 012.txt | AC | 133 ms | 86664 KiB |
| 013.txt | AC | 115 ms | 84640 KiB |
| 014.txt | AC | 127 ms | 86228 KiB |
| 015.txt | AC | 127 ms | 86660 KiB |
| 016.txt | AC | 130 ms | 86744 KiB |
| 017.txt | AC | 117 ms | 84892 KiB |
| 018.txt | AC | 122 ms | 86124 KiB |
| 019.txt | AC | 123 ms | 85784 KiB |
| 020.txt | AC | 122 ms | 85684 KiB |
| 021.txt | AC | 115 ms | 84824 KiB |
| 022.txt | AC | 210 ms | 90272 KiB |
| 023.txt | AC | 211 ms | 90088 KiB |
| 024.txt | AC | 209 ms | 90100 KiB |
| 025.txt | AC | 129 ms | 85616 KiB |
| 026.txt | AC | 132 ms | 86752 KiB |
| 027.txt | AC | 131 ms | 86560 KiB |
| 028.txt | AC | 130 ms | 86536 KiB |
| 029.txt | AC | 116 ms | 84484 KiB |
| 030.txt | AC | 126 ms | 85808 KiB |
| 031.txt | AC | 129 ms | 86780 KiB |
| 032.txt | AC | 128 ms | 86704 KiB |
| 033.txt | AC | 115 ms | 84648 KiB |
| 034.txt | AC | 122 ms | 85868 KiB |
| 035.txt | AC | 123 ms | 85948 KiB |
| 036.txt | AC | 123 ms | 85724 KiB |
| 037.txt | AC | 115 ms | 84644 KiB |
| example0.txt | AC | 119 ms | 85804 KiB |
| example1.txt | AC | 114 ms | 84932 KiB |
| example2.txt | AC | 116 ms | 84600 KiB |
| example3.txt | AC | 123 ms | 85620 KiB |