Skip to content

Instantly share code, notes, and snippets.

@qryxip
Last active November 12, 2019 11:01
Show Gist options
  • Save qryxip/fde7c4608a4674580220f16e35a63ba2 to your computer and use it in GitHub Desktop.
Save qryxip/fde7c4608a4674580220f16e35a63ba2 to your computer and use it in GitHub Desktop.
Template for AtCoder
//! ```cargo
//! [package]
//! name = "atcoder"
//! version = "0.0.0"
//! authors = ["Ryo Yamashita <qryxip@gmail.com>"]
//! edition = "2015"
//! license = "MIT"
//! ```
#![allow(unused_imports)]
/// Read whitespace-separated values from the stdin.
///
/// I used @tanakh's `input!` as reference, which is [currently licensed under MIT license](https://github.com/tanakh/competitive-rs).
///
/// ```text
/// The MIT License (MIT)
///
/// Copyright (c) 2016 Hideyuki Tanaka
///
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in all
/// copies or substantial portions of the Software.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
/// SOFTWARE.
/// ```
macro_rules! input {
($($name:ident : $t:tt),*,) => {
input!($($name: $t),*)
};
($($name:ident : $t:tt),*) => {
let mut _scanned = ::_input::Scanned::new(::std::io::stdin(), 1024);
$(
let $name = unsafe { _read_value!(_scanned, $t) };
)*
};
}
macro_rules! _read_value {
($scanned:expr, ($($t:tt),*)) => {
($(_read_value!($scanned, $t)),*)
};
($scanned:expr, 1based) => {
_read_value!($scanned, usize) - 1
};
($scanned:expr, [u8]) => {
_read_value!($scanned, String).into_bytes()
};
($scanned:expr, [$t:tt; $n:expr]) => {
(0..$n).map(|_| _read_value!($scanned, $t)).collect::<Vec<_>>()
};
($scanned:expr, $t:ty) => {
$scanned.next::<$t>()
};
}
mod _input {
use std::fmt;
use std::io::{self, Read};
use std::str::{self, FromStr};
pub struct Scanned {
buf: Vec<u8>,
pos: usize,
}
impl Scanned {
pub fn new<R: Read>(mut input: R, estimated: usize) -> Self {
let mut buf_ = Vec::with_capacity(estimated);
let _ = io::copy(&mut input, &mut buf_).unwrap();
debug_assert!(str::from_utf8(&buf_).is_ok());
debug_assert!(buf_.iter().all(|&c| u32::from(c) <= 0x7F));
Scanned { buf: buf_, pos: 0 }
}
#[inline]
pub unsafe fn next<T: FromStr>(&mut self) -> T
where
T::Err: fmt::Debug,
{
let mut start = None;
loop {
match (self.buf[self.pos], start.is_some()) {
(b' ', true) | (b'\n', true) => break,
(_, true) | (b' ', false) | (b'\n', false) => self.pos += 1,
(_, false) => start = Some(self.pos),
}
}
let target = &self.buf[start.unwrap()..self.pos];
str::from_utf8_unchecked(target).parse().unwrap()
}
}
}
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::io::{self, BufWriter, Read, Stderr, StderrLock, Stdout, StdoutLock, Write};
use std::iter::{self, Product, Sum};
use std::num::{ParseFloatError, ParseIntError};
use std::ops::{
Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Deref,
DerefMut, Div, DivAssign, Mul, MulAssign, Neg, Not, Rem, RemAssign, Sub, SubAssign,
};
use std::str::{self, FromStr};
use std::{char, cmp, f32, f64, fmt, i16, i32, i64, i8, mem, thread, u16, u32, u64, u8};
fn main() {
input! {
n: usize,
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment