QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#330962#8058. Binary vs Ternaryucup-team296#AC ✓23ms2304kbRust20.7kb2024-02-17 21:25:092024-02-17 21:25:09

Judging History

你现在查看的是最新测评结果

  • [2024-02-17 21:25:09]
  • 评测
  • 测评结果:AC
  • 用时:23ms
  • 内存:2304kb
  • [2024-02-17 21:25:09]
  • 提交

answer

// 
pub mod solution {
//{"name":"uc23_l","group":"Manual","url":"","interactive":false,"timeLimit":2000,"tests":[{"input":"","output":""}],"testType":"multiNumber","input":{"type":"stdin","fileName":null,"pattern":null},"output":{"type":"stdout","fileName":null,"pattern":null},"languages":{"java":{"taskClass":"uc23_l"}}}

use crate::algo_lib::io::input::Input;
use crate::algo_lib::io::output::Output;
use crate::algo_lib::string::str::StrReader;

type PreCalc = ();

fn solve(input: &mut Input, out: &mut Output, _test_case: usize, _data: &PreCalc) {
let a = input.read_str();
let b = input.read_str();

if a.len() == 1 {
if b.len() == 1 {
if a == b {
out.print_line(0);
} else {
out.print_line(-1);
}
} else {
out.print_line(-1);
}
return;
}
if b.len() == 1 {
out.print_line(-1);
return;
}

let mut ans = Vec::new();
let mut second = a[1];
for c in a.iter().skip(2) {
if c == b'0' {
if second == b'1' {
ans.push((1, 2));
ans.push((2, 4));
second = b'0';
} else {
ans.push((2, 3));
}
} else {
if second == b'0' {
ans.push((1, 2));
}
ans.push((2, 3));
ans.push((1, 2));
ans.push((2, 5));
second = b'0';
}
}

if second == b'0' {
ans.push((1, 2));
}
for c in b.iter().skip(2).rev() {
if c == b'0' {
ans.push((1, 2));
ans.push((1, 2));
} else {
ans.push((1, 2));
ans.push((1, 2));
ans.push((2, 3));
}
}
if b[1] == b'0' {
ans.push((1, 2));
ans.push((2, 3));
}
out.print_line(ans.len());
out.print_per_line(&ans);
}

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::MultiNumber;
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 algo_lib {
pub mod collections {
pub mod iter_ext {
pub mod collect {
pub trait IterCollect<T>: Iterator<Item = T> + Sized {
fn collect_vec(self) -> Vec<T> {
self.collect()
}
}

impl<T, I: Iterator<Item = T> + Sized> IterCollect<T> for I {}
}
}
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::algo_lib::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()
}

//noinspection RsSelfConvention
pub fn is_empty(&mut self) -> bool {
self.skip_whitespace();
self.is_exhausted()
}

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::algo_lib::collections::vec_ext::default::default_vec;
use std::io::stderr;
use std::io::Stderr;
use std::io::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 string {
pub mod str {
use crate::algo_lib::collections::iter_ext::collect::IterCollect;
use crate::algo_lib::io::input::Input;
use crate::algo_lib::io::input::Readable;
use crate::algo_lib::io::output::Output;
use crate::algo_lib::io::output::Writable;
use std::cmp::Ordering;
use std::fmt::Debug;
use std::fmt::Display;
use std::fmt::Formatter;
use std::hash::Hash;
use std::hash::Hasher;
use std::iter::Copied;
use std::iter::FromIterator;
use std::marker::PhantomData;
use std::ops::Add;
use std::ops::AddAssign;
use std::ops::Deref;
use std::ops::DerefMut;
use std::ops::Index;
use std::ops::IndexMut;
use std::slice::Iter;
use std::slice::IterMut;
use std::slice::SliceIndex;
use std::str::FromStr;
use std::vec::IntoIter;

pub enum Str<'s> {
Extendable(Vec<u8>, PhantomData<&'s [u8]>),
Owned(Box<[u8]>, PhantomData<&'s [u8]>),
Ref(&'s [u8]),
}

impl Default for Str<'static> {
fn default() -> Self {
Self::new()
}
}

impl Str<'static> {
pub fn new() -> Self {
Str::Extendable(Vec::new(), PhantomData)
}

pub fn with_capacity(cap: usize) -> Self {
Str::Extendable(Vec::with_capacity(cap), PhantomData)
}
}

impl<'s> Str<'s> {
pub fn push(&mut self, c: u8) {
self.transform_to_extendable();
self.as_extendable().push(c)
}

pub fn pop(&mut self) -> Option<u8> {
self.transform_to_extendable();
self.as_extendable().pop()
}

pub fn as_slice(&self) -> &[u8] {
match self {
Str::Extendable(s, _) => s.as_ref(),
Str::Owned(s, _) => s.as_ref(),
Str::Ref(s) => s,
}
}

pub fn len(&self) -> usize {
self.as_slice().len()
}

pub fn is_empty(&self) -> bool {
self.len() == 0
}

pub fn iter(&self) -> Copied<Iter<u8>> {
match self {
Str::Extendable(v, _) => v.iter(),
Str::Owned(v, _) => v.iter(),
Str::Ref(v) => v.iter(),
}
.copied()
}

pub fn iter_mut(&mut self) -> IterMut<u8> {
self.transform_to_owned();
self.as_mut_slice().iter_mut()
}

pub fn sort(&mut self) {
self.transform_to_owned();
self.as_mut_slice().sort_unstable();
}

pub fn into_owned(mut self) -> Str<'static> {
self.transform_to_owned();
match self {
Str::Extendable(v, _) => Str::Extendable(v, PhantomData),
Str::Owned(v, _) => Str::Owned(v, PhantomData),
_ => unreachable!(),
}
}

fn transform_to_extendable(&mut self) {
match self {
Str::Extendable(_, _) => {}
Str::Owned(_, _) => {
let mut fake = Str::new();
std::mem::swap(self, &mut fake);
if let Str::Owned(s, _) = fake {
*self = Str::Extendable(s.to_vec(), PhantomData)
}
}
Str::Ref(s) => *self = Str::Extendable(s.to_vec(), PhantomData),
}
}

fn as_extendable(&mut self) -> &mut Vec<u8> {
match self {
Str::Extendable(s, _) => s,
_ => panic!("unreachable"),
}
}

fn transform_to_owned(&mut self) {
if let Str::Ref(s) = self {
*self = Str::Owned(s.to_vec().into_boxed_slice(), PhantomData)
}
}

pub fn as_mut_slice(&mut self) -> &mut [u8] {
self.transform_to_owned();
match self {
Str::Extendable(s, _) => s.as_mut_slice(),
Str::Owned(s, _) => s.as_mut(),
_ => panic!("unreachable"),
}
}

pub fn into_string(self) -> String {
match self {
Str::Extendable(v, _) => unsafe { String::from_utf8_unchecked(v) },
Str::Owned(v, _) => unsafe { String::from_utf8_unchecked(v.into_vec()) },
Str::Ref(v) => String::from_utf8_lossy(v).into_owned(),
}
}

pub fn reverse(&mut self) {
self.as_mut_slice().reverse();
}

pub fn trim(&self) -> Str<'_> {
let mut start = 0;
let mut end = self.len();
while start < end && (self[start] as char).is_whitespace() {
start += 1;
}
while start < end && (self[end - 1] as char).is_whitespace() {
end -= 1;
}
self[start..end].into()
}

pub fn split<'a, 'b>(&'a self, sep: impl Into<Str<'b>>) -> Vec<Str<'a>>
where
's: 'a,
{
let sep = sep.into();
let mut res = Vec::new();
let mut start = 0;
for i in 0..self.len() {
if self[i..].starts_with(sep.as_slice()) {
res.push(self[start..i].into());
start = i + sep.len();
}
}
res.push(self[start..].into());
res
}

pub fn parse<F: FromStr>(self) -> F
where
F::Err: Debug,
{
self.into_string().parse().unwrap()
}

pub fn parse_vec<T: Readable>(&self) -> Vec<T> {
let mut bytes = self.as_slice();
let mut input = Input::new(&mut bytes);
let mut res = Vec::new();
while !input.is_exhausted() {
res.push(input.read());
}
res
}
}

impl<'s> IntoIterator for Str<'s> {
type Item = u8;
type IntoIter = IntoIter<u8>;

#[allow(clippy::unnecessary_to_owned)]
fn into_iter(self) -> Self::IntoIter {
match self {
Str::Extendable(v, _) => v.into_iter(),
Str::Owned(v, _) => v.into_vec().into_iter(),
Str::Ref(v) => v.to_vec().into_iter(),
}
}
}

impl From<String> for Str<'static> {
fn from(s: String) -> Self {
Str::Extendable(s.into(), PhantomData)
}
}

impl<'s> From<&'s str> for Str<'s> {
fn from(s: &'s str) -> Self {
Str::Ref(s.as_bytes())
}
}

