結果
問題 | No.332 数列をプレゼントに |
ユーザー |
![]() |
提出日時 | 2023-04-25 23:18:43 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 169 ms / 2,000 ms |
コード長 | 1,984 bytes |
コンパイル時間 | 297 ms |
コンパイル使用メモリ | 82,248 KB |
実行使用メモリ | 149,160 KB |
最終ジャッジ日時 | 2024-11-15 07:38:46 |
合計ジャッジ時間 | 8,444 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 42 |
ソースコード
import sys# sys.setrecursionlimit(200005)# sys.set_int_max_str_digits(200005)int1 = lambda x: int(x)-1pDB = lambda *x: print(*x, end="\n", file=sys.stderr)p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)def II(): return int(sys.stdin.readline())def LI(): return list(map(int, sys.stdin.readline().split()))def LLI(rows_number): return [LI() for _ in range(rows_number)]def LI1(): return list(map(int1, sys.stdin.readline().split()))def LLI1(rows_number): return [LI1() for _ in range(rows_number)]def SI(): return sys.stdin.readline().rstrip()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)]inf = (1 << 63)-1# md = 10**9+7md = 998244353n, x = LI()aa = LI()if n <= 20:sa = [(0, 0)]for i, a in enumerate(aa):s = 1 << insa = []for t, b in sa:nsa.append((s | t, a+b))sa += nsafor s,a in sa:if a==x:ans=""for i in range(n):if s>>i&1:ans+="o"else:ans+="x"print(ans)exit()else:ia = sorted(enumerate(aa), key=lambda x: -x[1])sa = [(0, 0)]for i in range(20):s = 1 << ia=ia[i][1]nsa = []for t, b in sa:nsa.append((s | t, a+b))sa += nsat=sum(a for _,a in ia[20:])dp=[-1]*(t+1)dp[0]=0for i,a in ia[20:]:for j in range(t-a,-1,-1):if dp[j]==-1 or dp[j+a]!=-1:continuedp[j+a]=ians=[0]*nfor s,a in sa:if not 0<=x-a<=t:continueif dp[x-a]==-1:continuefor j in range(n):if s>>j&1:i=ia[j][0]ans[i]=1x-=awhile x:i=dp[x]ans[i]=1x-=aa[i]print("".join("o" if a else "x" for a in ans))exit()print("No")