結果
| 問題 |
No.1534 おなかがいたい
|
| コンテスト | |
| ユーザー |
57tggx
|
| 提出日時 | 2021-05-21 13:32:43 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 2,000 ms |
| コード長 | 781 bytes |
| コンパイル時間 | 11,502 ms |
| コンパイル使用メモリ | 407,804 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-20 14:05:01 |
| 合計ジャッジ時間 | 12,505 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 19 |
ソースコード
use std::io::BufRead;
fn main() {
let input: Vec<_> = std::io::stdin()
.lock()
.lines()
.collect::<Result<_, _>>()
.unwrap();
let (s, empty) = input.split_first().unwrap();
assert!(empty.is_empty()); // 入力の 2 行目以降がないことをチェック
{
let s: Vec<_> = s.chars().collect();
assert!(matches!(s.len(), 1..=200_000)); // 文字数をチェック
assert!(s.iter().all(char::is_ascii_lowercase)); // 全て英小文字であることをチェック
}
fn solve(s: &str) -> Option<usize> {
let end = s.find("pain")?;
Some(1 + s[..end].matches("pon").count().checked_sub(2)?)
}
let ans: i32 = solve(s).map(|x| x as i32).unwrap_or(-1);
println!("{}", ans);
}
57tggx