結果
| 問題 |
No.119 旅行のツアーの問題
|
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2025-06-26 03:05:03 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 104 ms / 5,000 ms |
| コード長 | 795 bytes |
| コンパイル時間 | 666 ms |
| コンパイル使用メモリ | 82,904 KB |
| 実行使用メモリ | 77,072 KB |
| 最終ジャッジ日時 | 2025-06-26 03:05:07 |
| 合計ジャッジ時間 | 3,231 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 19 |
ソースコード
import sys
input = sys.stdin.readline
from collections import Counter
N=int(input())
M=[list(map(int,input().split())) for i in range(N)]
k=int(input())
E=[0]*N
for i in range(k):
d,e=map(int,input().split())
E[d]^=(1<<e)
DP=Counter()
DP[0]=0
for i in range(N):
a,b=M[i]
NDP=Counter()
for c in DP:
now=DP[c]
if c & (1<<i) != 0:
toc=c^(1<<i)
# tourに行く
NDP[toc|E[i]]=max(NDP[toc|E[i]],now+a)
# 国へ行かない
NDP[toc]=max(NDP[toc],now)
else:
# tourに行く
NDP[c|E[i]]=max(NDP[c|E[i]],now+a)
# 国へ行く
NDP[c]=max(NDP[c],now+b)
DP=NDP
#print(DP)
print(max(DP.values()))
titia