結果
問題 |
No.1508 Avoid being hit
|
ユーザー |
![]() |
提出日時 | 2023-07-18 11:37:34 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,337 bytes |
コンパイル時間 | 251 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 821,564 KB |
最終ジャッジ日時 | 2024-09-18 10:59:42 |
合計ジャッジ時間 | 13,595 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 MLE * 2 -- * 25 |
ソースコード
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 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 dp=[None]*(Q+1) dp[0]=(1<<N)-1 for q in range(1,Q+1): dp[q]=dp[q-1]>>1|dp[q-1]|dp[q-1]<<1 dp[q]&=~(1<<N|1<<A[q-1]|1<<B[q-1]) if dp[Q]: print("YES") for x in range(N): if dp[Q]&1<<x: break ans_lst=[x] for q in range(Q-1,-1,-1): if 0<=x-1<N and dp[q]&1<<x-1: x-=1 elif 0<=x+1<N and dp[q]&1<<x+1: x+=1 ans_lst.append(x) ans_lst=ans_lst[::-1] print(*[x+1 for x in ans_lst],sep="\n") else: print("NO")