Submission #24328077
Source Code Expand
import itertools
h, w, c = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(h)]
p = itertools.product(range(h), range(w))
b = []
for x, y in p:
b += [[a[x][y], x, y]]
sb = sorted(b)
res = 4 * 10 ** 12
for s in range(h * w - 1):
for t in range(s + 1, h * w):
tmp = sb[s][0] + sb[t][0]
tmp += c * (abs(sb[s][1] - sb[t][1]) + abs(sb[s][2] - sb[t][2]))
if tmp < res:
res = tmp
elif tmp > c * (h + w):
# print('break')
break
print(res)
Submission Info
| Submission Time | |
|---|---|
| Task | D - National Railway |
| User | cubesat |
| Language | PyPy3 (7.3.0) |
| Score | 0 |
| Code Size | 562 Byte |
| Status | TLE |
| Exec Time | 2213 ms |
| Memory | 215224 KiB |
Judge Result
| Set Name | Sample | All | ||||||
|---|---|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 0 / 400 | ||||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | example0.txt, example1.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, example0.txt, example1.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 000.txt | AC | 122 ms | 68320 KiB |
| 001.txt | AC | 67 ms | 68068 KiB |
| 002.txt | AC | 72 ms | 68292 KiB |
| 003.txt | AC | 72 ms | 68264 KiB |
| 004.txt | AC | 71 ms | 68292 KiB |
| 005.txt | AC | 74 ms | 68264 KiB |
| 006.txt | AC | 74 ms | 68168 KiB |
| 007.txt | AC | 922 ms | 69892 KiB |
| 008.txt | AC | 630 ms | 211896 KiB |
| 009.txt | TLE | 2213 ms | 215224 KiB |
| 010.txt | TLE | 2213 ms | 214848 KiB |
| 011.txt | TLE | 2213 ms | 214808 KiB |
| 012.txt | TLE | 2213 ms | 214924 KiB |
| 013.txt | TLE | 2213 ms | 215040 KiB |
| 014.txt | TLE | 2213 ms | 215004 KiB |
| 015.txt | TLE | 2213 ms | 214948 KiB |
| 016.txt | TLE | 2213 ms | 214796 KiB |
| 017.txt | TLE | 2213 ms | 214708 KiB |
| 018.txt | TLE | 2213 ms | 214752 KiB |
| 019.txt | TLE | 2213 ms | 214856 KiB |
| 020.txt | TLE | 2210 ms | 121888 KiB |
| 021.txt | TLE | 2210 ms | 133088 KiB |
| 022.txt | TLE | 2208 ms | 89164 KiB |
| 023.txt | TLE | 2208 ms | 88108 KiB |
| 024.txt | TLE | 2208 ms | 76624 KiB |
| 025.txt | AC | 63 ms | 62104 KiB |
| 026.txt | AC | 136 ms | 68900 KiB |
| 027.txt | AC | 148 ms | 69308 KiB |
| 028.txt | TLE | 2213 ms | 212032 KiB |
| 029.txt | TLE | 2213 ms | 213248 KiB |
| 030.txt | TLE | 2213 ms | 213216 KiB |
| 031.txt | TLE | 2213 ms | 213348 KiB |
| example0.txt | AC | 63 ms | 62084 KiB |
| example1.txt | AC | 54 ms | 62028 KiB |