結果
| 問題 |
No.1017 Reiwa Sequence
|
| ユーザー |
mkawa2
|
| 提出日時 | 2020-04-06 00:05:11 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,428 bytes |
| コンパイル時間 | 304 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 16,256 KB |
| 最終ジャッジ日時 | 2024-07-03 08:22:43 |
| 合計ジャッジ時間 | 18,626 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 15 TLE * 1 -- * 34 |
ソースコード
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.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]
# N=22のとき、Aの部分集合の選び方は2**22=4194304通り
# それに対して、部分集合の和は150000*22=3300000通り(正確には0も入れて+1通り)
# 選び方のパターン>和のパターンということは、同じ和になる選び方が必ず存在するということ
# よって、Nが22以上のときは初めから22項だけで考え、あとは0にする
def main():
def dfs(i=0,s=0,t=0):
if s and s==t:return True
if i==len(aa):return False
if dfs(i+1,s,t):return True
xx.append(i)
if dfs(i+1,s+aa[i],t):return True
xx.pop()
yy.append(i)
if dfs(i+1,s,t+aa[i]):return True
yy.pop()
return False
n=II()
aa=LI()
if len(aa)>22:aa=aa[:22]
xx=[]
yy=[]
if dfs():
print("Yes")
coe=[0]*len(aa)
for i in xx:coe[i]=1
for i in yy:coe[i]=-1
for i in range(len(aa)):aa[i]*=coe[i]
if n-len(aa)>0:aa+=[0]*(n-len(aa))
print(*aa)
else:print("No")
main()
mkawa2