結果
| 問題 | No.3561 Collect KCPC |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-06-21 02:17:43 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,788 bytes |
| 記録 | |
| コンパイル時間 | 524 ms |
| コンパイル使用メモリ | 85,504 KB |
| 実行使用メモリ | 138,360 KB |
| 最終ジャッジ日時 | 2026-06-21 02:18:10 |
| 合計ジャッジ時間 | 25,066 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_1 |
(要ログイン)
| サブタスク | 配点 | 結果 |
|---|---|---|
| 部分点1 | 10 % | AC * 9 WA * 6 |
| 部分点2 | 20 % | AC * 8 WA * 7 |
| 部分点3 | 20 % | AC * 13 |
| 部分点4 | 50 % | AC * 30 WA * 21 |
| 合計 | 20 点 |
ソースコード
## https://yukicoder.me/problems/no/3561
import heapq
MAX_INT = 10 ** 18
def main():
N, M = map(int, input().split())
next_nodes = [[] for _ in range(N)]
for _ in range(M):
u, v, c = map(int, input().split())
next_nodes[u - 1].append((v - 1, c))
S = input()
fix = [[MAX_INT for _ in range(N)] for _ in range(4)]
seen = [[MAX_INT for _ in range(N)] for _ in range(4)]
queue = []
answer = MAX_INT
seen[0][0] = 0
heapq.heappush(queue, (0, 0, 0))
while len(queue) > 0:
cost, state, v = heapq.heappop(queue)
if fix[state][v] < MAX_INT:
continue
fix[state][v] = cost
if state == 0 and S[v] == "K":
new_state = 1
if seen[new_state][v] > cost:
seen[new_state][v] = cost
heapq.heappush(queue, (cost, new_state, v))
elif state == 1 and S[v] == "C":
new_state = 2
if seen[new_state][v] > cost:
seen[new_state][v] = cost
heapq.heappush(queue, (cost, new_state, v))
elif state == 2 and S[v] == "P":
new_state = 3
if seen[new_state][v] > cost:
seen[new_state][v] = cost
heapq.heappush(queue, (cost, new_state, v))
elif state == 3 and S[v] == "C":
answer = min(answer, cost)
for w, c in next_nodes[v]:
if fix[state][w] < MAX_INT:
continue
new_cost = c + cost
if seen[state][w] > new_cost:
seen[state][w] = new_cost
heapq.heappush(queue, (new_cost, state, w))
if answer == MAX_INT:
print(-1)
else:
print(answer)
if __name__ == "__main__":
main()