結果
問題 | No.1508 Avoid being hit |
ユーザー |
![]() |
提出日時 | 2021-05-15 00:04:27 |
言語 | Python3 (3.10.1 + numpy 1.22.3 + scipy 1.8.0) |
結果 |
AC
|
実行時間 | 230 ms / 3,000 ms |
コード長 | 1,404 bytes |
コンパイル時間 | 80 ms |
使用メモリ | 20,212 KB |
最終ジャッジ日時 | 2022-11-26 01:07:54 |
合計ジャッジ時間 | 7,331 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 使用メモリ |
---|---|---|
testcase_00 | AC | 203 ms
19,900 KB |
testcase_01 | AC | 15 ms
7,920 KB |
testcase_02 | AC | 15 ms
7,816 KB |
testcase_03 | AC | 15 ms
7,916 KB |
testcase_04 | AC | 14 ms
7,820 KB |
testcase_05 | AC | 14 ms
7,972 KB |
testcase_06 | AC | 15 ms
7,952 KB |
testcase_07 | AC | 14 ms
7,804 KB |
testcase_08 | AC | 14 ms
7,920 KB |
testcase_09 | AC | 13 ms
7,796 KB |
testcase_10 | AC | 14 ms
7,920 KB |
testcase_11 | AC | 14 ms
7,888 KB |
testcase_12 | AC | 15 ms
7,916 KB |
testcase_13 | AC | 14 ms
7,784 KB |
testcase_14 | AC | 14 ms
7,880 KB |
testcase_15 | AC | 15 ms
7,880 KB |
testcase_16 | AC | 147 ms
15,928 KB |
testcase_17 | AC | 92 ms
12,516 KB |
testcase_18 | AC | 68 ms
13,000 KB |
testcase_19 | AC | 118 ms
14,152 KB |
testcase_20 | AC | 163 ms
19,408 KB |
testcase_21 | AC | 118 ms
15,840 KB |
testcase_22 | AC | 151 ms
17,700 KB |
testcase_23 | AC | 152 ms
18,136 KB |
testcase_24 | AC | 230 ms
11,732 KB |
testcase_25 | AC | 207 ms
11,320 KB |
testcase_26 | AC | 28 ms
8,584 KB |
testcase_27 | AC | 112 ms
9,764 KB |
testcase_28 | AC | 116 ms
9,624 KB |
testcase_29 | AC | 218 ms
11,384 KB |
testcase_30 | AC | 119 ms
9,912 KB |
testcase_31 | AC | 185 ms
10,968 KB |
testcase_32 | AC | 198 ms
11,204 KB |
testcase_33 | AC | 65 ms
9,148 KB |
testcase_34 | AC | 173 ms
17,488 KB |
testcase_35 | AC | 29 ms
9,092 KB |
testcase_36 | AC | 101 ms
13,600 KB |
testcase_37 | AC | 52 ms
10,364 KB |
testcase_38 | AC | 144 ms
15,788 KB |
testcase_39 | AC | 98 ms
12,792 KB |
testcase_40 | AC | 187 ms
18,272 KB |
testcase_41 | AC | 114 ms
13,904 KB |
testcase_42 | AC | 181 ms
18,268 KB |
testcase_43 | AC | 216 ms
20,212 KB |
testcase_44 | AC | 15 ms
7,920 KB |
testcase_45 | AC | 14 ms
7,948 KB |
ソースコード
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)