impl From<Vec<u8>> for Str<'static> {
fn from(s: Vec<u8>) -> Self {
Str::Extendable(s, PhantomData)
}
}

impl<'s> From<&'s [u8]> for Str<'s> {
fn from(s: &'s [u8]) -> Self {
Str::Ref(s)
}
}

impl<'s, const N: usize> From<&'s [u8; N]> for Str<'s> {
fn from(s: &'s [u8; N]) -> Self {
Str::Ref(s)
}
}

impl<'s> From<&'s String> for Str<'s> {
fn from(s: &'s String) -> Self {
Str::Ref(s.as_bytes())
}
}

impl<'s> From<&'s Vec<u8>> for Str<'s> {
fn from(s: &'s Vec<u8>) -> Self {
Str::Ref(s.as_slice())
}
}

impl From<u8> for Str<'static> {
fn from(c: u8) -> Self {
Str::Owned(Box::new([c]), PhantomData)
}
}

impl From<char> for Str<'static> {
fn from(c: char) -> Self {
Str::from(c as u8)
}
}

impl<'s, 't: 's> From<&'s Str<'t>> for Str<'s> {
fn from(value: &'s Str<'t>) -> Self {
Str::Ref(value.as_slice())
}
}

impl<R: SliceIndex<[u8]>> Index<R> for Str<'_> {
type Output = R::Output;

