結果
| 問題 |
No.3097 Azuki Kurai
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-04-05 12:52:58 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,485 bytes |
| コンパイル時間 | 446 ms |
| コンパイル使用メモリ | 82,220 KB |
| 実行使用メモリ | 86,136 KB |
| 最終ジャッジ日時 | 2025-04-05 12:53:03 |
| 合計ジャッジ時間 | 4,718 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | RE * 32 |
ソースコード
def popcount(x):
# 32bit
x = x - ((x >> 1) & 0x55555555)
x = (x & 0x33333333) + ((x >> 2) & 0x33333333)
x = (x + (x >> 4)) & 0x0f0f0f0f
x = x + (x >> 8)
x = x + (x >> 16)
return x & 0x0000007f
inf = 10**18
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
dp = [[inf] * (1 << n) for _ in range(m + 1)]
for i in range(1 << n):
dp[0][i] = 0
for j in range(n):
if (i>>j) & 1 == 0:
dp[0][i] += a[j]
pl = [[] for _ in range(1 << n)]
for i in range(1 << n):
c = i
while c:
pl[i].append((popcount(i) - popcount(c)) * k)
c = (c - 1) & i
pl[i].append((popcount(i)) * k)
mae = [[[] for _ in range(1 << n)] for _ in range(n)]
for p in range(n):
for i in range(1 << n):
c = i
while c:
now = i
now |= ((c << 1) & ((1 << n) - 1))
now |= (c >> 1)
now |= ((c & 1) << (n - 1))
now &= ~(1 << p)
mae[p][i].append(now)
c = (c - 1) & i
now = i & ~(1 << p)
mae[p][i].append(now)
for p in range(m):
x = b[p] - 1
for i in range(1 << n):
f = 0
c = i
while c:
dp[p+1][mae[i][x][f]] = min(dp[p+1][mae[i][x][f]],dp[p][i]+pl[i][f])
c = (c - 1) & i
f += 1
dp[p+1][mae[i][x][f]] = min(dp[p+1][mae[i][x][f]],dp[p][i]+pl[i][f])
for i in range(m):
print(dp[i + 1][0])