QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#334167#2956. Statuesmfshi03WA 16ms10224kbPython31.7kb2024-02-21 12:11:252024-02-21 12:11:26

Judging History

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

  • [2024-02-21 12:11:26]
  • 评测
  • 测评结果:WA
  • 用时:16ms
  • 内存:10224kb
  • [2024-02-21 12:11:25]
  • 提交

answer

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)])

#print(start1)
#print(start2)
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)

#print(diag1)
#print(diag2)

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 = set(c2[-s:])
    asc = set(c1[:s])

    move1 = s
    move2 = s
    for v in d:
        if v in asc:
            move1 -= 1 
        if v in desc:
            move2 -= 1 

    d1_asc += move1
    d1_desc += move2 

    c2 = c2[:-s]
    c1 = c1[s:]

c1 = sorted(alln)
c2 = sorted(alln)

for d in diag2:
    s = len(d)
    desc = set(c2[-s:])
    asc = set(c1[:s])

    move1 = s
    move2 = s
    for v in d:
        if v in asc:
            move1 -= 1 
        if v in desc:
            move2 -= 1 

    d2_asc += move1
    d2_desc += move2

    c2 = c2[:-s]
    c1 = c1[s:] 


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: 13ms
memory: 10184kb

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: 0
Accepted
time: 12ms
memory: 10184kb

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:

2458

result:

ok single line: '2458'

Test #3:

score: 0
Accepted
time: 12ms
memory: 10124kb

input:

50 50
5922 2303 8307 7745 4554 2369 2512 747 3347 6779 6952 3114 6768 5910 4358 4524 452 3370 5212 1721 3469 7412 6516 2769 1201 7653 2420 2075 6595 535 2525 8813 34 316 5904 5785 2207 6655 6062 1828 6280 5691 2027 322 5830 2778 2622 1453 79 2597
9400 1109 937 3051 8142 1793 4508 7661 6756 931 3875 ...

output:

2465

result:

ok single line: '2465'

Test #4:

score: 0
Accepted
time: 10ms
memory: 10224kb

input:

50 50
3899 4000 3573 2348 6892 8166 9845 7650 1533 7989 4832 1843 5536 5635 7278 3780 905 5743 4353 3262 9901 6617 8626 7337 9942 2206 9325 9588 2401 2476 3126 754 629 4676 4662 8590 3855 7917 9558 5855 7694 5124 9926 6726 4584 5329 4651 2676 4151 9286
7219 1049 3652 1889 6982 1703 238 320 5883 5269...

output:

2463

result:

ok single line: '2463'

Test #5:

score: 0
Accepted
time: 16ms
memory: 10120kb

input:

50 50
5816 2852 402 -1 1092 2198 8089 4041 973 2859 8152 6819 4643 3383 2703 7538 8434 2089 8019 -1 3020 9375 -1 6689 2153 4471 -1 -1 8138 -1 6371 145 5120 -1 860 -1 -1 3082 1138 8343 144 5318 5104 3003 1854 5155 4154 -1 6894 4546
-1 -1 -1 2424 -1 6176 6612 -1 9708 -1 8761 1794 8190 8864 1641 -1 515...

output:

1667

result:

ok single line: '1667'

Test #6:

score: 0
Accepted
time: 11ms
memory: 10224kb

input:

50 50
3034 -1 832 -1 -1 8832 4295 -1 -1 -1 6633 1519 593 -1 7211 -1 643 4929 6378 3389 9150 784 -1 1160 8328 8659 3153 -1 9407 7144 -1 -1 7802 -1 -1 -1 -1 9509 8975 7450 2930 9933 -1 9669 6096 6697 6718 -1 -1 -1
-1 -1 5514 6401 1678 1546 124 2380 1120 5646 -1 2247 -1 3356 9218 -1 411 112 -1 -1 9175 ...

output:

1625

result:

ok single line: '1625'

Test #7:

score: -100
Wrong Answer
time: 15ms
memory: 10100kb

input:

50 50
4644 6810 7319 -1 -1 -1 9778 9045 -1 489 5685 -1 9894 -1 3736 1901 -1 2356 3765 4457 1799 4343 6971 5374 2630 -1 8803 8856 7374 5802 -1 -1 7207 3728 1769 -1 2902 -1 2006 9139 7687 3651 7298 6342 8049 6209 2550 -1 3184 -1
7366 184 9391 5873 3627 -1 -1 -1 5757 2553 8108 9859 2513 1890 5078 -1 78...

output:

1651

result:

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