QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#205829#7558. Abstractucup-team635#WA 14ms10084kbRust3.6kb2023-10-07 17:31:562023-10-07 17:31:57

Judging History

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

  • [2023-10-07 17:31:57]
  • 评测
  • 测评结果:WA
  • 用时:14ms
  • 内存:10084kb
  • [2023-10-07 17:31:56]
  • 提交

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,
        m: usize,
        a: [u64; n],
        e: [(usize1, usize1); m],
    }
    if a.iter().all(|a| *a == 0) {
        println!("0");
        return;
    }
    let mut g = vec![vec![]; n];
    let mut h = vec![vec![]; n];
    let mut deg = vec![0; n];
    for &(s, t) in e.iter() {
        g[s].push(t);
        h[t].push(s);
        deg[s] += 1;
    }
    let mut topo = vec![];
    topo.push(g.iter().position(|g| g.is_empty()).unwrap());
    for i in 0..n {
        let v = topo[i];
        for &u in h[v].iter() {
            deg[u] -= 1;
            if deg[u] == 0 {
                topo.push(u);
            }
        }
    }
    let norm = |a: &mut Vec<u64>| {
        while a.last().map_or(false, |p| *p == 0) {
            a.pop();
        }
    };
    let add = |a: &mut Vec<u64>, b: &[u64]| {
        let len = a.len().max(b.len());
        a.resize(len + 1, 0);
        let mut carry = 0;
        for (a, b) in a.iter_mut().zip(b.iter()) {
            let (x, c) = (*a).overflowing_add(*b);
            let (x, d) = x.overflowing_add(carry);
            *a = x;
            if c || d {
                carry = 1;
            } else {
                carry = 0;
            }
        }
        norm(a);
    };
    let mut dp = a.iter().map(|a| vec![*a]).collect::<Vec<_>>();
    for &v in topo[1..].iter().rev() {
        let mut src = std::mem::take(&mut dp[v]);
        let len = src.len();
        src.push(0);
        for i in (0..len).rev() {
            let v = src[i];
            if v >> 63 & 1 == 1 {
                src[i + 1] += 1;
            }
            src[i] = v << 1;
        }
        norm(&mut src);
        for &u in g[v].iter() {
            add(&mut dp[u], &src);
        }
    }
    let dp = &mut dp[topo[0]];
    norm(dp);
    let mut x = 63;
    while *dp.last().unwrap() >> x & 1 == 0 {
        x -= 1;
    }
    let ans = (dp.len() - 1) * 64 + x + 1;
    println!("{}", ans);
}

// ---------- 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: 100
Accepted
time: 0ms
memory: 2052kb

input:

3 2
1 1 1
1 2
2 3

output:

3

result:

ok 1 number(s): "3"

Test #2:

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

input:

6 8
1 1 4 5 1 4
1 4
1 5
2 3
2 5
3 4
4 5
4 6
5 6

output:

8

result:

ok 1 number(s): "8"

Test #3:

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

input:

5 6
7 2 3 6 6
1 2
1 4
2 3
3 4
3 5
4 5

output:

9

result:

ok 1 number(s): "9"

Test #4:

score: -100
Wrong Answer
time: 14ms
memory: 10084kb

input:

7286 80481
637288250 628935175 588324396 766398783 663989874 865498593 695497968 630237220 19939888 448367842 412696777 111291257 304805809 585852799 58270069 391993802 606944382 827515045 389862501 643981354 160381074 324288921 257053597 980043955 417281046 870855665 360154617 60327683 966755927 55...

output:

7342

result:

wrong answer 1st numbers differ - expected: '7344', found: '7342'