結果
| 問題 |
No.1512 作文
|
| コンテスト | |
| ユーザー |
fukafukatani
|
| 提出日時 | 2021-05-21 21:37:37 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 109 ms / 2,000 ms |
| コード長 | 1,244 bytes |
| コンパイル時間 | 20,024 ms |
| コンパイル使用メモリ | 400,916 KB |
| 実行使用メモリ | 14,848 KB |
| 最終ジャッジ日時 | 2024-10-10 08:09:57 |
| 合計ジャッジ時間 | 14,323 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 38 |
コンパイルメッセージ
warning: unused variable: `i`
--> src/main.rs:21:9
|
21 | for i in 0..n {
| ^ help: if this is intentional, prefix it with an underscore: `_i`
|
= note: `#[warn(unused_variables)]` on by default
ソースコード
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;
use std::ops::Bound::*;
#[allow(unused_macros)]
macro_rules! debug {
($($e:expr),*) => {
#[cfg(debug_assertions)]
$({
let (e, mut err) = (stringify!($e), std::io::stderr());
writeln!(err, "{} = {:?}", e, $e).unwrap()
})*
};
}
fn main() {
let n = read::<usize>();
let mut ss = vec![];
for i in 0..n {
let s = read::<String>().chars().collect::<Vec<_>>();
let mut s_sorted = s.clone();
s_sorted.sort();
if s.iter().zip(s_sorted.iter()).all(|(&a, &b)| a == b) {
ss.push(s);
}
}
ss.sort_by_key(|ref s| (s[s.len() - 1], s[0]));
let mut dp = vec![0i64; 26];
for s in ss {
let s_idx = s[0].to_digit(36).unwrap() as usize - 10;
let t_idx = s[s.len() - 1].to_digit(36).unwrap() as usize - 10;
for i in (0..=s_idx).rev() {
dp[t_idx] = max(dp[i] + s.len() as i64, dp[t_idx]);
}
}
println!("{}", dp.iter().max().unwrap());
}
fn read<T: std::str::FromStr>() -> T {
let mut s = String::new();
std::io::stdin().read_line(&mut s).ok();
s.trim().parse().ok().unwrap()
}
fukafukatani