結果
問題 | No.1362 [Zelkova 8th Tune] Black Sheep |
ユーザー |
![]() |
提出日時 | 2021-01-22 21:59:07 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 3 ms / 1,000 ms |
コード長 | 1,991 bytes |
コンパイル時間 | 15,524 ms |
コンパイル使用メモリ | 388,628 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-12-28 00:33:44 |
合計ジャッジ時間 | 17,094 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 38 |
ソースコード
use std::io::{BufRead, Write};struct Lines<B> { b: B, buf: Vec<u8> }impl<B: BufRead> Lines<B> {fn next(&mut self) -> &str {self.buf.clear();self.b.read_until(b'\n', &mut self.buf).ok();if self.buf.ends_with(&[b'\n']) {self.buf.pop();if self.buf.ends_with(&[b'\r']) {self.buf.pop();}}std::str::from_utf8(&self.buf).unwrap()}}macro_rules! parse {($s:expr, Usize1) => (parse!($s, usize) - 1);($s:expr, Bytes) => ($s.as_bytes().to_vec());($s:expr, Chars) => ($s.chars().collect::<Vec<_>>());($s:expr, $t:ty) => ($s.parse::<$t>().unwrap());}macro_rules! scan {($iter:expr, ($($t:ident),*)) => (($(scan!($iter, $t)),*));($iter:expr, [$t:ident]) => ($iter.map(|s| parse!(s, $t)).collect::<Vec<_>>());($iter:expr, $t:ident) => (parse!($iter.next().unwrap(), $t));}macro_rules! read {($lines:expr, [$t:tt; $n:expr]) => ((0..$n).map(|_| read!($lines, $t)).collect::<Vec<_>>());($lines:expr, $t:tt) => ({let iter = &mut $lines.next().split(' ');scan!(iter, $t)});}fn run<B: BufRead, W: Write>(mut lines: Lines<B>, mut writer: W) {let s = read!(lines, Bytes);let b0 = s.first().unwrap();let mut b1 = b0;let mut cnt = [0, 0];let mut pos = [0, 0];for (i, b) in s.iter().enumerate() {if b == b0 {cnt[0] += 1;pos[0] = i + 1;} else {b1 = b;cnt[1] += 1;pos[1] = i + 1;}}if cnt[0] == 1 {writeln!(writer, "{} {}", pos[0], *b0 as char).ok();} else {writeln!(writer, "{} {}", pos[1], *b1 as char).ok();}}fn main() {let (stdin, stdout) = (std::io::stdin(), std::io::stdout());let lines = Lines { b: stdin.lock(), buf: Vec::new() };run(lines, std::io::BufWriter::new(stdout.lock()));}