QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#303932 | #8008. Fortune Wheel | ucup-team635# | WA | 13ms | 3660kb | Rust | 2.6kb | 2024-01-13 08:36:32 | 2024-01-13 08:36:32 |
Judging History
answer
use std::io::Write;
use std::collections::*;
type Map<K, V> = BTreeMap<K, V>;
type Set<T> = BTreeSet<T>;
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;
if u >= n {
u -= n;
}
if dp[u] > d {
dp[u] = d;
deq.push_back(u);
}
}
}
let mut ans = (dp[src], 1);
let sum = dp.iter().filter(|p| **p != inf).sum::<usize>();
let c = dp.iter().filter(|p| **p == inf).count();
let p = (sum + n, n - c);
if ans.0 * p.1 > p.0 * ans.1 {
ans = p;
}
for i in (2..=n).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 ----------
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 2168kb
input:
6 3 2 2 4
output:
8 3
result:
ok 2 number(s): "8 3"
Test #2:
score: 0
Accepted
time: 0ms
memory: 2092kb
input:
5 4 1 1
output:
1 1
result:
ok 2 number(s): "1 1"
Test #3:
score: 0
Accepted
time: 13ms
memory: 3660kb
input:
99999 65238 100 64714 45675 36156 13116 93455 22785 10977 60219 14981 25839 83709 80404 41400 12469 31530 65521 35436 20326 96792 50699 27522 98233 26187 12509 90992 72693 83919 74145 80892 68422 38333 33497 89154 88403 77492 4570 3908 59194 3482 89871 96330 45114 5555 73987 95832 476 949 74649 2084...
output:
3 1
result:
ok 2 number(s): "3 1"
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 2304kb
input:
10000 23 7 9594 8998 9330 6851 1662 6719 583
output:
94179 10000
result:
wrong answer 1st numbers differ - expected: '42726', found: '94179'