結果

問題 No.1508 Avoid being hit
ユーザー mkawa2mkawa2
提出日時 2021-05-15 00:04:27
言語 Python3
(3.11.2 + numpy 1.24.2 + scipy 1.10.1)
結果
AC  
実行時間 274 ms / 3,000 ms
コード長 1,404 bytes
コンパイル時間 1,447 ms
コンパイル使用メモリ 10,832 KB
実行使用メモリ 20,056 KB
最終ジャッジ日時 2023-07-25 13:00:29
合計ジャッジ時間 8,982 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 245 ms
19,476 KB
testcase_01 AC 17 ms
8,012 KB
testcase_02 AC 16 ms
8,300 KB
testcase_03 AC 17 ms
8,016 KB
testcase_04 AC 17 ms
8,004 KB
testcase_05 AC 17 ms
8,264 KB
testcase_06 AC 17 ms
8,196 KB
testcase_07 AC 17 ms
8,048 KB
testcase_08 AC 17 ms
8,024 KB
testcase_09 AC 16 ms
8,016 KB
testcase_10 AC 17 ms
8,432 KB
testcase_11 AC 17 ms
8,024 KB
testcase_12 AC 17 ms
8,024 KB
testcase_13 AC 17 ms
8,024 KB
testcase_14 AC 17 ms
8,016 KB
testcase_15 AC 17 ms
8,264 KB
testcase_16 AC 166 ms
16,664 KB
testcase_17 AC 103 ms
12,856 KB
testcase_18 AC 82 ms
13,232 KB
testcase_19 AC 146 ms
14,328 KB
testcase_20 AC 199 ms
20,056 KB
testcase_21 AC 137 ms
16,184 KB
testcase_22 AC 162 ms
17,968 KB
testcase_23 AC 180 ms
19,760 KB
testcase_24 AC 274 ms
11,888 KB
testcase_25 AC 253 ms
11,564 KB
testcase_26 AC 34 ms
8,832 KB
testcase_27 AC 137 ms
9,960 KB
testcase_28 AC 135 ms
10,000 KB
testcase_29 AC 261 ms
11,880 KB
testcase_30 AC 145 ms
10,092 KB
testcase_31 AC 225 ms
11,256 KB
testcase_32 AC 242 ms
11,592 KB
testcase_33 AC 79 ms
9,220 KB
testcase_34 AC 210 ms
18,368 KB
testcase_35 AC 36 ms
9,208 KB
testcase_36 AC 125 ms
13,716 KB
testcase_37 AC 64 ms
10,604 KB
testcase_38 AC 171 ms
16,256 KB
testcase_39 AC 115 ms
13,136 KB
testcase_40 AC 216 ms
18,636 KB
testcase_41 AC 133 ms
14,792 KB
testcase_42 AC 223 ms
18,724 KB
testcase_43 AC 263 ms
19,956 KB
testcase_44 AC 16 ms
8,044 KB
testcase_45 AC 16 ms
8,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10**6)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.buffer.readline())
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def LI1(): return list(map(int1, sys.stdin.buffer.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def BI(): return sys.stdin.buffer.readline().rstrip()
def SI(): return sys.stdin.buffer.readline().rstrip().decode()
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
dij = [(0, 1), (1, 0), (1, 1), (1, -1)]
inf = 10**16
# md = 998244353
md = 10**9+7

n,q=LI()
aa=LI()
bb=LI()

ll=[1]*q
rr=[n]*q
l,r=1,n
for i in range(q-1,-1,-1):
    a,b=aa[i],bb[i]
    if a>b:a,b=b,a
    l=max(1,l-1)
    if l==a:l+=1
    if l==b:l+=1
    r=min(n,r+1)
    if r==b:r-=1
    if r==a:r-=1
    ll[i]=l
    rr[i]=r

for l,r in zip(ll,rr):
    if l>r:
        print("NO")
        exit()

print("YES")
print(ll[0])
now=ll[0]
for l,r,a,b in zip(ll,rr,aa,bb):
    if l>now:now+=1
    elif r<now:now-=1
    elif now==a:
        if now-1!=b and l<=now-1:
            now-=1
        else:
            now+=1
    elif now == b:
        if now-1 != a and l <= now-1:
            now -= 1
        else:
            now += 1
    print(now)
0