結果
| 問題 | No.430 文字列検索 |
| コンテスト | |
| ユーザー |
akakimidori
|
| 提出日時 | 2019-10-05 02:13:11 |
| 言語 | Rust (1.94.0 + proconio + num + itertools) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,449 bytes |
| 記録 | |
| コンパイル時間 | 3,607 ms |
| コンパイル使用メモリ | 152,468 KB |
| 最終ジャッジ日時 | 2026-05-09 10:29:24 |
| 合計ジャッジ時間 | 5,387 ms |
|
ジャッジサーバーID (参考情報) |
judge2_1 / judge3_1 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
error: cannot explicitly borrow within an implicitly-borrowing pattern
--> src/main.rs:55:22
|
55 | Some(ref t) => {
| ^^^ explicit `ref` binding modifier not allowed when implicitly borrowing
|
= note: for more information, see <https://doc.rust-lang.org/reference/patterns.html#binding-modes>
note: matching on a reference type with a non-reference pattern implicitly borrows the contents
--> src/main.rs:55:17
|
55 | Some(ref t) => {
| ^^^^^^^^^^^ this non-reference pattern matches on a reference type `&_`
help: remove the unnecessary binding modifier
|
55 - Some(ref t) => {
55 + Some(t) => {
|
error: could not compile `main` (bin "main") due to 1 previous error
ソースコード
use std::io::Read;
const F: usize = 26;
type Link = Option<Box<Node>>;
struct Node {
cnt: u32,
next: [Link; F],
}
fn insert(mut t: Link, s: &[usize]) -> Link {
if t.is_none() {
t = Some(Box::new(Node {
cnt: 0,
next: Default::default(),
}));
}
let mut t = t.unwrap();
if s.len() == 0 {
t.cnt += 1;
} else {
let k = s[0];
let next = t.next[k].take();
t.next[k] = insert(next, &s[1..]);
}
Some(t)
}
fn convert(s: String) -> Vec<usize> {
let mut a = Vec::with_capacity(s.len());
for c in s.chars() {
let k = c as usize - 'A' as usize;
a.push(k);
}
a
}
fn run() {
let mut s = String::new();
std::io::stdin().read_to_string(&mut s).unwrap();
let mut it = s.trim().split_whitespace();
let s = convert(it.next().unwrap().to_string());
let n: usize = it.next().unwrap().parse().unwrap();
let mut t = None;
for _ in 0..n {
let a = convert(it.next().unwrap().to_string());
t = insert(t, &a);
}
let mut ans = 0;
for i in 0..s.len() {
let mut now = &t;
for &k in &s[i..] {
now = &now.as_ref().unwrap().next[k];
match now {
None => break,
Some(ref t) => {
ans += t.cnt;
}
}
}
}
println!("{}", ans);
}
fn main() {
run();
}
akakimidori