結果
問題 | No.2434 RAKUTAN de RAKUTAN |
ユーザー | chineristAC |
提出日時 | 2023-08-18 23:47:02 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,004 ms / 2,000 ms |
コード長 | 2,425 bytes |
コンパイル時間 | 172 ms |
コンパイル使用メモリ | 82,008 KB |
実行使用メモリ | 304,156 KB |
最終ジャッジ日時 | 2024-11-28 11:26:37 |
合計ジャッジ時間 | 8,639 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
53,256 KB |
testcase_01 | AC | 42 ms
53,120 KB |
testcase_02 | AC | 47 ms
60,032 KB |
testcase_03 | AC | 74 ms
72,320 KB |
testcase_04 | AC | 76 ms
71,936 KB |
testcase_05 | AC | 74 ms
71,552 KB |
testcase_06 | AC | 76 ms
72,064 KB |
testcase_07 | AC | 42 ms
53,120 KB |
testcase_08 | AC | 42 ms
52,992 KB |
testcase_09 | AC | 42 ms
52,992 KB |
testcase_10 | AC | 1,004 ms
303,844 KB |
testcase_11 | AC | 999 ms
303,704 KB |
testcase_12 | AC | 997 ms
303,536 KB |
testcase_13 | AC | 998 ms
303,624 KB |
testcase_14 | AC | 997 ms
304,104 KB |
testcase_15 | AC | 77 ms
74,052 KB |
testcase_16 | AC | 73 ms
71,008 KB |
testcase_17 | AC | 77 ms
73,756 KB |
testcase_18 | AC | 70 ms
70,976 KB |
testcase_19 | AC | 67 ms
69,376 KB |
testcase_20 | AC | 684 ms
303,248 KB |
testcase_21 | AC | 685 ms
304,156 KB |
testcase_22 | AC | 43 ms
54,044 KB |
testcase_23 | AC | 56 ms
64,324 KB |
testcase_24 | AC | 62 ms
67,188 KB |
testcase_25 | AC | 55 ms
63,984 KB |
testcase_26 | AC | 54 ms
62,772 KB |
ソースコード
import sys from itertools import permutations from heapq import * input = lambda :sys.stdin.readline().rstrip() mi = lambda :map(int,input().split()) li = lambda :list(mi()) class SegmentTree: def __init__(self, init_val, segfunc, ide_ele): n = len(init_val) self.segfunc = segfunc self.ide_ele = ide_ele self.num = 1 << (n - 1).bit_length() self.tree = [ide_ele] * 2 * self.num self.size = n for i in range(n): self.tree[self.num + i] = init_val[i] for i in range(self.num - 1, 0, -1): self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1]) def update(self, k, x): k += self.num self.tree[k] = self.segfunc(self.tree[k],x) while k > 1: k >>= 1 self.tree[k] = self.segfunc(self.tree[2*k], self.tree[2*k+1]) def query(self, l, r): if r==self.size: r = self.num res = self.ide_ele l += self.num r += self.num right = [] while l < r: if l & 1: res = self.segfunc(res, self.tree[l]) l += 1 if r & 1: right.append(self.tree[r-1]) l >>= 1 r >>= 1 for e in right[::-1]: res = self.segfunc(res,e) return res N,H,X = mi() G = int(input()) G = li() B = int(input()) B = li() day = set([0,N]) for i in range(X+1): day.add(i) for i in range(X+1): if 0 <= N-i: day.add(N-i) for g in G: for i in range(-X,X+1): if 0 <= g+i <= N: day.add(g+i) for b in B: for i in range(-X,X+1): if 0 <= b+i <= N: day.add(b+i) day = sorted(day) d_to_i = {d:i for i,d in enumerate(day)} n = len(day) M = max(len(G),len(B)) INF = H + 1 dp = [[INF]*(2*M+1) for i in range(n)] dp[0][0] = 0 G = set(G) B = set(B) for i in range(1,n): d = day[i] p = 0 if d in G: p = 1 elif d in B: p = -1 for h in range(-M,M+1): if dp[i-1][h] == INF: continue dp[i][h+p] = min(dp[i][h+p],dp[i-1][h]) if d-X in d_to_i: pre = d_to_i[d-X] for h in range(-M,M+1): if dp[pre][h] == INF: continue dp[i][h+p] = min(dp[i][h+p],dp[pre][h]+1) for tani in range(-M,M+1)[::-1]: if dp[-1][tani] <= H: print(tani) break