QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#334474 | #2956. Statues | mfshi03 | WA | 18ms | 10620kb | Python3 | 1.9kb | 2024-02-22 00:03:33 | 2024-02-22 00:03:34 |
Judging History
answer
from collections import Counter
m, n = tuple(map(int, input().split()))
matrix = []
for i in range(m):
matrix.append(list(map(int, input().split())))
diag1 = []
diag2 = []
start1 = [(i, 0) for i in range(0, m)]
start1.extend([(m - 1, j) for j in range(1, n)])
start2 = [(i, n - 1) for i in range(0, m)]
start2.extend([(m - 1, n - 1 - j) for j in range(1, n)])
alln = []
for t in start1:
i, j = t[0], t[1]
temp = []
while i >= 0 and j < n:
if matrix[i][j] != -1:
alln.append(matrix[i][j])
temp.append(matrix[i][j])
i -= 1
j += 1
diag1.append(temp)
for t in start2:
i, j = t[0], t[1]
temp = []
while j >= 0 and i >= 0:
if matrix[i][j] != -1:
temp.append(matrix[i][j])
i -= 1
j -= 1
diag2.append(temp)
c1 = sorted(alln)
c2 = sorted(alln)
d1_asc = 0
d1_desc = 0
d2_asc = 0
d2_desc = 0
for d in diag1:
s = len(d)
desc = Counter(c2[-s+1:])
asc = Counter(c1[:s])
move1 = 0
move2 = 0
for v in d:
if v in asc:
asc[v] -= 1
if v in desc:
desc[v] -= 1
for v in asc:
move1 += asc[v]
for v in desc:
move2 += desc[v]
d1_asc += move1
d1_desc += move2
c2 = c2[:-s+1]
c1 = c1[s:]
c1 = sorted(alln)
c2 = sorted(alln)
for d in diag2:
s = len(d)
desc = Counter(c2[-s+1:])
asc = Counter(c1[:s])
move1 = 0
move2 = 0
for v in d:
if v in asc:
asc[v] -= 1
if v in desc:
desc[v] -= 1
for v in asc:
move1 += asc[v]
for v in desc:
move2 += desc[v]
d2_asc += move1
d2_desc += move2
c2 = c2[:-s+1]
c1 = c1[s:]
#print(d1_asc, d1_desc, d2_asc, d2_desc)
print(min(d1_asc, d1_desc, d2_asc, d2_desc))
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 18ms
memory: 10620kb
input:
50 50 9946 213 7427 7298 9772 2466 4890 2062 2490 1538 5605 4546 5426 2974 7693 5133 206 1329 7853 5669 8991 8828 1006 808 2227 1878 8900 8948 2755 8784 2564 5954 348 1718 2880 5820 7112 8161 4337 7247 5447 7465 1280 7708 1567 6280 129 9961 5758 9546 6412 3445 7559 7648 3160 3649 2388 7527 1800 4392...
output:
2466
result:
ok single line: '2466'
Test #2:
score: -100
Wrong Answer
time: 13ms
memory: 10440kb
input:
50 50 9711 1938 4236 1965 4256 3579 7882 3432 4879 2623 8535 4292 9663 1737 4394 3897 73 429 1926 6010 759 7172 824 7860 8172 1010 2096 3107 95 8163 7594 4420 6514 3476 1224 8069 5763 3423 5854 937 2430 3518 4441 5735 9292 3440 1772 8594 9373 809 2473 4660 6862 595 1481 2211 3078 3507 8664 3429 2275...
output:
2461
result:
wrong answer 1st lines differ - expected: '2458', found: '2461'