結果

問題 No.1508 Avoid being hit
ユーザー trineutrontrineutron
提出日時 2021-05-15 00:43:48
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,192 ms / 3,000 ms
コード長 1,871 bytes
コンパイル時間 245 ms
コンパイル使用メモリ 13,184 KB
実行使用メモリ 59,904 KB
最終ジャッジ日時 2024-04-10 05:57:20
合計ジャッジ時間 24,047 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 840 ms
48,200 KB
testcase_01 AC 30 ms
11,008 KB
testcase_02 AC 31 ms
11,008 KB
testcase_03 AC 30 ms
11,008 KB
testcase_04 AC 30 ms
11,008 KB
testcase_05 AC 30 ms
11,008 KB
testcase_06 AC 30 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 30 ms
11,008 KB
testcase_12 AC 29 ms
11,008 KB
testcase_13 AC 29 ms
11,008 KB
testcase_14 AC 29 ms
11,008 KB
testcase_15 AC 30 ms
11,008 KB
testcase_16 AC 685 ms
44,068 KB
testcase_17 AC 391 ms
29,716 KB
testcase_18 AC 336 ms
27,776 KB
testcase_19 AC 553 ms
38,496 KB
testcase_20 AC 880 ms
54,324 KB
testcase_21 AC 563 ms
39,324 KB
testcase_22 AC 726 ms
46,348 KB
testcase_23 AC 790 ms
50,540 KB
testcase_24 AC 1,167 ms
49,536 KB
testcase_25 AC 1,076 ms
46,148 KB
testcase_26 AC 99 ms
13,696 KB
testcase_27 AC 548 ms
28,804 KB
testcase_28 AC 538 ms
28,804 KB
testcase_29 AC 1,046 ms
46,876 KB
testcase_30 AC 569 ms
30,268 KB
testcase_31 AC 917 ms
41,932 KB
testcase_32 AC 1,016 ms
44,888 KB
testcase_33 AC 285 ms
20,224 KB
testcase_34 AC 941 ms
50,416 KB
testcase_35 AC 117 ms
15,104 KB
testcase_36 AC 553 ms
33,164 KB
testcase_37 AC 242 ms
20,992 KB
testcase_38 AC 774 ms
42,944 KB
testcase_39 AC 500 ms
31,440 KB
testcase_40 AC 1,008 ms
52,452 KB
testcase_41 AC 575 ms
34,648 KB
testcase_42 AC 1,007 ms
52,800 KB
testcase_43 AC 1,192 ms
59,904 KB
testcase_44 AC 30 ms
11,136 KB
testcase_45 AC 29 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 j != 0 and segs[i + 1][j - 1][1] == l:
            continue
        jcopy = j
        while jcopy != len(segs[i + 1]) - 1 and r == segs[i + 1][jcopy + 1][0]:
            jcopy += 1
            r = segs[i + 1][jcopy][1]
        if 0 < l < n + 1:
            l += 1
        if 1 < r < n + 2:
            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])
    segs[i].sort()
    if a[i] == b[i]:
        continue
    for j in range(len(segs[i]) - 1):
        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 = []
for i in range(len(segs[0]) - 1):
    if segs[0][i][1] != segs[0][i + 1][0]:
        s = segs[0][i][1]
        break
else:
    print('NO')
    exit()
ans.append(s)
for i in range(q):
    for j in range(len(segs[i]) - 1):
        if segs[i][j][1] < segs[i][j + 1][0] and segs[i][j][1] <= s + 1 and s - 1 < segs[i][j + 1][0]:
            s = max(s - 1, segs[i][j][1])
            ans.append(s)
            break
    else:
        print('NO')
        exit()
print('YES')
for x in ans:
    print(x)
0