結果

問題 No.1508 Avoid being hit
ユーザー trineutrontrineutron
提出日時 2021-05-14 23:54:52
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,561 bytes
コンパイル時間 246 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 59,488 KB
最終ジャッジ日時 2024-04-10 04:56:59
合計ジャッジ時間 21,118 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 747 ms
46,748 KB
testcase_01 AC 30 ms
11,008 KB
testcase_02 AC 30 ms
11,008 KB
testcase_03 AC 30 ms
11,008 KB
testcase_04 AC 29 ms
11,008 KB
testcase_05 AC 30 ms
11,008 KB
testcase_06 AC 29 ms
11,008 KB
testcase_07 AC 30 ms
11,008 KB
testcase_08 AC 29 ms
11,136 KB
testcase_09 AC 30 ms
11,008 KB
testcase_10 AC 30 ms
11,008 KB
testcase_11 AC 29 ms
11,136 KB
testcase_12 AC 29 ms
11,008 KB
testcase_13 AC 30 ms
11,136 KB
testcase_14 WA -
testcase_15 AC 30 ms
11,136 KB
testcase_16 AC 592 ms
43,924 KB
testcase_17 AC 326 ms
30,052 KB
testcase_18 AC 288 ms
27,720 KB
testcase_19 AC 478 ms
38,428 KB
testcase_20 AC 777 ms
54,312 KB
testcase_21 AC 485 ms
39,376 KB
testcase_22 AC 617 ms
46,392 KB
testcase_23 AC 683 ms
50,320 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 863 ms
50,316 KB
testcase_35 AC 104 ms
15,104 KB
testcase_36 AC 476 ms
33,268 KB
testcase_37 AC 217 ms
20,852 KB
testcase_38 AC 677 ms
42,692 KB
testcase_39 AC 442 ms
31,416 KB
testcase_40 AC 881 ms
52,192 KB
testcase_41 AC 494 ms
34,460 KB
testcase_42 AC 876 ms
52,556 KB
testcase_43 AC 1,041 ms
59,488 KB
testcase_44 WA -
testcase_45 AC 30 ms
11,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, q = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

segs = [None] * (q + 1)
segs[q] = [[0, 1], [n + 1, n + 2]]
for i in reversed(range(q)):
    segs[i] = []
    for j in range(len(segs[i + 1])):
        l, r = segs[i + 1][j]
        if 0 < l < n + 1 and (j == 0 or segs[i + 1][j - 1][1] != segs[i + 1][j][0]):
            l += 1
        if 1 < r < n + 2 and (j == len(segs[i + 1]) - 1 or segs[i + 1][j + 1][0] != segs[i + 1][j][1]):
            r -= 1
        if l < r:
            segs[i].append([l, r])
    for j in range(len(segs[i]) - 1):
        if segs[i][j][1] <= a[i] < segs[i][j + 1][0]:
            if segs[i][j][1] == a[i]:
                segs[i][j][1] += 1
            elif a[i] + 1 == segs[i][j + 1][0]:
                segs[i][j + 1][0] -= 1
            else:
                segs[i].append([a[i], a[i] + 1])
        if a[i] == b[i]:
            continue
        if segs[i][j][1] <= b[i] < segs[i][j + 1][0]:
            if segs[i][j][1] == b[i]:
                segs[i][j][1] += 1
            elif b[i] + 1 == segs[i][j + 1][0]:
                segs[i][j + 1][0] -= 1
            else:
                segs[i].append([b[i], b[i] + 1])
    segs[i].sort()

ans = []
s = segs[0][0][1]
ans.append(s)
for i in range(q):
    for j in range(len(segs[i]) - 1):
        if abs(segs[i][j][1] - s) <= 1 and segs[i][j][1] != segs[i][j + 1][0]:
            s = segs[i][j][1]
            ans.append(s)
            break
    else:
        print('NO')
        exit()
print('YES')
for x in ans:
    print(x)
0