QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#223220 | #7606. Digital Nim | ucup-team296# | AC ✓ | 62ms | 9540kb | Rust | 26.4kb | 2023-10-21 22:38:34 | 2023-10-21 22:38:34 |
Judging History
answer
//
pub mod solution {
use crate::io::input::Input;
use crate::io::output::Output;
use crate::misc::memo::memoization_3d::Memoization3d;
use crate::misc::recursive_function::Callable3;
use crate::numbers::number_iterator::iterate;
type PreCalc = ();
fn solve(input: &mut Input, out: &mut Output, _test_case: usize, _data: &PreCalc) {
let mut mem = Memoization3d::new(18 * 9 + 1, 18, 18 * 9 + 1, |f, sum, digs, mut back| {
if digs != 0 {
for i in 0..10 {
back = f.call(sum + i, digs - 1, back);
}
back
} else {
if sum > back {
back + 1
} else {
0
}
}
});
let t = input.read_size();
for _ in 0..t {
let n = input.read_size();
let mut back = 0;
let v = iterate(1, n);
for (mut pref, digs, _) in v {
let mut sum = 0;
while pref > 0 {
sum += pref % 10;
pref /= 10;
}
back = mem.call(sum, digs, back);
}
if back == 0 {
out.print_line("Bajtek");
} else {
out.print_line("Algosia");
}
}
}
pub(crate) fn run(mut input: Input, mut output: Output) -> bool {
let pre_calc = ();
#[allow(dead_code)]
enum TestType {
Single,
MultiNumber,
MultiEof,
}
let test_type = TestType::Single;
match test_type {
TestType::Single => solve(&mut input, &mut output, 1, &pre_calc),
TestType::MultiNumber => {
let t = input.read();
for i in 1..=t {
solve(&mut input, &mut output, i, &pre_calc);
}
}
TestType::MultiEof => {
let mut i = 1;
while input.peek().is_some() {
solve(&mut input, &mut output, i, &pre_calc);
i += 1;
}
}
}
output.flush();
input.skip_whitespace();
input.peek().is_none()
}
}
pub mod collections {
pub mod md_arr {
pub mod arr3d {
use crate::collections::slice_ext::legacy_fill::LegacyFill;
use crate::io::input::{Input, Readable};
use crate::io::output::{Output, Writable};
use std::ops::{Index, IndexMut};
use std::vec::IntoIter;
#[derive(Clone, Eq, PartialEq)]
pub struct Arr3d<T> {
d1: usize,
d2: usize,
d3: usize,
data: Vec<T>,
}
impl<T: Clone> Arr3d<T> {
pub fn new(d1: usize, d2: usize, d3: usize, value: T) -> Self {
Self {
d1,
d2,
d3,
data: vec![value; d1 * d2 * d3],
}
}
}
impl<T> Arr3d<T> {
pub fn generate<F>(d1: usize, d2: usize, d3: usize, mut gen: F) -> Self
where
F: FnMut(usize, usize, usize) -> T,
{
let mut data = Vec::with_capacity(d1 * d2 * d3);
for i in 0usize..d1 {
for j in 0usize..d2 {
for k in 0..d3 {
data.push(gen(i, j, k));
}
}
}
Self { d1, d2, d3, data }
}
pub fn d1(&self) -> usize {
self.d1
}
pub fn d2(&self) -> usize {
self.d2
}
pub fn d3(&self) -> usize {
self.d3
}
pub fn iter(&self) -> impl Iterator<Item = &T> {
self.data.iter()
}
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T> {
self.data.iter_mut()
}
}
impl<T> IntoIterator for Arr3d<T> {
type Item = T;
type IntoIter = IntoIter<T>;
fn into_iter(self) -> Self::IntoIter {
self.data.into_iter()
}
}
impl<T> Index<(usize, usize, usize)> for Arr3d<T> {
type Output = T;
fn index(&self, (a1, a2, a3): (usize, usize, usize)) -> &Self::Output {
assert!(a1 < self.d1);
assert!(a2 < self.d2);
assert!(a3 < self.d3);
&self.data[(a1 * self.d2 + a2) * self.d3 + a3]
}
}
impl<T> IndexMut<(usize, usize, usize)> for Arr3d<T> {
fn index_mut(&mut self, (a1, a2, a3): (usize, usize, usize)) -> &mut Self::Output {
assert!(a1 < self.d1);
assert!(a2 < self.d2);
assert!(a3 < self.d3);
&mut self.data[(a1 * self.d2 + a2) * self.d3 + a3]
}
}
impl<T: Writable> Writable for Arr3d<T> {
fn write(&self, output: &mut Output) {
let mut at = 0usize;
for i in 0..self.d1 {
if i != 0 {
output.put(b'\n');
}
for j in 0..self.d2 {
if j != 0 {
output.put(b'\n');
}
for k in 0..self.d3 {
if k != 0 {
output.put(b' ');
}
self.data[at].write(output);
at += 1;
}
}
}
}
}
pub trait Arr3dRead {
fn read_3d_table<T: Readable>(&mut self, d1: usize, d2: usize, d3: usize) -> Arr3d<T>;
}
impl Arr3dRead for Input<'_> {
fn read_3d_table<T: Readable>(&mut self, d1: usize, d2: usize, d3: usize) -> Arr3d<T> {
Arr3d::generate(d1, d2, d3, |_, _, _| self.read())
}
}
impl<T: Readable> Readable for Arr3d<T> {
fn read(input: &mut Input) -> Self {
let d1 = input.read();
let d2 = input.read();
let d3 = input.read();
input.read_3d_table(d1, d2, d3)
}
}
impl<T: Clone> Arr3d<T> {
pub fn fill(&mut self, elem: T) {
self.data.legacy_fill(elem);
}
}
}
}
pub mod slice_ext {
pub mod legacy_fill {
// 1.50
pub trait LegacyFill<T> {
fn legacy_fill(&mut self, val: T);
}
impl<T: Clone> LegacyFill<T> for [T] {
fn legacy_fill(&mut self, val: T) {
for el in self.iter_mut() {
*el = val.clone();
}
}
}
}
}
pub mod vec_ext {
pub mod default {
pub fn default_vec<T: Default>(len: usize) -> Vec<T> {
let mut v = Vec::with_capacity(len);
for _ in 0..len {
v.push(T::default());
}
v
}
}
}
}
pub mod io {
pub mod input {
use crate::collections::vec_ext::default::default_vec;
use std::io::Read;
pub struct Input<'s> {
input: &'s mut dyn Read,
buf: Vec<u8>,
at: usize,
buf_read: usize,
}
macro_rules! read_impl {
($t: ty, $read_name: ident, $read_vec_name: ident) => {
pub fn $read_name(&mut self) -> $t {
self.read()
}
pub fn $read_vec_name(&mut self, len: usize) -> Vec<$t> {
self.read_vec(len)
}
};
($t: ty, $read_name: ident, $read_vec_name: ident, $read_pair_vec_name: ident) => {
read_impl!($t, $read_name, $read_vec_name);
pub fn $read_pair_vec_name(&mut self, len: usize) -> Vec<($t, $t)> {
self.read_vec(len)
}
};
}
impl<'s> Input<'s> {
const DEFAULT_BUF_SIZE: usize = 4096;
pub fn new(input: &'s mut dyn Read) -> Self {
Self {
input,
buf: default_vec(Self::DEFAULT_BUF_SIZE),
at: 0,
buf_read: 0,
}
}
pub fn new_with_size(input: &'s mut dyn Read, buf_size: usize) -> Self {
Self {
input,
buf: default_vec(buf_size),
at: 0,
buf_read: 0,
}
}
pub fn get(&mut self) -> Option<u8> {
if self.refill_buffer() {
let res = self.buf[self.at];
self.at += 1;
if res == b'\r' {
if self.refill_buffer() && self.buf[self.at] == b'\n' {
self.at += 1;
}
return Some(b'\n');
}
Some(res)
} else {
None
}
}
pub fn peek(&mut self) -> Option<u8> {
if self.refill_buffer() {
let res = self.buf[self.at];
Some(if res == b'\r' { b'\n' } else { res })
} else {
None
}
}
pub fn skip_whitespace(&mut self) {
while let Some(b) = self.peek() {
if !char::from(b).is_whitespace() {
return;
}
self.get();
}
}
pub fn next_token(&mut self) -> Option<Vec<u8>> {
self.skip_whitespace();
let mut res = Vec::new();
while let Some(c) = self.get() {
if char::from(c).is_whitespace() {
break;
}
res.push(c);
}
if res.is_empty() {
None
} else {
Some(res)
}
}
//noinspection RsSelfConvention
pub fn is_exhausted(&mut self) -> bool {
self.peek().is_none()
}
pub fn read<T: Readable>(&mut self) -> T {
T::read(self)
}
pub fn read_vec<T: Readable>(&mut self, size: usize) -> Vec<T> {
let mut res = Vec::with_capacity(size);
for _ in 0..size {
res.push(self.read());
}
res
}
pub fn read_char(&mut self) -> char {
self.skip_whitespace();
self.get().unwrap().into()
}
read_impl!(u32, read_unsigned, read_unsigned_vec);
read_impl!(u64, read_u64, read_u64_vec);
read_impl!(usize, read_size, read_size_vec, read_size_pair_vec);
read_impl!(i32, read_int, read_int_vec, read_int_pair_vec);
read_impl!(i64, read_long, read_long_vec, read_long_pair_vec);
read_impl!(i128, read_i128, read_i128_vec);
fn refill_buffer(&mut self) -> bool {
if self.at == self.buf_read {
self.at = 0;
self.buf_read = self.input.read(&mut self.buf).unwrap();
self.buf_read != 0
} else {
true
}
}
}
pub trait Readable {
fn read(input: &mut Input) -> Self;
}
impl Readable for char {
fn read(input: &mut Input) -> Self {
input.read_char()
}
}
impl<T: Readable> Readable for Vec<T> {
fn read(input: &mut Input) -> Self {
let size = input.read();
input.read_vec(size)
}
}
macro_rules! read_integer {
($($t:ident)+) => {$(
impl Readable for $t {
fn read(input: &mut Input) -> Self {
input.skip_whitespace();
let mut c = input.get().unwrap();
let sgn = match c {
b'-' => {
c = input.get().unwrap();
true
}
b'+' => {
c = input.get().unwrap();
false
}
_ => false,
};
let mut res = 0;
loop {
assert!(c.is_ascii_digit());
res *= 10;
let d = (c - b'0') as $t;
if sgn {
res -= d;
} else {
res += d;
}
match input.get() {
None => break,
Some(ch) => {
if ch.is_ascii_whitespace() {
break;
} else {
c = ch;
}
}
}
}
res
}
}
)+};
}
read_integer!(i8 i16 i32 i64 i128 isize u8 u16 u32 u64 u128 usize);
macro_rules! tuple_readable {
($($name:ident)+) => {
impl<$($name: Readable), +> Readable for ($($name,)+) {
fn read(input: &mut Input) -> Self {
($($name::read(input),)+)
}
}
}
}
tuple_readable! {T}
tuple_readable! {T U}
tuple_readable! {T U V}
tuple_readable! {T U V X}
tuple_readable! {T U V X Y}
tuple_readable! {T U V X Y Z}
tuple_readable! {T U V X Y Z A}
tuple_readable! {T U V X Y Z A B}
tuple_readable! {T U V X Y Z A B C}
tuple_readable! {T U V X Y Z A B C D}
tuple_readable! {T U V X Y Z A B C D E}
tuple_readable! {T U V X Y Z A B C D E F}
impl Read for Input<'_> {
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
if self.at == self.buf_read {
self.input.read(buf)
} else {
let mut i = 0;
while i < buf.len() && self.at < self.buf_read {
buf[i] = self.buf[self.at];
i += 1;
self.at += 1;
}
Ok(i)
}
}
}
}
pub mod output {
use crate::collections::vec_ext::default::default_vec;
use std::io::{stderr, Stderr, Write};
#[derive(Copy, Clone)]
pub enum BoolOutput {
YesNo,
YesNoCaps,
PossibleImpossible,
Custom(&'static str, &'static str),
}
impl BoolOutput {
pub fn output(&self, output: &mut Output, val: bool) {
(if val { self.yes() } else { self.no() }).write(output);
}
fn yes(&self) -> &str {
match self {
BoolOutput::YesNo => "Yes",
BoolOutput::YesNoCaps => "YES",
BoolOutput::PossibleImpossible => "Possible",
BoolOutput::Custom(yes, _) => yes,
}
}
fn no(&self) -> &str {
match self {
BoolOutput::YesNo => "No",
BoolOutput::YesNoCaps => "NO",
BoolOutput::PossibleImpossible => "Impossible",
BoolOutput::Custom(_, no) => no,
}
}
}
pub struct Output<'s> {
output: &'s mut dyn Write,
buf: Vec<u8>,
at: usize,
auto_flush: bool,
bool_output: BoolOutput,
}
impl<'s> Output<'s> {
const DEFAULT_BUF_SIZE: usize = 4096;
pub fn new(output: &'s mut dyn Write) -> Self {
Self {
output,
buf: default_vec(Self::DEFAULT_BUF_SIZE),
at: 0,
auto_flush: false,
bool_output: BoolOutput::YesNoCaps,
}
}
pub fn new_with_auto_flush(output: &'s mut dyn Write) -> Self {
Self {
output,
buf: default_vec(Self::DEFAULT_BUF_SIZE),
at: 0,
auto_flush: true,
bool_output: BoolOutput::YesNoCaps,
}
}
pub fn flush(&mut self) {
if self.at != 0 {
self.output.write_all(&self.buf[..self.at]).unwrap();
self.output.flush().unwrap();
self.at = 0;
}
}
pub fn print<T: Writable>(&mut self, s: T) {
s.write(self);
self.maybe_flush();
}
pub fn print_line<T: Writable>(&mut self, s: T) {
self.print(s);
self.put(b'\n');
self.maybe_flush();
}
pub fn put(&mut self, b: u8) {
self.buf[self.at] = b;
self.at += 1;
if self.at == self.buf.len() {
self.flush();
}
}
pub fn maybe_flush(&mut self) {
if self.auto_flush {
self.flush();
}
}
pub fn print_per_line<T: Writable>(&mut self, arg: &[T]) {
for i in arg {
i.write(self);
self.put(b'\n');
}
}
pub fn print_iter<T: Writable, I: Iterator<Item = T>>(&mut self, iter: I) {
let mut first = true;
for e in iter {
if first {
first = false;
} else {
self.put(b' ');
}
e.write(self);
}
}
pub fn print_iter_ref<'a, T: 'a + Writable, I: Iterator<Item = &'a T>>(&mut self, iter: I) {
let mut first = true;
for e in iter {
if first {
first = false;
} else {
self.put(b' ');
}
e.write(self);
}
}
pub fn set_bool_output(&mut self, bool_output: BoolOutput) {
self.bool_output = bool_output;
}
}
impl Write for Output<'_> {
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
let mut start = 0usize;
let mut rem = buf.len();
while rem > 0 {
let len = (self.buf.len() - self.at).min(rem);
self.buf[self.at..self.at + len].copy_from_slice(&buf[start..start + len]);
self.at += len;
if self.at == self.buf.len() {
self.flush();
}
start += len;
rem -= len;
}
self.maybe_flush();
Ok(buf.len())
}
fn flush(&mut self) -> std::io::Result<()> {
self.flush();
Ok(())
}
}
pub trait Writable {
fn write(&self, output: &mut Output);
}
impl Writable for &str {
fn write(&self, output: &mut Output) {
output.write_all(self.as_bytes()).unwrap();
}
}
impl Writable for String {
fn write(&self, output: &mut Output) {
output.write_all(self.as_bytes()).unwrap();
}
}
impl Writable for char {
fn write(&self, output: &mut Output) {
output.put(*self as u8);
}
}
impl<T: Writable> Writable for [T] {
fn write(&self, output: &mut Output) {
output.print_iter_ref(self.iter());
}
}
impl<T: Writable, const N: usize> Writable for [T; N] {
fn write(&self, output: &mut Output) {
output.print_iter_ref(self.iter());
}
}
impl<T: Writable> Writable for &T {
fn write(&self, output: &mut Output) {
T::write(self, output)
}
}
impl<T: Writable> Writable for Vec<T> {
fn write(&self, output: &mut Output) {
self.as_slice().write(output);
}
}
impl Writable for () {
fn write(&self, _output: &mut Output) {}
}
macro_rules! write_to_string {
($($t:ident)+) => {$(
impl Writable for $t {
fn write(&self, output: &mut Output) {
self.to_string().write(output);
}
}
)+};
}
write_to_string!(u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize);
macro_rules! tuple_writable {
($name0:ident $($name:ident: $id:tt )*) => {
impl<$name0: Writable, $($name: Writable,)*> Writable for ($name0, $($name,)*) {
fn write(&self, out: &mut Output) {
self.0.write(out);
$(
out.put(b' ');
self.$id.write(out);
)*
}
}
}
}
tuple_writable! {T}
tuple_writable! {T U:1}
tuple_writable! {T U:1 V:2}
tuple_writable! {T U:1 V:2 X:3}
tuple_writable! {T U:1 V:2 X:3 Y:4}
tuple_writable! {T U:1 V:2 X:3 Y:4 Z:5}
tuple_writable! {T U:1 V:2 X:3 Y:4 Z:5 A:6}
tuple_writable! {T U:1 V:2 X:3 Y:4 Z:5 A:6 B:7}
impl<T: Writable> Writable for Option<T> {
fn write(&self, output: &mut Output) {
match self {
None => (-1).write(output),
Some(t) => t.write(output),
}
}
}
impl Writable for bool {
fn write(&self, output: &mut Output) {
let bool_output = output.bool_output;
bool_output.output(output, *self)
}
}
static mut ERR: Option<Stderr> = None;
pub fn err() -> Output<'static> {
unsafe {
if ERR.is_none() {
ERR = Some(stderr());
}
Output::new_with_auto_flush(ERR.as_mut().unwrap())
}
}
}
}
pub mod misc {
pub mod memo {
pub mod memoization_3d {
use crate::collections::md_arr::arr3d::Arr3d;
use crate::misc::recursive_function::Callable3;
pub struct Memoization3d<F, Output>
where
F: FnMut(&mut dyn Callable3<usize, usize, usize, Output>, usize, usize, usize) -> Output,
{
f: std::cell::UnsafeCell<F>,
res: Arr3d<Option<Output>>,
}
impl<F, Output: Clone> Memoization3d<F, Output>
where
F: FnMut(&mut dyn Callable3<usize, usize, usize, Output>, usize, usize, usize) -> Output,
{
pub fn new(d1: usize, d2: usize, d3: usize, f: F) -> Self {
Self {
f: std::cell::UnsafeCell::new(f),
res: Arr3d::new(d1, d2, d3, None),
}
}
}
impl<F, Output: Clone> Callable3<usize, usize, usize, Output> for Memoization3d<F, Output>
where
F: FnMut(&mut dyn Callable3<usize, usize, usize, Output>, usize, usize, usize) -> Output,
{
fn call(&mut self, a1: usize, a2: usize, a3: usize) -> Output {
match self.res[(a1, a2, a3)].as_ref() {
None => {
let res = unsafe { (*self.f.get())(self, a1, a2, a3) };
self.res[(a1, a2, a3)] = Some(res.clone());
res
}
Some(res) => res.clone(),
}
}
}
}
}
pub mod recursive_function {
use std::marker::PhantomData;
macro_rules! recursive_function {
($name: ident, $trait: ident, ($($type: ident $arg: ident,)*)) => {
pub trait $trait<$($type, )*Output> {
fn call(&mut self, $($arg: $type,)*) -> Output;
}
pub struct $name<F, $($type, )*Output>
where
F: FnMut(&mut dyn $trait<$($type, )*Output>, $($type, )*) -> Output,
{
f: std::cell::UnsafeCell<F>,
$($arg: PhantomData<$type>,
)*
phantom_output: PhantomData<Output>,
}
impl<F, $($type, )*Output> $name<F, $($type, )*Output>
where
F: FnMut(&mut dyn $trait<$($type, )*Output>, $($type, )*) -> Output,
{
pub fn new(f: F) -> Self {
Self {
f: std::cell::UnsafeCell::new(f),
$($arg: Default::default(),
)*
phantom_output: Default::default(),
}
}
}
impl<F, $($type, )*Output> $trait<$($type, )*Output> for $name<F, $($type, )*Output>
where
F: FnMut(&mut dyn $trait<$($type, )*Output>, $($type, )*) -> Output,
{
fn call(&mut self, $($arg: $type,)*) -> Output {
unsafe { (*self.f.get())(self, $($arg, )*) }
}
}
}
}
recursive_function!(RecursiveFunction0, Callable0, ());
recursive_function!(RecursiveFunction, Callable, (Arg arg,));
recursive_function!(RecursiveFunction2, Callable2, (Arg1 arg1, Arg2 arg2,));
recursive_function!(RecursiveFunction3, Callable3, (Arg1 arg1, Arg2 arg2, Arg3 arg3,));
recursive_function!(RecursiveFunction4, Callable4, (Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4,));
recursive_function!(RecursiveFunction5, Callable5, (Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5,));
recursive_function!(RecursiveFunction6, Callable6, (Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6,));
recursive_function!(RecursiveFunction7, Callable7, (Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6, Arg7 arg7,));
recursive_function!(RecursiveFunction8, Callable8, (Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6, Arg7 arg7, Arg8 arg8,));
recursive_function!(RecursiveFunction9, Callable9, (Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6, Arg7 arg7, Arg8 arg8, Arg9 arg9,));
}
}
pub mod numbers {
pub mod num_traits {
pub mod add_sub {
use std::ops::{Add, AddAssign, Sub, SubAssign};
pub trait Addable: Add<Output = Self> + AddAssign + Copy {}
impl<T: Add<Output = Self> + AddAssign + Copy> Addable for T {}
pub trait AddSub: Addable + Sub<Output = Self> + SubAssign {}
impl<T: Addable + Sub<Output = Self> + SubAssign> AddSub for T {}
}
pub mod from_u8 {
pub trait FromU8 {
fn from_u8(val: u8) -> Self;
}
macro_rules! from_u8_impl {
($($t: ident)+) => {$(
impl FromU8 for $t {
fn from_u8(val: u8) -> Self {
val as $t
}
}
)+};
}
from_u8_impl!(i128 i64 i32 i16 i8 isize u128 u64 u32 u16 u8 usize);
}
pub mod mul_div_rem {
use std::ops::{Div, DivAssign, Mul, MulAssign, Rem, RemAssign};
pub trait Multable: Mul<Output = Self> + MulAssign + Copy {}
impl<T: Mul<Output = Self> + MulAssign + Copy> Multable for T {}
pub trait MulDiv: Multable + Div<Output = Self> + DivAssign {}
impl<T: Multable + Div<Output = Self> + DivAssign> MulDiv for T {}
pub trait MulDivRem: MulDiv + Rem<Output = Self> + RemAssign {}
impl<T: MulDiv + Rem<Output = Self> + RemAssign> MulDivRem for T {}
}
pub mod ord {
pub trait MinMax: PartialOrd {
fn min_val() -> Self;
fn max_val() -> Self;
#[must_use]
fn minimum(self, other: Self) -> Self;
#[must_use]
fn maximum(self, other: Self) -> Self;
}
macro_rules! min_max_integer_impl {
($($t: ident)+) => {$(
impl MinMax for $t {
fn min_val() -> Self {
// 1.43
std::$t::MIN
}
fn max_val() -> Self {
// 1.43
std::$t::MAX
}
fn minimum(self, other: Self) -> Self {
Self::min(self, other)
}
fn maximum(self, other: Self) -> Self {
Self::max(self, other)
}
}
)+};
}
min_max_integer_impl!(i128 i64 i32 i16 i8 isize u128 u64 u32 u16 u8 usize);
}
pub mod zero_one {
pub trait ZeroOne {
fn zero() -> Self;
fn one() -> Self;
}
macro_rules! zero_one_integer_impl {
($($t: ident)+) => {$(
impl ZeroOne for $t {
fn zero() -> Self {
0
}
fn one() -> Self {
1
}
}
)+};
}
zero_one_integer_impl!(i128 i64 i32 i16 i8 isize u128 u64 u32 u16 u8 usize);
}
}
pub mod number_iterator {
use crate::numbers::num_traits::add_sub::Addable;
use crate::numbers::num_traits::from_u8::FromU8;
use crate::numbers::num_traits::mul_div_rem::MulDiv;
use crate::numbers::num_traits::ord::MinMax;
use crate::numbers::num_traits::zero_one::ZeroOne;
pub fn iterate<T: Copy + Addable + MulDiv + ZeroOne + FromU8 + Ord + MinMax>(
from: T,
to: T,
) -> Vec<(T, usize, T)> {
iterate_with_base(from, to, T::from_u8(10))
}
pub fn iterate_with_base<T: Copy + Addable + MulDiv + ZeroOne + Ord + MinMax>(
mut from: T,
mut to: T,
base: T,
) -> Vec<(T, usize, T)> {
let mut pw = T::one();
to += T::one();
let mut res = Vec::new();
let mut i = 0usize;
loop {
let end = T::max_val() / base < pw || from / (pw * base) == to / (pw * base);
if end {
let c_from = from / pw;
let c_to = to / pw;
let mut cur = c_from;
while cur < c_to {
res.push((cur, i, cur * pw));
cur += T::one();
}
break;
}
let c_from = from / pw;
let c_to = (from / (pw * base) + T::one()) * base;
let mut cur = c_from;
while cur < c_to {
res.push((cur, i, cur * pw));
cur += T::one();
}
from = c_to * pw;
let c_from = to / (pw * base) * base;
let c_to = to / pw;
let mut cur = c_from;
while cur < c_to {
res.push((cur, i, cur * pw));
cur += T::one();
}
i += 1;
pw *= base;
}
res.sort_by(|a, b| a.2.cmp(&b.2));
res
}
}
}
fn main() {
let mut sin = std::io::stdin();
let input = if false {
io::input::Input::new_with_size(&mut sin, 1)
} else {
io::input::Input::new(&mut sin)
};
let mut stdout = std::io::stdout();
let output = if false {
io::output::Output::new_with_auto_flush(&mut stdout)
} else {
io::output::Output::new(&mut stdout)
};
solution::run(input, output);
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 9316kb
input:
4 1 10 42 190
output:
Algosia Bajtek Algosia Algosia
result:
ok 4 lines
Test #2:
score: 0
Accepted
time: 2ms
memory: 9368kb
input:
1 1
output:
Algosia
result:
ok single line: 'Algosia'
Test #3:
score: 0
Accepted
time: 6ms
memory: 9540kb
input:
10000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 10...
output:
Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Bajtek Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Bajtek Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Bajtek Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia...
result:
ok 10000 lines
Test #4:
score: 0
Accepted
time: 11ms
memory: 9504kb
input:
10000 86 385 545 561 563 770 831 859 1123 1218 1423 1437 1602 1650 1884 1960 2096 2160 2330 2552 2662 2762 3359 3382 3425 3556 3606 3669 3790 3962 3980 4009 4060 4128 4418 4424 4458 4483 4510 4540 4594 4659 4704 4766 4822 4946 5073 5139 5195 5225 5267 5390 5490 5557 5885 6171 6235 6307 6371 6442 645...
output:
Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Bajtek Algosia Bajtek Bajtek Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia...
result:
ok 10000 lines
Test #5:
score: 0
Accepted
time: 25ms
memory: 9388kb
input:
10000 63282 121076 318636 395380 405847 473533 850891 859227 876990 877183 1202581 1360154 1416399 1450189 1603717 1618175 1636686 1648221 1649807 1652127 1714183 1730743 1766595 1813769 1883327 1909563 2033458 2034831 2054278 2365137 2398438 2431649 2544385 2591344 2781989 2799879 2946371 3081362 3...
output:
Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Bajtek Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algos...
result:
ok 10000 lines
Test #6:
score: 0
Accepted
time: 36ms
memory: 9364kb
input:
10000 55974796 164367751 726067320 832933581 839242663 874743324 924711240 1273805641 1293241492 1502671500 1580201972 1866598988 1875214768 1887602218 2187236520 2190435343 2200271756 2222335108 2298443856 2312384848 2553086341 2728080634 2847195043 2941043887 3015534723 3032934075 3042416569 30536...
output:
Algosia Algosia Bajtek Algosia Algosia Algosia Algosia Algosia Algosia Bajtek Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosi...
result:
ok 10000 lines
Test #7:
score: 0
Accepted
time: 46ms
memory: 9348kb
input:
10000 226734696862 331363710798 571908782674 587317947192 712617926622 750076643202 845071930320 900747937168 1029215192240 1236146558335 1390866543043 1421889212655 1678882652961 1860532340178 1919377401251 2008873081380 2015692609997 2195759385338 2467741475021 2486222596605 2634516025808 26507182...
output:
Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algo...
result:
ok 10000 lines
Test #8:
score: 0
Accepted
time: 59ms
memory: 9452kb
input:
10000 124622741096106 127915048407795 338055966544572 424759758772639 540891121626578 884552643212757 918897131418487 1038990284375115 1043645564945444 1091151047570719 1131685140698119 1179792323538604 1218106719409451 1308943890457408 1401629782270253 1553755285224054 1685066123444970 175412220254...
output:
Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Bajtek Algosia Algosia Algosia Bajtek Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosi...
result:
ok 10000 lines
Test #9:
score: 0
Accepted
time: 58ms
memory: 9404kb
input:
10000 1 12040017006426 36919715476907 130350585855721 221622468425134 272540915018120 364336484657993 478643981515498 557794141673071 606233096811090 775089479486393 893004821985325 902237988318842 1130499645664726 1195851979931148 1414028882291509 1655625823710955 1755276365843095 2018579471606792 ...
output:
Algosia Algosia Algosia Algosia Algosia Bajtek Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algos...
result:
ok 10000 lines
Test #10:
score: 0
Accepted
time: 62ms
memory: 9500kb
input:
10000 999999999999990001 999999999999990002 999999999999990003 999999999999990004 999999999999990005 999999999999990006 999999999999990007 999999999999990008 999999999999990009 999999999999990010 999999999999990011 999999999999990012 999999999999990013 999999999999990014 999999999999990015 999999999...
output:
Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Bajtek Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algos...
result:
ok 10000 lines
Test #11:
score: 0
Accepted
time: 15ms
memory: 9492kb
input:
10000 70 117 160 240 250 300 380 490 657 714 1120 1160 1220 1257 1320 1340 1373 1410 1480 1593 1636 1790 1800 1820 1860 2104 2130 2160 2191 2240 2340 2447 2500 2630 2780 2820 2860 3069 3200 3220 3240 3418 3420 3460 3500 3590 3700 3720 3820 3855 3960 4050 4270 4280 4300 4505 4700 4866 4899 4950 5060 ...
output:
Bajtek Algosia Bajtek Bajtek Bajtek Bajtek Bajtek Bajtek Algosia Algosia Bajtek Bajtek Bajtek Algosia Bajtek Bajtek Algosia Bajtek Bajtek Algosia Algosia Bajtek Bajtek Bajtek Bajtek Algosia Bajtek Bajtek Algosia Bajtek Bajtek Algosia Bajtek Bajtek Bajtek Bajtek Bajtek Algosia Bajtek Bajtek Bajtek Al...
result:
ok 10000 lines
Test #12:
score: 0
Accepted
time: 20ms
memory: 9384kb
input:
10000 233670 263580 429860 854050 873291 1086178 1304670 1321550 1328046 1406784 1426400 1477950 1486792 1684240 1795146 1852820 1853080 1912430 2191240 2197854 2203980 2283121 2338700 2420280 2535760 2583393 2641220 2662760 2815271 2904030 3004200 3005800 3088730 3163300 3308385 3327308 3370803 342...
output:
Bajtek Bajtek Bajtek Bajtek Algosia Algosia Bajtek Algosia Algosia Algosia Bajtek Bajtek Algosia Bajtek Algosia Algosia Bajtek Algosia Bajtek Algosia Bajtek Algosia Bajtek Bajtek Bajtek Algosia Bajtek Bajtek Algosia Algosia Bajtek Bajtek Bajtek Bajtek Algosia Algosia Algosia Algosia Algosia Algosia ...
result:
ok 10000 lines
Test #13:
score: 0
Accepted
time: 31ms
memory: 9320kb
input:
10000 37768120 150180510 229863847 560379800 586663800 658215455 700419092 842166110 1099982656 1196035589 1212804381 1276766090 1340726750 1439493400 1485368600 1552383430 1571761867 1619040412 1639555800 1756888955 1878781302 1906920599 2006336430 2034670454 2128404710 2172553769 2343552940 235525...
output:
Bajtek Bajtek Algosia Bajtek Bajtek Algosia Algosia Bajtek Algosia Algosia Algosia Bajtek Bajtek Bajtek Bajtek Bajtek Algosia Algosia Bajtek Algosia Algosia Algosia Bajtek Algosia Bajtek Algosia Bajtek Bajtek Algosia Algosia Bajtek Algosia Algosia Bajtek Bajtek Bajtek Bajtek Bajtek Algosia Bajtek Al...
result:
ok 10000 lines
Test #14:
score: 0
Accepted
time: 42ms
memory: 9308kb
input:
10000 140411141830 370827567460 432745525710 437369528100 451414954866 548449130655 582806101555 584683156587 840808279410 850593238720 922032818220 932201709949 976847660068 980705147940 1015231086577 1079623223909 1188227310354 1208869181620 1257901597290 1387458748506 1430129564600 1514175866070 ...
output:
Bajtek Bajtek Algosia Bajtek Algosia Algosia Algosia Algosia Bajtek Bajtek Bajtek Algosia Algosia Bajtek Algosia Algosia Algosia Bajtek Bajtek Algosia Bajtek Bajtek Bajtek Bajtek Bajtek Algosia Bajtek Bajtek Bajtek Bajtek Algosia Algosia Algosia Algosia Algosia Algosia Algosia Bajtek Bajtek Algosia ...
result:
ok 10000 lines
Test #15:
score: 0
Accepted
time: 56ms
memory: 9296kb
input:
10000 68839458383200 122548893723820 189239968438380 214424448493520 260360126583970 307063514207551 343073386643240 528994809938142 578589436821610 586247296648460 760004635119421 772309204371700 777998567649100 845471647736690 858069088401550 1186547393187216 1241694321320137 1450552266461060 1521...
output:
Bajtek Bajtek Bajtek Bajtek Algosia Algosia Bajtek Algosia Bajtek Bajtek Algosia Bajtek Bajtek Bajtek Bajtek Algosia Algosia Bajtek Algosia Algosia Bajtek Bajtek Algosia Bajtek Algosia Algosia Bajtek Bajtek Bajtek Bajtek Algosia Bajtek Bajtek Bajtek Algosia Algosia Bajtek Algosia Bajtek Algosia Bajt...
result:
ok 10000 lines
Test #16:
score: 0
Accepted
time: 32ms
memory: 9452kb
input:
10000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 10...
output:
Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Bajtek Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Bajtek Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Bajtek Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia...
result:
ok 10000 lines
Test #17:
score: 0
Accepted
time: 33ms
memory: 9540kb
input:
10000 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200 210 220 230 240 250 260 270 280 290 300 310 320 330 340 350 360 370 380 390 400 410 420 430 440 450 460 470 480 490 500 510 520 530 540 550 560 570 580 590 600 610 620 630 640 650 660 670 680 690 700 710 720 730 740 750 760...
output:
Bajtek Bajtek Bajtek Bajtek Bajtek Bajtek Bajtek Bajtek Bajtek Bajtek Bajtek Bajtek Bajtek Bajtek Bajtek Bajtek Bajtek Bajtek Algosia Bajtek Bajtek Bajtek Bajtek Bajtek Bajtek Bajtek Bajtek Algosia Bajtek Bajtek Bajtek Bajtek Bajtek Bajtek Bajtek Bajtek Algosia Bajtek Algosia Bajtek Bajtek Bajtek Ba...
result:
ok 10000 lines
Test #18:
score: 0
Accepted
time: 7ms
memory: 9332kb
input:
10000 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200 210 220 230 240 250 260 270 280 290 300 310 320 330 340 350 360 370 380 390 400 410 420 430 440 450 460 470 480 490 500 510 520 530 540 550 560 570 580 590 600 610 620 630 640 650 660 670 680 690 700 710 720 730 740 750 760...
output:
Bajtek Bajtek Bajtek Bajtek Bajtek Bajtek Bajtek Bajtek Bajtek Bajtek Bajtek Bajtek Bajtek Bajtek Bajtek Bajtek Bajtek Bajtek Algosia Bajtek Bajtek Bajtek Bajtek Bajtek Bajtek Bajtek Bajtek Algosia Bajtek Bajtek Bajtek Bajtek Bajtek Bajtek Bajtek Bajtek Algosia Bajtek Algosia Bajtek Bajtek Bajtek Ba...
result:
ok 10000 lines
Test #19:
score: 0
Accepted
time: 15ms
memory: 9296kb
input:
10000 10 40 110 140 190 290 400 410 460 590 760 810 1000 1060 1290 1450 1500 1660 1730 1800 2300 2450 2520 2630 2640 2750 2880 2920 3310 3500 3670 3710 4010 4020 4040 4080 4100 4230 4280 4520 4680 4730 4840 5150 5340 5390 5400 5490 5570 5760 5830 5960 5990 6010 6050 6080 6100 6130 6170 6230 6250 629...
output:
Bajtek Bajtek Bajtek Bajtek Algosia Bajtek Bajtek Bajtek Algosia Algosia Bajtek Bajtek Bajtek Bajtek Algosia Algosia Bajtek Bajtek Bajtek Bajtek Bajtek Bajtek Bajtek Bajtek Algosia Algosia Bajtek Bajtek Bajtek Bajtek Algosia Algosia Bajtek Bajtek Bajtek Algosia Bajtek Bajtek Algosia Bajtek Bajtek Al...
result:
ok 10000 lines
Test #20:
score: 0
Accepted
time: 24ms
memory: 9464kb
input:
10000 187980 682630 818640 1044370 1063650 1091690 1113430 1481670 1511400 1605690 1683890 1707110 1863100 1939890 2016730 2269950 2276800 2354240 2465340 2520450 2580240 2786890 2889490 3180360 3281200 3362740 3386330 3483110 3486660 3514470 3524380 3729260 3842500 3904700 3907560 4028620 4075380 4...
output:
Algosia Bajtek Algosia Algosia Bajtek Algosia Algosia Bajtek Bajtek Bajtek Algosia Algosia Algosia Bajtek Algosia Bajtek Bajtek Algosia Bajtek Bajtek Algosia Algosia Algosia Algosia Bajtek Algosia Bajtek Algosia Algosia Algosia Bajtek Bajtek Bajtek Bajtek Algosia Algosia Bajtek Algosia Bajtek Bajtek...
result:
ok 10000 lines
Test #21:
score: 0
Accepted
time: 33ms
memory: 9436kb
input:
10000 60810990 97581310 166821440 196069190 216834580 622747490 811898210 888735980 1192107900 1197822780 1202523680 1421856990 1499482000 1562447650 1566552320 1720101440 1801617500 1853604370 2025975570 2034190570 2308971870 2313441650 2375358600 2486068680 2533542700 2916043660 3205803050 3246192...
output:
Algosia Algosia Algosia Algosia Algosia Bajtek Algosia Algosia Algosia Algosia Algosia Algosia Bajtek Algosia Algosia Algosia Algosia Algosia Algosia Bajtek Algosia Algosia Bajtek Algosia Algosia Algosia Algosia Bajtek Algosia Bajtek Algosia Algosia Bajtek Algosia Bajtek Bajtek Algosia Bajtek Bajtek...
result:
ok 10000 lines
Test #22:
score: 0
Accepted
time: 46ms
memory: 9412kb
input:
10000 76406715630 111565324460 200750576620 261707853560 445866973050 668135631280 974874883740 1162782063390 1165158948810 1242609524690 1272305703760 1315874237130 1393854893090 1454312667550 1525253603140 1592330451160 1802879548460 1836626272740 1883614175330 2003404258120 2241268746360 22653837...
output:
Algosia Algosia Algosia Algosia Algosia Bajtek Algosia Algosia Algosia Algosia Algosia Algosia Algosia Bajtek Algosia Algosia Algosia Algosia Algosia Bajtek Bajtek Algosia Bajtek Bajtek Algosia Algosia Bajtek Algosia Bajtek Algosia Algosia Algosia Bajtek Algosia Algosia Algosia Algosia Algosia Algos...
result:
ok 10000 lines
Test #23:
score: 0
Accepted
time: 51ms
memory: 9384kb
input:
10000 42607698916130 113454013589710 159641487153560 243076228475200 327199745352220 373104139235030 391375671066200 456211469904330 535489401599290 599949701164690 728261849853720 751891876690360 778296973651600 979417366859480 1115462673920810 1290359926184490 1318835783282350 1324359337113120 132...
output:
Algosia Algosia Algosia Algosia Algosia Algosia Bajtek Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Bajtek Algosia Algosia Algosia Algosia Algosia Algosia Bajtek Algosia Bajtek Algosia Algosia Algosia ...
result:
ok 10000 lines
Extra Test:
score: 0
Extra Test Passed