結果
| 問題 | No.3561 Collect KCPC |
| コンテスト | |
| ユーザー |
urectanc
|
| 提出日時 | 2026-05-29 21:12:31 |
| 言語 | Rust (1.94.0 + proconio + num + itertools) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,716 bytes |
| 記録 | |
| コンパイル時間 | 5,696 ms |
| コンパイル使用メモリ | 198,116 KB |
| 実行使用メモリ | 702,052 KB |
| 最終ジャッジ日時 | 2026-05-29 21:13:26 |
| 合計ジャッジ時間 | 19,338 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_0 |
(要ログイン)
| サブタスク | 配点 | 結果 |
|---|---|---|
| 部分点1 | 10 % | AC * 15 |
| 部分点2 | 20 % | AC * 8 TLE * 1 -- * 6 |
| 部分点3 | 20 % | AC * 1 -- * 12 |
| 部分点4 | 50 % | AC * 20 TLE * 1 -- * 30 |
| 合計 | 10 点 |
ソースコード
use std::{
cmp::Reverse,
collections::{BinaryHeap, HashMap},
};
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 = HashMap::new();
let mut heap: BinaryHeap<(Reverse<usize>, usize, Vec<usize>)> = BinaryHeap::new();
dist.insert((0, vec![]), 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, history.clone())] {
continue;
}
let target = kcpc[history.len()];
if target == s[current] && !history.contains(¤t) {
if i == 3 {
println!("{}", d);
return;
} else {
let mut nhistory = history.clone();
nhistory.push(current);
if !dist.contains_key(&(current, nhistory.clone())) {
dist.insert((current, nhistory.clone()), d);
heap.push((Reverse(d), current, nhistory));
}
}
}
for &(next, w) in &graph[current] {
if dist
.get(&(next, history.clone()))
.copied()
.unwrap_or(!0usize)
> d + w
{
dist.insert((next, history.clone()), d + w);
heap.push((Reverse(d + w), next, history.clone()));
}
}
}
println!("-1");
}
urectanc