fn index(&self, index: R) -> &Self::Output {
self.as_slice().index(index)
}
}

impl<R: SliceIndex<[u8]>> IndexMut<R> for Str<'_> {
fn index_mut(&mut self, index: R) -> &mut Self::Output {
self.transform_to_owned();
self.as_mut_slice().index_mut(index)
}
}

impl Clone for Str<'_> {
fn clone(&self) -> Self {
match self {
Str::Extendable(s, _) => s.clone().into(),
Str::Owned(s, _) => s.to_vec().into(),
Str::Ref(s) => Str::Ref(s),
}
}
}

impl<'r, 's, S: Into<Str<'r>>> AddAssign<S> for Str<'s> {
fn add_assign(&mut self, rhs: S) {
self.transform_to_extendable();
self.as_extendable()
.extend_from_slice(rhs.into().as_slice());
}
}

impl<'r, 's, S: Into<Str<'r>>> Add<S> for Str<'s> {
type Output = Str<'s>;

fn add(mut self, rhs: S) -> Self::Output {
self += rhs;
self
}
}

impl Readable for Str<'static> {
fn read(input: &mut Input) -> Self {
input.next_token().unwrap().into()
}
}

impl Writable for Str<'_> {
fn write(&self, output: &mut Output) {
for c in self.as_slice() {
output.put(*c);
}
output.maybe_flush();
}
}

impl Display for Str<'_> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
<String as Display>::fmt(&String::from_utf8(self.as_slice().to_vec()).unwrap(), f)
}
}

impl Hash for Str<'_> {
fn hash<H: Hasher>(&self, state: &mut H) {
self.as_slice().hash(state);
}
}

impl<'r> PartialEq<Str<'r>> for Str<'_> {
fn eq(&self, other: &Str<'r>) -> bool {
self.as_slice().eq(other.as_slice())
}
}

impl Eq for Str<'_> {}

impl<'r> PartialOrd<Str<'r>> for Str<'_> {
fn partial_cmp(&self, other: &Str<'r>) -> Option<Ordering> {
self.as_slice().partial_cmp(other.as_slice())
}
}

impl Ord for Str<'_> {
fn cmp(&self, other: &Self) -> Ordering {
self.as_slice().cmp(other.as_slice())
}
}

impl FromIterator<u8> for Str<'static> {
fn from_iter<T: IntoIterator<Item = u8>>(iter: T) -> Self {
Self::Extendable(iter.into_iter().collect_vec(), Default::default())
}
}

