QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#230503 | #7639. Forbidden Set | ucup-team296# | AC ✓ | 1ms | 2356kb | Rust | 17.7kb | 2023-10-28 19:14:06 | 2023-10-28 19:14:07 |
Judging History
answer
pub mod solution {
//{"name":"h","group":"Manual","url":"","interactive":false,"timeLimit":2000,"tests":[{"input":"","output":""},{"input":"","output":""}],"testType":"single","input":{"type":"stdin","fileName":null,"pattern":null},"output":{"type":"stdout","fileName":null,"pattern":null},"languages":{"java":{"taskClass":"h"}}}
use crate::algo_lib::io::output::output;
use crate::algo_lib::io::task_io_settings::TaskIoType;
use crate::algo_lib::io::task_runner::run_task;
use crate::algo_lib::io::input::Input;
use crate::algo_lib::io::task_io_settings::TaskIoSettings;
use crate::algo_lib::math::primes::gen_primes_table;
#[allow(unused)]
use crate::dbg;
use crate::out;
use crate::out_line;
fn solve(input: &mut Input, _test_case: usize) {
let n = input.usize();
let mut bad = vec![false; 10];
for _ in 0..n {
bad[input.usize()] = true;
}
let primes = gen_primes_table(1_000_00);
for p in 2..primes.len() {
if !primes[p] {
continue;
}
let mut ok = true;
let mut z = p;
while z != 0 {
if bad[z % 10] {
ok = false;
break;
}
z /= 10;
}
if ok {
out_line!(p);
return;
}
}
out_line!(-1);
}
pub(crate) fn run(mut input: Input) -> bool {
solve(&mut input, 1);
output().flush();
true
}
#[allow(unused)]
pub fn submit() -> bool {
let io = TaskIoSettings {
is_interactive: false,
input: TaskIoType::Std,
output: TaskIoType::Std,
};
run_task(io, run)
}
}
pub mod algo_lib {
pub mod io {
pub mod input {
use std::fmt::Debug;
use std::io::Read;
use std::marker::PhantomData;
use std::path::Path;
use std::str::FromStr;
pub struct Input {
input: Box<dyn Read>,
buf: Vec<u8>,
at: usize,
buf_read: usize,
}
macro_rules! read_integer_fun {
($t:ident) => {
#[allow(unused)]
pub fn $t(&mut self) -> $t {
self.read_integer()
}
};
}
impl Input {
const DEFAULT_BUF_SIZE: usize = 4096;
///
/// Using with stdin:
/// ```no_run
/// use algo_lib::io::input::Input;
/// let stdin = std::io::stdin();
/// let input = Input::new(Box::new(stdin));
/// ```
///
/// For read files use ``new_file`` instead.
///
///
pub fn new(input: Box<dyn Read>) -> Self {
Self {
input,
buf: vec![0; Self::DEFAULT_BUF_SIZE],
at: 0,
buf_read: 0,
}
}
pub fn new_file<P: AsRef<Path>>(path: P) -> Self {
let file = std::fs::File::open(&path)
.unwrap_or_else(|_| panic!("Can't open file: {:?}", path.as_ref().as_os_str()));
Self::new(Box::new(file))
}
pub fn new_with_size(input: Box<dyn Read>, buf_size: usize) -> Self {
Self {
input,
buf: vec![0; buf_size],
at: 0,
buf_read: 0,
}
}
pub fn new_file_with_size<P: AsRef<Path>>(path: P, buf_size: usize) -> Self {
let file = std::fs::File::open(&path)
.unwrap_or_else(|_| panic!("Can't open file: {:?}", path.as_ref().as_os_str()));
Self::new_with_size(Box::new(file), buf_size)
}
pub fn get(&mut self) -> Option<u8> {
if self.refill_buffer() {
let res = self.buf[self.at];
self.at += 1;
Some(res)
} else {
None
}
}
pub fn peek(&mut self) -> Option<u8> {
if self.refill_buffer() {
Some(self.buf[self.at])
} 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 has_more_elements(&mut self) -> bool {
!self.is_exhausted()
}
pub fn read<T: Readable>(&mut self) -> T {
T::read(self)
}
pub fn vec<T: Readable>(&mut self, size: usize) -> Vec<T> {
let mut res = Vec::with_capacity(size);
for _ in 0usize..size {
res.push(self.read());
}
res
}
pub fn string_vec(&mut self, size: usize) -> Vec<Vec<u8>> {
let mut res = Vec::with_capacity(size);
for _ in 0usize..size {
res.push(self.string());
}
res
}
pub fn read_line(&mut self) -> String {
let mut res = String::new();
while let Some(c) = self.get() {
if c == b'\n' {
break;
}
if c == b'\r' {
if self.peek() == Some(b'\n') {
self.get();
}
break;
}
res.push(c.into());
}
res
}
#[allow(clippy::should_implement_trait)]
pub fn into_iter<T: Readable>(self) -> InputIterator<T> {
InputIterator {
input: self,
phantom: Default::default(),
}
}
fn read_integer<T: FromStr>(&mut self) -> T
where
<T as FromStr>::Err: Debug,
{
let res = self.read_string();
res.parse::<T>().unwrap()
}
fn read_string(&mut self) -> String {
match self.next_token() {
None => {
panic!("Input exhausted");
}
Some(res) => unsafe { String::from_utf8_unchecked(res) },
}
}
pub fn string_as_string(&mut self) -> String {
self.read_string()
}
pub fn string(&mut self) -> Vec<u8> {
self.read_string().into_bytes()
}
fn read_char(&mut self) -> char {
self.skip_whitespace();
self.get().unwrap().into()
}
fn read_float(&mut self) -> f64 {
self.read_string().parse().unwrap()
}
pub fn f64(&mut self) -> f64 {
self.read_float()
}
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
}
}
read_integer_fun!(i32);
read_integer_fun!(i64);
read_integer_fun!(i128);
read_integer_fun!(u32);
read_integer_fun!(u64);
read_integer_fun!(usize);
}
pub trait Readable {
fn read(input: &mut Input) -> Self;
}
impl Readable for String {
fn read(input: &mut Input) -> Self {
input.read_string()
}
}
impl Readable for char {
fn read(input: &mut Input) -> Self {
input.read_char()
}
}
impl Readable for f64 {
fn read(input: &mut Input) -> Self {
input.read_string().parse().unwrap()
}
}
impl Readable for f32 {
fn read(input: &mut Input) -> Self {
input.read_string().parse().unwrap()
}
}
impl<T: Readable> Readable for Vec<T> {
fn read(input: &mut Input) -> Self {
let size = input.read();
input.vec(size)
}
}
pub struct InputIterator<T: Readable> {
input: Input,
phantom: PhantomData<T>,
}
impl<T: Readable> Iterator for InputIterator<T> {
type Item = T;
fn next(&mut self) -> Option<Self::Item> {
self.input.skip_whitespace();
self.input.peek().map(|_| self.input.read())
}
}
macro_rules! read_integer {
($t:ident) => {
impl Readable for $t {
fn read(input: &mut Input) -> Self {
input.read_integer()
}
}
};
}
read_integer!(i8);
read_integer!(i16);
read_integer!(i32);
read_integer!(i64);
read_integer!(i128);
read_integer!(isize);
read_integer!(u8);
read_integer!(u16);
read_integer!(u32);
read_integer!(u64);
read_integer!(u128);
read_integer!(usize);
}
pub mod output {
use std::io::Write;
pub struct Output {
output: Box<dyn Write>,
buf: Vec<u8>,
at: usize,
auto_flush: bool,
}
impl Output {
const DEFAULT_BUF_SIZE: usize = 4096;
pub fn new(output: Box<dyn Write>) -> Self {
Self {
output,
buf: vec![0; Self::DEFAULT_BUF_SIZE],
at: 0,
auto_flush: false,
}
}
pub fn new_with_auto_flush(output: Box<dyn Write>) -> Self {
Self {
output,
buf: vec![0; Self::DEFAULT_BUF_SIZE],
at: 0,
auto_flush: true,
}
}
pub fn flush(&mut self) {
if self.at != 0 {
self.output.write_all(&self.buf[..self.at]).unwrap();
self.at = 0;
self.output.flush().expect("Couldn't flush output");
}
}
pub fn print<T: Writable>(&mut self, s: &T) {
s.write(self);
}
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);
}
}
}
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;
}
if self.auto_flush {
self.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> Writable for Vec<T> {
fn write(&self, output: &mut Output) {
self[..].write(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);
write_to_string!(u16);
write_to_string!(u32);
write_to_string!(u64);
write_to_string!(u128);
write_to_string!(usize);
write_to_string!(i8);
write_to_string!(i16);
write_to_string!(i32);
write_to_string!(i64);
write_to_string!(i128);
write_to_string!(isize);
write_to_string!(f32);
write_to_string!(f64);
impl<T: Writable, U: Writable> Writable for (T, U) {
fn write(&self, output: &mut Output) {
self.0.write(output);
output.put(b' ');
self.1.write(output);
}
}
impl<T: Writable, U: Writable, V: Writable> Writable for (T, U, V) {
fn write(&self, output: &mut Output) {
self.0.write(output);
output.put(b' ');
self.1.write(output);
output.put(b' ');
self.2.write(output);
}
}
pub static mut OUTPUT: Option<Output> = None;
pub fn set_global_output_to_stdout() {
unsafe {
OUTPUT = Some(Output::new(Box::new(std::io::stdout())));
}
}
pub fn set_global_output_to_file(path: &str) {
unsafe {
let out_file =
std::fs::File::create(path).unwrap_or_else(|_| panic!("Can't create file {}", path));
OUTPUT = Some(Output::new(Box::new(out_file)));
}
}
pub fn set_global_output_to_none() {
unsafe {
match &mut OUTPUT {
None => {}
Some(output) => output.flush(),
}
OUTPUT = None;
}
}
pub fn output() -> &'static mut Output {
unsafe {
match &mut OUTPUT {
None => {
panic!("Global output wasn't initialized");
}
Some(output) => output,
}
}
}
#[macro_export]
macro_rules! out {
($first: expr $(,$args:expr )*) => {
output().print(&$first);
$(output().put(b' ');
output().print(&$args);
)*
output().maybe_flush();
}
}
#[macro_export]
macro_rules! out_line {
($first: expr $(, $args:expr )* ) => {
{
out!($first $(,$args)*);
output().put(b'\n');
output().maybe_flush();
}
};
() => {
{
output().put(b'\n');
output().maybe_flush();
}
};
}
}
pub mod task_io_settings {
pub enum TaskIoType {
Std,
File(String),
}
pub struct TaskIoSettings {
pub is_interactive: bool,
pub input: TaskIoType,
pub output: TaskIoType,
}
}
pub mod task_runner {
use std::io::Write;
use super::input::Input;
use super::output::Output;
use super::output::OUTPUT;
use super::task_io_settings::TaskIoSettings;
use super::task_io_settings::TaskIoType;
pub fn run_task<Res>(io: TaskIoSettings, run: impl FnOnce(Input) -> Res) -> Res {
let output: Box<dyn Write> = match io.output {
TaskIoType::Std => Box::new(std::io::stdout()),
TaskIoType::File(file) => {
let out_file = std::fs::File::create(file).unwrap();
Box::new(out_file)
}
};
unsafe {
OUTPUT = Some(Output::new(output));
}
let input = match io.input {
TaskIoType::Std => {
let sin = std::io::stdin();
Input::new(Box::new(sin))
}
TaskIoType::File(file) => Input::new_file(file),
};
run(input)
}
}
}
pub mod math {
pub mod primes {
pub fn gen_primes_table(up_to: usize) -> Vec<bool> {
let mut is_prime = vec![true; up_to + 1];
is_prime[0] = false;
is_prime[1] = false;
for p in 2..is_prime.len() {
if is_prime[p] {
for another in (2 * p..is_prime.len()).step_by(p) {
is_prime[another] = false;
}
}
}
is_prime
}
pub fn gen_largest_prime_table(up_to: usize) -> Vec<usize> {
let mut largest_prime = vec![0; up_to + 1];
for p in 2..largest_prime.len() {
if largest_prime[p] == 0 {
for another in (p..largest_prime.len()).step_by(p) {
largest_prime[another] = p;
}
}
}
largest_prime
}
pub struct PrimesIter<'a> {
largest_primes: &'a [usize],
value: usize,
}
pub struct Prime {
pub value: usize,
pub power: usize,
}
pub fn factorize(largest_primes: &[usize], value: usize) -> PrimesIter {
PrimesIter {
largest_primes,
value,
}
}
impl<'a> Iterator for PrimesIter<'a> {
type Item = Prime;
fn next(&mut self) -> Option<Self::Item> {
if self.value == 1 {
None
} else {
let prime = self.largest_primes[self.value];
let mut power = 0;
while self.value % prime == 0 {
self.value /= prime;
power += 1;
}
Some(Prime {
value: prime,
power,
})
}
}
}
pub fn is_prime(x: i64) -> bool {
if x <= 1 {
return false;
}
let mut i = 2;
while i * i <= x {
if x % i == 0 {
return false;
}
i += 1;
}
true
}
}
}
pub mod misc {
pub mod dbg_macro {
#[macro_export]
#[allow(unused_macros)]
macro_rules! dbg {
($first_val:expr, $($val:expr),+ $(,)?) => {
eprint!("[{}:{}] {} = {:?}",
file!(), line!(), stringify!($first_val), &$first_val);
($(eprint!(", {} = {:?}", stringify!($val), &$val)),+,);
eprintln!();
};
($first_val:expr) => {
eprintln!("[{}:{}] {} = {:?}",
file!(), line!(), stringify!($first_val), &$first_val)
};
}
}
}
}
fn main() {
crate::solution::submit();
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 2092kb
input:
7 0 1 2 4 6 8 9
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 1ms
memory: 2028kb
input:
9 0 1 2 3 5 6 7 8 9
output:
-1
result:
ok 1 number(s): "-1"
Test #3:
score: 0
Accepted
time: 0ms
memory: 2132kb
input:
9 0 2 3 4 5 6 7 8 9
output:
11
result:
ok 1 number(s): "11"
Test #4:
score: 0
Accepted
time: 1ms
memory: 2108kb
input:
9 0 1 3 4 5 6 7 8 9
output:
2
result:
ok 1 number(s): "2"
Test #5:
score: 0
Accepted
time: 1ms
memory: 2156kb
input:
9 0 1 2 4 5 6 7 8 9
output:
3
result:
ok 1 number(s): "3"
Test #6:
score: 0
Accepted
time: 1ms
memory: 2092kb
input:
9 0 1 2 3 4 6 7 8 9
output:
5
result:
ok 1 number(s): "5"
Test #7:
score: 0
Accepted
time: 1ms
memory: 2296kb
input:
9 0 1 2 3 4 5 7 8 9
output:
-1
result:
ok 1 number(s): "-1"
Test #8:
score: 0
Accepted
time: 1ms
memory: 2264kb
input:
9 0 1 2 3 4 5 6 8 9
output:
7
result:
ok 1 number(s): "7"
Test #9:
score: 0
Accepted
time: 0ms
memory: 2084kb
input:
9 0 1 2 3 4 5 6 7 9
output:
-1
result:
ok 1 number(s): "-1"
Test #10:
score: 0
Accepted
time: 1ms
memory: 2268kb
input:
9 0 1 2 3 4 5 6 7 8
output:
-1
result:
ok 1 number(s): "-1"
Test #11:
score: 0
Accepted
time: 1ms
memory: 2356kb
input:
4 1 3 7 9
output:
2
result:
ok 1 number(s): "2"
Test #12:
score: 0
Accepted
time: 1ms
memory: 2100kb
input:
7 1 2 3 4 5 7 8
output:
-1
result:
ok 1 number(s): "-1"
Test #13:
score: 0
Accepted
time: 1ms
memory: 2024kb
input:
8 0 1 2 3 4 5 7 8
output:
-1
result:
ok 1 number(s): "-1"
Test #14:
score: 0
Accepted
time: 1ms
memory: 2096kb
input:
8 1 2 3 4 5 6 7 8
output:
-1
result:
ok 1 number(s): "-1"
Test #15:
score: 0
Accepted
time: 1ms
memory: 2096kb
input:
5 1 2 3 5 7
output:
89
result:
ok 1 number(s): "89"
Test #16:
score: 0
Accepted
time: 1ms
memory: 2156kb
input:
6 1 2 3 5 7 8
output:
409
result:
ok 1 number(s): "409"
Test #17:
score: 0
Accepted
time: 1ms
memory: 2252kb
input:
8 0 1 2 3 5 6 7 8
output:
449
result:
ok 1 number(s): "449"
Test #18:
score: 0
Accepted
time: 1ms
memory: 2152kb
input:
5 2 3 5 7 9
output:
11
result:
ok 1 number(s): "11"
Test #19:
score: 0
Accepted
time: 1ms
memory: 2096kb
input:
6 1 2 4 5 7 8
output:
3
result:
ok 1 number(s): "3"
Test #20:
score: 0
Accepted
time: 1ms
memory: 2152kb
input:
8 0 1 2 4 5 7 8 9
output:
3
result:
ok 1 number(s): "3"
Test #21:
score: 0
Accepted
time: 0ms
memory: 2016kb
input:
8 0 1 3 5 6 7 8 9
output:
2
result:
ok 1 number(s): "2"
Test #22:
score: 0
Accepted
time: 1ms
memory: 2356kb
input:
8 0 2 3 5 6 7 8 9
output:
11
result:
ok 1 number(s): "11"
Test #23:
score: 0
Accepted
time: 1ms
memory: 2096kb
input:
8 0 2 4 5 6 7 8 9
output:
3
result:
ok 1 number(s): "3"
Test #24:
score: 0
Accepted
time: 1ms
memory: 2156kb
input:
7 0 2 3 5 6 7 8
output:
11
result:
ok 1 number(s): "11"
Test #25:
score: 0
Accepted
time: 1ms
memory: 2072kb
input:
8 2 3 4 5 6 7 8 9
output:
11
result:
ok 1 number(s): "11"
Test #26:
score: 0
Accepted
time: 1ms
memory: 2304kb
input:
8 0 1 2 5 6 7 8 9
output:
3
result:
ok 1 number(s): "3"
Test #27:
score: 0
Accepted
time: 1ms
memory: 2268kb
input:
1 2
output:
3
result:
ok 1 number(s): "3"
Test #28:
score: 0
Accepted
time: 0ms
memory: 2096kb
input:
10 0 1 2 3 4 5 6 7 8 9
output:
-1
result:
ok 1 number(s): "-1"
Test #29:
score: 0
Accepted
time: 1ms
memory: 2264kb
input:
7 0 2 3 5 6 8 9
output:
7
result:
ok 1 number(s): "7"
Test #30:
score: 0
Accepted
time: 1ms
memory: 2108kb
input:
8 1 2 3 4 5 6 7 9
output:
-1
result:
ok 1 number(s): "-1"
Test #31:
score: 0
Accepted
time: 1ms
memory: 2048kb
input:
4 0 2 6 7
output:
3
result:
ok 1 number(s): "3"
Test #32:
score: 0
Accepted
time: 1ms
memory: 2176kb
input:
5 2 3 4 6 8
output:
5
result:
ok 1 number(s): "5"
Test #33:
score: 0
Accepted
time: 1ms
memory: 2272kb
input:
6 0 2 3 4 5 8
output:
7
result:
ok 1 number(s): "7"
Test #34:
score: 0
Accepted
time: 1ms
memory: 2156kb
input:
3 1 5 7
output:
2
result:
ok 1 number(s): "2"
Test #35:
score: 0
Accepted
time: 1ms
memory: 2260kb
input:
3 1 4 9
output:
2
result:
ok 1 number(s): "2"
Test #36:
score: 0
Accepted
time: 1ms
memory: 2012kb
input:
6 2 3 4 6 7 9
output:
5
result:
ok 1 number(s): "5"
Test #37:
score: 0
Accepted
time: 1ms
memory: 2076kb
input:
7 1 2 3 4 5 6 8
output:
7
result:
ok 1 number(s): "7"
Test #38:
score: 0
Accepted
time: 1ms
memory: 2296kb
input:
6 0 1 3 5 8 9
output:
2
result:
ok 1 number(s): "2"
Test #39:
score: 0
Accepted
time: 1ms
memory: 2108kb
input:
3 1 3 4
output:
2
result:
ok 1 number(s): "2"
Test #40:
score: 0
Accepted
time: 0ms
memory: 2172kb
input:
4 1 5 6 9
output:
2
result:
ok 1 number(s): "2"
Test #41:
score: 0
Accepted
time: 1ms
memory: 2252kb
input:
7 0 2 3 5 6 7 9
output:
11
result:
ok 1 number(s): "11"
Test #42:
score: 0
Accepted
time: 1ms
memory: 2244kb
input:
4 0 3 7 9
output:
2
result:
ok 1 number(s): "2"
Extra Test:
score: 0
Extra Test Passed