結果

問題 No.1508 Avoid being hit
ユーザー tpynerivertpyneriver
提出日時 2021-05-14 23:00:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 172 ms / 3,000 ms
コード長 1,609 bytes
コンパイル時間 369 ms
コンパイル使用メモリ 82,256 KB
実行使用メモリ 101,904 KB
最終ジャッジ日時 2024-04-10 05:34:12
合計ジャッジ時間 6,453 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
96,316 KB
testcase_01 AC 35 ms
53,908 KB
testcase_02 AC 34 ms
53,376 KB
testcase_03 AC 32 ms
53,112 KB
testcase_04 AC 34 ms
52,760 KB
testcase_05 AC 33 ms
52,948 KB
testcase_06 AC 33 ms
53,140 KB
testcase_07 AC 32 ms
53,128 KB
testcase_08 AC 35 ms
52,348 KB
testcase_09 AC 34 ms
52,380 KB
testcase_10 AC 34 ms
52,260 KB
testcase_11 AC 36 ms
53,392 KB
testcase_12 AC 34 ms
53,340 KB
testcase_13 AC 35 ms
54,020 KB
testcase_14 AC 36 ms
53,692 KB
testcase_15 AC 35 ms
53,012 KB
testcase_16 AC 94 ms
98,920 KB
testcase_17 AC 70 ms
87,052 KB
testcase_18 AC 67 ms
82,744 KB
testcase_19 AC 86 ms
95,560 KB
testcase_20 AC 108 ms
101,904 KB
testcase_21 AC 85 ms
93,540 KB
testcase_22 AC 94 ms
98,760 KB
testcase_23 AC 96 ms
98,812 KB
testcase_24 AC 172 ms
101,868 KB
testcase_25 AC 159 ms
98,412 KB
testcase_26 AC 86 ms
76,936 KB
testcase_27 AC 119 ms
87,116 KB
testcase_28 AC 118 ms
86,892 KB
testcase_29 AC 162 ms
98,380 KB
testcase_30 AC 117 ms
88,392 KB
testcase_31 AC 150 ms
95,652 KB
testcase_32 AC 159 ms
97,996 KB
testcase_33 AC 105 ms
81,096 KB
testcase_34 AC 115 ms
93,804 KB
testcase_35 AC 71 ms
77,512 KB
testcase_36 AC 93 ms
84,592 KB
testcase_37 AC 73 ms
77,192 KB
testcase_38 AC 107 ms
90,476 KB
testcase_39 AC 92 ms
84,588 KB
testcase_40 AC 124 ms
96,092 KB
testcase_41 AC 95 ms
85,852 KB
testcase_42 AC 123 ms
95,808 KB
testcase_43 AC 145 ms
98,920 KB
testcase_44 AC 34 ms
53,172 KB
testcase_45 AC 35 ms
53,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline

N, Q = map(int, readline().split())

ok = [None]*(Q+1)
ok[-1] = [(1, N+1)]

A = list(map(int, readline().split()))
B = list(map(int, readline().split()))


INF = 10**9+7
for i in range(Q):
    a, b = A[i], B[i]
    res = []
    for l, r in ok[i-1]:
        res.append((max(1, l-1), min(N+1, r+1)))
    
    st = -INF
    en = -INF
    
    res2 = []
    for l, r in res:
        if en < l:
            if st != en:
                res2.append((st, en))
            st = l
        en = r
    
    if st != en:
        res2.append((st, en))
    
    res3 = []
    for l, r in res2:
        if l <= a < r:
            if l != a:
                res3.append((l, a))
            if r-1 != a:
                res3.append((a+1, r))
        else:
            res3.append((l, r))
    
    res4 = []
    for l, r in res3:
        if l <= b < r:
            if l != b:
                res4.append((l, b))
            if r-1 != b:
                res4.append((b+1, r))
        else:
            res4.append((l, r))
    
    
    ok[i] = res4[:]


if not ok[Q-1]:
    print("NO")
else:
    print("YES")
    ans = [ok[Q-1][0][0]]
    
    for i in range(Q-2, -2, -1):
        for l, r in ok[i]:
            if l <= ans[-1]-1 < r:
                ans.append(ans[-1]-1)
                break
            if l <= ans[-1] < r:
                ans.append(ans[-1])
                break
            if l <= ans[-1]+1 < r:
                ans.append(ans[-1]+1)
                break
        else:
            assert False
    
    print('\n'.join(map(str, ans[::-1])))
    
    
    
    
0