QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#334476#2956. Statuesmfshi03WA 10ms10544kbPython31.9kb2024-02-22 00:06:582024-02-22 00:06:59

Judging History

你现在查看的是最新测评结果

  • [2024-02-22 00:06:59]
  • 评测
  • 测评结果:WA
  • 用时:10ms
  • 内存:10544kb
  • [2024-02-22 00:06:58]
  • 提交

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:])
    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:] 
    
assert len(c2) == 0
assert len(c1) == 0
#print(d1_asc, d1_desc, d2_asc, d2_desc)
print(min(d1_asc, d1_desc, d2_asc, d2_desc))

详细

Test #1:

score: 0
Wrong Answer
time: 10ms
memory: 10544kb

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:

1

result:

wrong answer 1st lines differ - expected: '2466', found: '1'