結果

問題 No.1508 Avoid being hit
ユーザー tpynerivertpyneriver
提出日時 2021-05-14 23:00:07
言語 PyPy3
(7.3.8)
結果
AC  
実行時間 236 ms / 3,000 ms
コード長 1,609 bytes
コンパイル時間 837 ms
使用メモリ 106,412 KB
最終ジャッジ日時 2022-11-26 01:02:06
合計ジャッジ時間 10,295 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 180 ms
100,896 KB
testcase_01 AC 75 ms
75,528 KB
testcase_02 AC 75 ms
75,732 KB
testcase_03 AC 74 ms
75,696 KB
testcase_04 AC 72 ms
75,524 KB
testcase_05 AC 73 ms
75,840 KB
testcase_06 AC 76 ms
75,744 KB
testcase_07 AC 74 ms
75,844 KB
testcase_08 AC 75 ms
75,704 KB
testcase_09 AC 75 ms
75,724 KB
testcase_10 AC 78 ms
75,720 KB
testcase_11 AC 72 ms
75,540 KB
testcase_12 AC 75 ms
75,404 KB
testcase_13 AC 73 ms
75,376 KB
testcase_14 AC 72 ms
75,816 KB
testcase_15 AC 76 ms
75,704 KB
testcase_16 AC 136 ms
103,068 KB
testcase_17 AC 114 ms
92,456 KB
testcase_18 AC 111 ms
88,248 KB
testcase_19 AC 133 ms
100,188 KB
testcase_20 AC 151 ms
104,328 KB
testcase_21 AC 129 ms
97,672 KB
testcase_22 AC 137 ms
103,328 KB
testcase_23 AC 151 ms
103,800 KB
testcase_24 AC 229 ms
106,028 KB
testcase_25 AC 224 ms
103,380 KB
testcase_26 AC 135 ms
82,480 KB
testcase_27 AC 175 ms
92,116 KB
testcase_28 AC 175 ms
92,292 KB
testcase_29 AC 236 ms
103,880 KB
testcase_30 AC 178 ms
92,660 KB
testcase_31 AC 212 ms
100,528 KB
testcase_32 AC 229 ms
103,060 KB
testcase_33 AC 158 ms
85,132 KB
testcase_34 AC 168 ms
98,476 KB
testcase_35 AC 118 ms
82,236 KB
testcase_36 AC 144 ms
89,676 KB
testcase_37 AC 121 ms
82,476 KB
testcase_38 AC 157 ms
95,412 KB
testcase_39 AC 139 ms
89,796 KB
testcase_40 AC 181 ms
100,276 KB
testcase_41 AC 141 ms
91,068 KB
testcase_42 AC 180 ms
100,756 KB
testcase_43 AC 192 ms
106,412 KB
testcase_44 AC 78 ms
75,696 KB
testcase_45 AC 80 ms
75,472 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