QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#303940 | #8008. Fortune Wheel | ucup-team635# | TL | 0ms | 0kb | Rust | 2.8kb | 2024-01-13 08:42:11 | 2024-01-13 08:42:12 |
Judging History
answer
use std::collections::*;
type Deque<T> = VecDeque<T>;
fn main() {
input! {
n: usize,
src: usize,
m: usize,
a: [usize; m],
}
let inf = n + 1;
let mut dp = vec![inf; n];
dp[0] = 0;
let mut deq = Deque::new();
deq.push_back(0);
while let Some(v) = deq.pop_front() {
let d = dp[v] + 1;
for &a in a.iter() {
let mut u = v + n - a;
while u >= n {
u -= n;
}
if dp[u] > d {
dp[u] = d;
deq.push_back(u);
}
}
}
let mut ans = (dp[src], 1);
dp.sort();
let mut sum = dp.iter().filter(|p| **p != inf).sum::<usize>();
let mut c = dp.iter().filter(|p| **p == inf).count();
while dp.len() > 0 {
let p = (sum + n, n - c);
if ans.0 * p.1 > p.0 * ans.1 {
ans = p;
}
let v = dp.pop().unwrap();
sum -= v;
c += 1;
while dp.last().map_or(false, |p| *p == v) {
dp.pop();
sum -= v;
c += 1;
}
}
for i in (2..=ans.1).rev() {
if ans.0 % i == 0 && ans.1 % i == 0 {
ans.0 /= i;
ans.1 /= i;
}
}
println!("{} {}", ans.0, ans.1);
}
// ---------- begin input macro ----------
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[macro_export]
macro_rules! input {
(source = $s:expr, $($r:tt)*) => {
let mut iter = $s.split_whitespace();
input_inner!{iter, $($r)*}
};
($($r:tt)*) => {
let s = {
use std::io::Read;
let mut s = String::new();
std::io::stdin().read_to_string(&mut s).unwrap();
s
};
let mut iter = s.split_whitespace();
input_inner!{iter, $($r)*}
};
}
#[macro_export]
macro_rules! input_inner {
($iter:expr) => {};
($iter:expr, ) => {};
($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
let $var = read_value!($iter, $t);
input_inner!{$iter $($r)*}
};
}
#[macro_export]
macro_rules! read_value {
($iter:expr, ( $($t:tt),* )) => {
( $(read_value!($iter, $t)),* )
};
($iter:expr, [ $t:tt ; $len:expr ]) => {
(0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
};
($iter:expr, chars) => {
read_value!($iter, String).chars().collect::<Vec<char>>()
};
($iter:expr, bytes) => {
read_value!($iter, String).bytes().collect::<Vec<u8>>()
};
($iter:expr, usize1) => {
read_value!($iter, usize) - 1
};
($iter:expr, $t:ty) => {
$iter.next().unwrap().parse::<$t>().expect("Parse error")
};
}
// ---------- end input macro ----------
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
6 3 2 2 4