結果
| 問題 |
No.346 チワワ数え上げ問題
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-09-22 23:20:02 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 1,708 bytes |
| コンパイル時間 | 13,198 ms |
| コンパイル使用メモリ | 377,932 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-19 03:47:40 |
| 合計ジャッジ時間 | 13,192 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 |
ソースコード
#[allow(unused_macros)]
macro_rules! debug {
($($a:expr),*) => {
#[cfg(debug_assertions)]
writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
}
}
#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};
fn main() {
let out = std::io::stdout();
let mut out = BufWriter::new(out.lock());
macro_rules! puts {
($($format:tt)*) => (write!(out,$($format)*).unwrap());
}
let stdin = std::io::stdin();
let mut sc = Scanner { reader: stdin.lock() };
let c:Vec<char> = sc.chars();
let n = c.len();
let mut acm = vec![0; n+1];
let mut cnt = 0;
for i in 0..n {
if c[i] == 'w' {
cnt += 1;
}
acm[i+1] = cnt;
}
let mut ans = 0usize;
for i in 0..n {
if c[i] == 'c' {
let w = acm[n] - acm[i];
ans += w*(w-1)/2;
}
}
puts!("{}\n", ans);
}
pub struct Scanner<R> {
reader: R,
}
impl<R: std::io::Read> Scanner<R> {
pub fn read<T: std::str::FromStr>(&mut self) -> T {
use std::io::Read;
let buf: String = self
.reader
.by_ref()
.bytes()
.map(|b| b.unwrap() as char)
.skip_while(|c| c.is_whitespace())
.take_while(|c| !c.is_whitespace())
.collect();
buf.parse::<T>().ok().expect("Parse error.")
}
pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
(0..n).map(|_| self.read()).collect()
}
pub fn chars(&mut self) -> Vec<char> {
self.read::<String>().chars().collect()
}
}