impl<'r> FromIterator<&'r u8> for Str<'static> {
fn from_iter<T: IntoIterator<Item = &'r u8>>(iter: T) -> Self {
Self::Extendable(iter.into_iter().cloned().collect_vec(), Default::default())
}
}

impl Deref for Str<'_> {
type Target = [u8];

fn deref(&self) -> &Self::Target {
self.as_slice()
}
}

impl DerefMut for Str<'_> {
fn deref_mut(&mut self) -> &mut Self::Target {
self.as_mut_slice()
}
}

pub trait StrReader {
fn read_str(&mut self) -> Str<'static>;
fn read_str_vec(&mut self, n: usize) -> Vec<Str<'static>>;
fn read_line(&mut self) -> Str<'static>;
fn read_line_vec(&mut self, n: usize) -> Vec<Str<'static>>;
fn read_lines(&mut self) -> Vec<Str<'static>>;
}

impl StrReader for Input<'_> {
fn read_str(&mut self) -> Str<'static> {
self.read()
}

fn read_str_vec(&mut self, n: usize) -> Vec<Str<'static>> {
self.read_vec(n)
}

fn read_line(&mut self) -> Str<'static> {
let mut res = Str::new();
while let Some(c) = self.get() {
if c == b'\n' {
break;
}
res.push(c);
}
res
}

fn read_line_vec(&mut self, n: usize) -> Vec<Str<'static>> {
let mut res = Vec::with_capacity(n);
for _ in 0..n {
res.push(self.read_line());
}
res
}

fn read_lines(&mut self) -> Vec<Str<'static>> {
let mut res = Vec::new();
while !self.is_exhausted() {
res.push(self.read_line());
}
if let Some(s) = res.last() {
if s.is_empty() {
res.pop();
}
}
res
}
}
}
}
}
fn main() {
    let mut sin = std::io::stdin();
    let input = if false {
        algo_lib::io::input::Input::new_with_size(&mut sin, 1)
    } else {
        algo_lib::io::input::Input::new(&mut sin)
    };
    let mut stdout = std::io::stdout();
    let output = if false {
        algo_lib::io::output::Output::new_with_auto_flush(&mut stdout)
    } else {
        algo_lib::io::output::Output::new(&mut stdout)
    };
    solution::run(input, output);
}

这程序好像有点Bug,我给组数据试试?

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 2160kb

input:

3
1
111
110110
1101010
1111
111111

output:

-1
24
1 2
2 4
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
2 3
1 2
1 2
1 2
1 2
1 2
2 3
1 2
1 2
1 2
1 2
2 3
1 2
1 2
20
2 3
1 2
2 5
1 2
2 3
1 2
2 5
1 2
1 2
1 2
2 3
1 2
1 2
2 3
1 2
1 2
2 3
1 2
1 2
2 3

result:

ok Haitang Suki (3 test cases)

Test #2:

score: 0
Accepted
time: 1ms
memory: 2192kb

input:

1000
11100
111
1
11110
10001
10
1011
1111
10
1110
1100
11
11010
11
110
11
1
10001
10110
10
10
11111
10000
1001
10
1
11
10111
11
10
1
100
11
10100
1
10
101
11
1100
110
11
1110
1
1001
1
11111
10
10010
10
11001
110
1010
10011
1110
10100
1001
1001
101
100
1
1001
11
101
11
101
1001
1
1
1011
1
10
10
1011
...

output:

9
2 3
1 2
2 5
2 3
2 3
1 2
1 2
1 2
2 3
-1
9
2 3
2 3
1 2
2 3
1 2
2 5
1 2
1 2
2 3
15
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
1 2
1 2
1 2
2 3
1 2
1 2
2 3
6
1 2
1 2
1 2
1 2
1 2
2 3
4
1 2
2 4
2 3
1 2
8
1 2
2 4
1 2
2 3
1 2
2 5
2 3
1 2
3
1 2
2 4
1 2
-1
12
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
2 3
1 2
1 2
2 3
10
1 2
1 2
1...

result:

ok Haitang Suki (1000 test cases)

Test #3:

score: 0
Accepted
time: 1ms
memory: 2068kb

input:

