結果
| 問題 | No.3561 Collect KCPC |
| コンテスト | |
| ユーザー |
urectanc
|
| 提出日時 | 2026-05-29 20:43:32 |
| 言語 | Rust (1.94.0 + proconio + num + itertools) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,517 bytes |
| 記録 | |
| コンパイル時間 | 12,294 ms |
| コンパイル使用メモリ | 191,776 KB |
| 実行使用メモリ | 30,848 KB |
| 最終ジャッジ日時 | 2026-05-29 20:43:49 |
| 合計ジャッジ時間 | 16,202 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge4_0 |
(要ログイン)
| サブタスク | 配点 | 結果 |
|---|---|---|
| 部分点1 | 10 % | AC * 14 WA * 1 |
| 部分点2 | 20 % | AC * 13 WA * 2 |
| 部分点3 | 20 % | AC * 13 |
| 部分点4 | 50 % | AC * 48 WA * 3 |
| 合計 | 20 点 |
ソースコード
use std::{cmp::Reverse, collections::BinaryHeap};
use proconio::{
input,
marker::{Chars, Usize1},
};
fn main() {
input! {
n: usize, m: usize,
edges: [(Usize1, Usize1, usize); m],
s: Chars,
}
let mut graph = vec![vec![]; n];
for &(u, v, w) in &edges {
graph[u].push((v, w));
}
let mut dist = vec![[!0usize; 4]; n];
let mut heap: BinaryHeap<(Reverse<usize>, usize, Vec<usize>)> = BinaryHeap::new();
dist[0][0] = 0;
heap.push((Reverse(0), 0, vec![]));
let kcpc = ['K', 'C', 'P', 'C'];
while let Some((Reverse(d), current, history)) = heap.pop() {
let i = history.len();
if d != dist[current][i] {
continue;
}
let target = kcpc[history.len()];
if target == s[current] && !history.contains(¤t) {
if i == 3 {
println!("{}", dist[current][i]);
return;
} else if dist[current][i + 1] > dist[current][i] {
let mut nhistory = history.clone();
nhistory.push(current);
dist[current][i + 1] = dist[current][i];
heap.push((Reverse(d), current, nhistory));
}
}
for &(next, w) in &graph[current] {
if dist[next][i] > dist[current][i] + w {
dist[next][i] = dist[current][i] + w;
heap.push((Reverse(dist[next][i]), next, history.clone()));
}
}
}
println!("-1");
}
urectanc