結果

問題 No.1508 Avoid being hit
ユーザー mkawa2mkawa2
提出日時 2021-05-15 00:04:27
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 323 ms / 3,000 ms
コード長 1,404 bytes
コンパイル時間 219 ms
コンパイル使用メモリ 13,056 KB
実行使用メモリ 22,476 KB
最終ジャッジ日時 2024-04-10 05:38:22
合計ジャッジ時間 8,812 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 289 ms
21,900 KB
testcase_01 AC 31 ms
10,880 KB
testcase_02 AC 30 ms
10,752 KB
testcase_03 AC 29 ms
11,008 KB
testcase_04 AC 31 ms
11,008 KB
testcase_05 AC 29 ms
11,008 KB
testcase_06 AC 29 ms
10,880 KB
testcase_07 AC 28 ms
10,880 KB
testcase_08 AC 30 ms
10,880 KB
testcase_09 AC 29 ms
11,008 KB
testcase_10 AC 29 ms
10,880 KB
testcase_11 AC 28 ms
11,008 KB
testcase_12 AC 28 ms
11,008 KB
testcase_13 AC 29 ms
10,880 KB
testcase_14 AC 30 ms
10,880 KB
testcase_15 AC 30 ms
11,008 KB
testcase_16 AC 188 ms
18,920 KB
testcase_17 AC 123 ms
15,924 KB
testcase_18 AC 104 ms
15,752 KB
testcase_19 AC 166 ms
17,920 KB
testcase_20 AC 226 ms
22,440 KB
testcase_21 AC 160 ms
19,208 KB
testcase_22 AC 192 ms
20,836 KB
testcase_23 AC 213 ms
21,052 KB
testcase_24 AC 323 ms
14,704 KB
testcase_25 AC 290 ms
14,504 KB
testcase_26 AC 49 ms
11,520 KB
testcase_27 AC 156 ms
12,680 KB
testcase_28 AC 164 ms
12,652 KB
testcase_29 AC 298 ms
14,524 KB
testcase_30 AC 174 ms
12,852 KB
testcase_31 AC 272 ms
13,860 KB
testcase_32 AC 297 ms
14,340 KB
testcase_33 AC 97 ms
11,768 KB
testcase_34 AC 243 ms
20,292 KB
testcase_35 AC 51 ms
12,032 KB
testcase_36 AC 153 ms
16,492 KB
testcase_37 AC 84 ms
13,312 KB
testcase_38 AC 209 ms
18,884 KB
testcase_39 AC 141 ms
16,084 KB
testcase_40 AC 250 ms
20,824 KB
testcase_41 AC 157 ms
17,108 KB
testcase_42 AC 263 ms
20,848 KB
testcase_43 AC 295 ms
22,476 KB
testcase_44 AC 30 ms
10,752 KB
testcase_45 AC 29 ms
10,752 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