1000
1110
110
1
11
1110
110
101
111
100
1001
10
110
1001
10011
10
11010
100
111
1101
1001
1
111
1
1
11
1
1011
1101
1
11
111
10
100
1110
1001
10
10
11
1
10
11
11
111
1100
10100
11001
10
110
1001
101
1
10011
100
10
10110
111
1100
110
11010
11
1000
1101
1010
1
1100
100
11010
1
1011
1
11001
1110
11
1110...

output:

7
2 3
1 2
2 5
2 3
1 2
1 2
1 2
-1
7
2 3
1 2
2 5
2 3
1 2
1 2
1 2
8
1 2
2 3
1 2
2 5
1 2
1 2
1 2
2 3
9
2 3
1 2
1 2
1 2
2 3
1 2
1 2
1 2
2 3
3
1 2
1 2
1 2
16
2 3
1 2
2 3
1 2
2 5
1 2
1 2
1 2
2 3
1 2
1 2
2 3
1 2
1 2
1 2
2 3
8
1 2
1 2
1 2
1 2
1 2
2 3
1 2
1 2
5
2 3
1 2
1 2
1 2
2 3
14
1 2
2 4
1 2
2 3
1 2
2 5
1...

result:

ok Haitang Suki (1000 test cases)

Test #4:

score: 0
Accepted
time: 2ms
memory: 2192kb

input:

1000
11110010
11110001
11010110
1001
11011110
1001110
111101100
111111100
110
101111001
10000100
10
1100100
101010
100
1000
1011110
110101
1001
10001111
100011111
1001111011
1110100
1010
1001100001
1000
11
101101
1000001111
11100
101001101
1
11
111001111
100101101
10
1
10111
1111000111
1101
10111
11...

output:

30
2 3
1 2
2 5
1 2
2 3
1 2
2 5
2 3
2 3
1 2
2 3
1 2
2 5
2 3
1 2
1 2
1 2
2 3
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
2 3
1 2
1 2
2 3
24
1 2
2 4
1 2
2 3
1 2
2 5
2 3
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
2 3
1 2
1 2
1 2
2 3
1 2
1 2
1 2
2 3
35
1 2
2 4
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
2 3...

result:

ok Haitang Suki (1000 test cases)

Test #5:

score: 0
Accepted
time: 2ms
memory: 2100kb

input:

1000
11
10
1111101
10
1011010001
1101010100
101110
101101001
110
110
100001
1111
10
1001100
1101101000
1
1
1110
11
1110000
110111010
1001000
110100000
1
1110101001
10
11111
1001101
110
1110
111
11
11000
1
111111
1
101111111
1100100100
101101100
1111110
10001
1001
1100110100
100
1001
101001
100011000...

output:

2
1 2
2 3
19
2 3
1 2
2 5
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
2 3
1 2
2 3
1 2
2 5
1 2
1 2
2 3
40
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
2 3
1 2
2 3
1 2
2 5
2 3
2 3
2 3
1 2
2 3
1 2
2 5
1 2
1 2
1 2
1 2
1 2
1 2
1 2
2 3
1 2
1 2
1 2
1 2
2 3
1 2
1 2
1 2
1 2
2 3
1 2
1 2
34
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2...

result:

ok Haitang Suki (1000 test cases)

Test #6:

score: 0
Accepted
time: 0ms
memory: 2076kb

input:

1000
1010100001
1101101111
1000001111
1100000010
1101001000
1111011000
1011010000
1101111100
1000011000
1001010110
1100010110
1001001000
1000111110
1101100000
1101011010
1111000101
1110111001
1000000010
1111110000
1001100000
1000010111
1010101110
1110101000
1111100001
1110110101
1011100001
110111101...

output:

40
1 2
2 3
1 2
2 5
2 3
1 2
2 3
1 2
2 5
2 3
2 3
2 3
2 3
1 2
2 3
1 2
2 5
1 2
1 2
1 2
2 3
1 2
1 2
2 3
1 2
1 2
2 3
1 2
1 2
2 3
1 2
1 2
1 2
1 2
2 3
1 2
1 2
2 3
1 2
1 2
38
2 3
2 3
2 3
2 3
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
1 2
1 2
1 2
1 2
1 2
2 3
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 ...

result:

ok Haitang Suki (1000 test cases)

Test #7:

score: 0
Accepted
time: 3ms
memory: 2096kb

input:

