結果

問題 No.1508 Avoid being hit
ユーザー vwxyzvwxyz
提出日時 2023-07-18 13:31:37
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,046 ms / 3,000 ms
コード長 2,284 bytes
コンパイル時間 262 ms
コンパイル使用メモリ 12,132 KB
実行使用メモリ 50,388 KB
最終ジャッジ日時 2023-10-18 16:50:51
合計ジャッジ時間 23,550 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 822 ms
40,172 KB
testcase_01 AC 39 ms
11,392 KB
testcase_02 AC 40 ms
11,392 KB
testcase_03 AC 39 ms
11,392 KB
testcase_04 AC 39 ms
11,392 KB
testcase_05 AC 39 ms
11,392 KB
testcase_06 AC 41 ms
11,392 KB
testcase_07 AC 40 ms
11,392 KB
testcase_08 AC 40 ms
11,392 KB
testcase_09 AC 40 ms
11,392 KB
testcase_10 AC 39 ms
11,392 KB
testcase_11 AC 40 ms
11,392 KB
testcase_12 AC 40 ms
11,392 KB
testcase_13 AC 40 ms
11,392 KB
testcase_14 AC 39 ms
11,392 KB
testcase_15 AC 39 ms
11,392 KB
testcase_16 AC 755 ms
31,436 KB
testcase_17 AC 461 ms
22,820 KB
testcase_18 AC 348 ms
21,084 KB
testcase_19 AC 659 ms
28,288 KB
testcase_20 AC 896 ms
36,376 KB
testcase_21 AC 603 ms
27,744 KB
testcase_22 AC 750 ms
31,940 KB
testcase_23 AC 794 ms
34,028 KB
testcase_24 AC 1,046 ms
37,028 KB
testcase_25 AC 963 ms
35,044 KB
testcase_26 AC 102 ms
13,372 KB
testcase_27 AC 505 ms
23,376 KB
testcase_28 AC 508 ms
23,376 KB
testcase_29 AC 980 ms
35,592 KB
testcase_30 AC 552 ms
24,228 KB
testcase_31 AC 858 ms
32,240 KB
testcase_32 AC 920 ms
34,200 KB
testcase_33 AC 275 ms
17,744 KB
testcase_34 AC 816 ms
42,656 KB
testcase_35 AC 115 ms
14,784 KB
testcase_36 AC 479 ms
27,516 KB
testcase_37 AC 232 ms
19,512 KB
testcase_38 AC 663 ms
35,552 KB
testcase_39 AC 443 ms
28,480 KB
testcase_40 AC 844 ms
41,380 KB
testcase_41 AC 508 ms
30,936 KB
testcase_42 AC 862 ms
45,180 KB
testcase_43 AC 1,005 ms
50,388 KB
testcase_44 AC 41 ms
11,392 KB
testcase_45 AC 41 ms
11,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect
import copy
import decimal
import fractions
import heapq
import itertools
import math
import random
import sys
import time
from collections import Counter,deque,defaultdict
from functools import lru_cache,reduce
from heapq import heappush,heappop,heapify,heappushpop,_heappop_max,_heapify_max
def _heappush_max(heap,item):
    heap.append(item)
    heapq._siftdown_max(heap, 0, len(heap)-1)
def _heappushpop_max(heap, item):
    if heap and item < heap[0]:
        item, heap[0] = heap[0], item
        heapq._siftup_max(heap, 0)
    return item
from math import gcd as GCD
read=sys.stdin.read
readline=sys.stdin.readline
readlines=sys.stdin.readlines
write=sys.stdout.write

def Compress(lst):
    decomp=sorted(list(set(lst)))
    comp={x:i for i,x in enumerate(decomp)}
    return comp,decomp

N,Q=map(int,readline().split())
A=list(map(int,readline().split()))
B=list(map(int,readline().split()))
for q in range(Q):
    A[q]-=1
    B[q]-=1
    if A[q]>B[q]:
        A[q],B[q]=B[q],A[q]
dp=[[] for q in range(Q+1)]
for q in range(1,Q+1):
    lst=[A[q-1],A[q-1]+1,B[q-1],B[q-1]+1]
    for l,r in dp[q-1]:
        if 0<l:
            l+=1
        if r<N:
            r-=1
        if l<r:
            lst.append(l)
            lst.append(r)
    comp,decomp=Compress(lst)
    le=len(comp)
    bl=[1]*(le-1)
    for l,r in dp[q-1]:
        if 0<l:
            l+=1
        if r<N:
            r-=1
        if l<r:
            for i in range(comp[l],comp[r]):
                bl[i]=0
    for i in range(comp[A[q-1]],comp[A[q-1]+1]):
        bl[i]=0
    for i in range(comp[B[q-1]],comp[B[q-1]+1]):
        bl[i]=0
    L,R=[],[]
    if not bl[0]:
        L.append(0)
    for i in range(1,le-1):
        if bl[i-1] and not bl[i]:
            L.append(i)
        if not bl[i-1] and bl[i]:
            R.append(i)
    if not bl[le-2]:
        R.append(le-1)
    for l,r in zip(L,R):
        dp[q].append((decomp[l],decomp[r]))
if dp[Q]==[(0,N)]:
    print("NO")
    exit()

ans_lst=[]
l,r=dp[Q][0]
if l:
    x=l-1
else:
    x=r
ans_lst.append(x)
for q in range(Q-1,-1,-1):
    for x in (x-1,x,x+1):
        if 0<=x<N and not any(l<=x<r for l,r in dp[q]):
            ans_lst.append(x)
            break
ans_lst=ans_lst[::-1]
print("YES")
print(*[x+1 for x in ans_lst],sep="\n")
0