1000
1010010100
1100011110
1111100001
1110100100
1001011000
1001011110
1110100101
1000001010
1110010010
1110110010
1010001000
1110011110
1010101110
1100011011
1000000100
1100100001
1010001011
1111101100
1001110101
1010001011
1001001010
1010010111
1011001010
1110001111
1000001000
1111001011
100111101...

output:

38
1 2
2 3
1 2
2 5
2 3
2 3
1 2
2 3
1 2
2 5
2 3
1 2
2 3
1 2
2 5
2 3
2 3
1 2
1 2
1 2
1 2
1 2
2 3
1 2
1 2
2 3
1 2
1 2
2 3
1 2
1 2
2 3
1 2
1 2
1 2
1 2
1 2
1 2
39
2 3
1 2
2 5
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
2 3
2 3
2 3
2 3
1 2
2 3
1 2
2 5
1 2
1 2
1 2
1 2
1 2
1 2
1 2
2 3
1 2
1 2
1 2
1 2
1 2
1 2
2 3
1 2
1 ...

result:

ok Haitang Suki (1000 test cases)

Test #8:

score: 0
Accepted
time: 7ms
memory: 2188kb

input:

1000
10001101010010010010011111000100011110010111010011100110011
101100010110011111000010101
101111101000100010010101
10100101000010100001101000001101010111
1101110100111100111110101101101000110101010010011100
1110100100101011000011
1100001100101011010000111010111000000101
11101000100000101000001111...

output:

210
2 3
2 3
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
2 3
1 2
2 3
1 2
2 5
2 3
1 2
2 3
1 2
2 5
2 3
2 3
1 2
2 3
1 2
2 5
2 3
2 3
1 2
2 3
1 2
2 5
2 3
2 3
1 2
2 3
1 2
2 5
2 3
2 3
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
2 3
2 3
2 3
1 2
2 3
1 2
2 5
2 3
2 3
2 3
1 2
2 3
1 2
2 5
...

result:

ok Haitang Suki (1000 test cases)

Test #9:

score: 0
Accepted
time: 11ms
memory: 2104kb

input:

1000
100000000110011000110010101
11110000
10010001001001111000110110001001011101011110
111011111001100111101101000011111110
1011110110011110110011000111010011111000100110011010101000000
1101001
1001010
10101110110001101010001000111001000111011000110111111110
11101001110000011100
10100010111000000110...

output:

67
2 3
2 3
2 3
2 3
2 3
2 3
2 3
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
2 3
2 3
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
2 3
2 3
2 3
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
2 3
2 3
1 2
2 3
1 2
2 5
2 3
1 2
2 3
1 2
2 5
2 3
1 2
2 3
1 2
2 5
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
2 3
1 2
1 2
2 3
196
2 3
1 2
2 3
1 2
2 5
2 3
2...

result:

ok Haitang Suki (1000 test cases)

Test #10:

score: 0
Accepted
time: 3ms
memory: 2304kb

input:

1000
11111100001000000001110111011111001010011110100001100001011
1111001111111111100011111011011101100110000011010010
110010011001001110101
1011101100
1110
110111111010010011110010101101000101111000111111111010111111000
10101101101010001100111
11110001001011110010
1111010110010101010001011
111
10011...

output:

272
2 3
1 2
2 5
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
2 3
2 3
2 3
2 3
1 2
2 3
1 2
2 5
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
2 3
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
2 3
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
1 2
...

result:

ok Haitang Suki (1000 test cases)

Test #11:

score: 0
Accepted
time: 11ms
memory: 2196kb

input:

1000
111100011011111100101110101
11111011000101100110001011101011
10011001010101110111011111111110
11010100000
11001100100011101000101111011011
10011101010110110
101011000011
101110100101101010000111010010101101
1110111110000101110100101101
1101110111100000110001001011000001111101010011
111111100110...

output:

150
2 3
1 2
2 5
1 2
2 3
1 2
2 5
2 3
2 3
2 3
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
2 3
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
2 3
2 3
1 2
2 3
1 2
2 5
2 3
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
2 3
1 2
2 3
1 2
2 5
2 3
1 2
2 3
1 2
2 5
1 2
1 2
...

result:

ok Haitang Suki (1000 test cases)

Test #12:

score: 0
Accepted
time: 12ms
memory: 2112kb

input:

1000
11000001100100011000100101001101100011100100110010111011000
1111101101110
1000001011101111011010011001001100011000
11001110110101100011001011000111110111010000111010010
100101011
1011010011111100
100
11101000000110100100110100110001100111110111110010001001010
11110000011100011110010100000011100...

output:

161
1 2
2 4
2 3
2 3
2 3
2 3
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
2 3
2 3
1 2
2 3
1 2
2 5
2 3
2 3
2 3
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
2 3
2 3
2 3
1 2
2 3
1 2
2 5
2 3
2 3
1 2
2 3
1 2
2 5
2 3
1 2
2 3
1 2
2 5
2 3
2 3
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
2 3
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
2 3
2 3
2 3
1 2
2 3
1 2
...

result:

ok Haitang Suki (1000 test cases)

Test #13:

score: 0
Accepted
time: 22ms
memory: 2256kb

input:

1000
1110101101011010111111111001001001101101001111100001000010110001
1111100111110101010011010111100100111110001111111100010100010010
1101011000001010101000000011111111101101010111100011110011100011
1110010001100011111001000000111111111111000010001100000100000010
10111101100001101001001011010001101...

output:

324
2 3
1 2
2 5
2 3
1 2
2 3
1 2
2 5
2 3
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
2 3
1 2
2 3
1 2
2 5
2 3
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
2 3
1 2
2 3
1 2
2 5
2 3
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
2 3
...

result:

ok Haitang Suki (1000 test cases)

Test #14:

score: 0
Accepted
time: 13ms
memory: 2180kb

input:

1000
1010011000110100110000001111001100100010111111101001000101111100
1111001000000001111001010110011101110101000010000001010011001010
1001100100100101111101011111011010100111000001100101001110001010
1010101100010001100001111010010110011101010001011101010110110011
11101011110000111111101011111011001...

output:

306
1 2
2 3
1 2
2 5
2 3
2 3
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
2 3
2 3
2 3
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
2 3
1 2
2 3
1 2
2 5
2 3
2 3
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
2 3
2 3
2 3
2 3
2 3
2 3
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
2 3
2 3
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
2 3
2 3
...

result:

ok Haitang Suki (1000 test cases)

Test #15:

score: 0
Accepted
time: 23ms
memory: 2036kb

input:

1000
1011111000111010111001111001000011101001100011100000101110000101
1001100010000111101011001010000101100110101101010100101011001010
1001101111000001100111110111011111110011101010101101010110011100
1100101011100110001011000111111101001001111100110010100101001110
11111101100001101001110111010011001...

output:

314
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
2 3
2 3
2 3
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
2 3
1 2
2 3
1 2
2 5
2 3
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
2 3
2 3
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
2 3
2 3
1 2
...

result:

ok Haitang Suki (1000 test cases)

Test #16:

score: 0
Accepted
time: 22ms
memory: 2256kb

input:

1000
1001101101110101111101001110000111110100010100101111101001011001
1110001000100001001001001111111100101101101000100100111000001011
1000001000001110101011111011011111011101011100001101101111100001
1100111111001100100010010101001000101000101100100011101001111011
10110101000000011111000111111110000...

output:

323
2 3
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
2 3
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
2 3
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
2 3
1 2
2 3
1 2
2 5
2 3
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
2 3
1 2
2 3
1 2
2 5
2 3
2 3
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
1 2
2 3
...

result:

ok Haitang Suki (1000 test cases)

Test #17:

score: 0
Accepted
time: 22ms
memory: 2184kb

input:

1000
1101011111000011000110010000110000111110001000101110100110001110
1100101111001111100011111011001111000110100110110001010111101011
1010110111100001110110101111101000000111010111010101010110010111
1010011010011111001010111101100011110100111111100100111011101101
11100011010101001001001001110100000...

output:

312
1 2
2 4
1 2
2 3
1 2
2 5
2 3
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
2 3
2 3
2 3
2 3
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
2 3
2 3
2 3
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
2 3
2 3
1 2
2 3
1 2
2 5
2 3
2 3
2 3
2 3
1 2
2 3
1 2
2 5
1 2
2 3
1 2
2 5
2 3
2 3
2 3
2 3
1 2
2 3
...

result:

ok Haitang Suki (1000 test cases)

Extra Test:

score: 0
Extra Test Passed