QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#254460#7750. Revenge on My Bossucup-team635#WA 0ms2036kbRust4.2kb2023-11-18 12:46:382023-11-18 12:46:38

Judging History

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

  • [2023-11-18 12:46:38]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:2036kb
  • [2023-11-18 12:46:38]
  • 提交

answer

mod util {
    pub trait Join {
        fn join(self, sep: &str) -> String;
    }

    impl<T, I> Join for I
    where
        I: Iterator<Item = T>,
        T: std::fmt::Display,
    {
        fn join(self, sep: &str) -> String {
            let mut s = String::new();
            use std::fmt::*;
            for (i, v) in self.enumerate() {
                if i > 0 {
                    write!(&mut s, "{}", sep).ok();
                }
                write!(&mut s, "{}", v).ok();
            }
            s
        }
    }
}

// ---------- begin scannner ----------
#[allow(dead_code)]
mod scanner {
    use std::str::FromStr;
    pub struct Scanner<'a> {
        it: std::str::SplitWhitespace<'a>,
    }
    impl<'a> Scanner<'a> {
        pub fn new(s: &'a String) -> Scanner<'a> {
            Scanner {
                it: s.split_whitespace(),
            }
        }
        pub fn next<T: FromStr>(&mut self) -> T {
            self.it.next().unwrap().parse::<T>().ok().unwrap()
        }
        pub fn next_bytes(&mut self) -> Vec<u8> {
            self.it.next().unwrap().bytes().collect()
        }
        pub fn next_chars(&mut self) -> Vec<char> {
            self.it.next().unwrap().chars().collect()
        }
        pub fn next_vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
            (0..len).map(|_| self.next()).collect()
        }
    }
}
// ---------- end scannner ----------

use std::collections::*;
use std::io::Write;

type Map<K, V> = BTreeMap<K, V>;
type Set<T> = BTreeSet<T>;
type Deque<T> = VecDeque<T>;

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut sc = scanner::Scanner::new(&s);
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    run(&mut sc, &mut out);
}

fn run<W: Write>(sc: &mut scanner::Scanner, out: &mut std::io::BufWriter<W>) {
    let t: u32 = sc.next();
    for it in 0..t {
        let n: usize = sc.next();
        let mut p = vec![(0, 0, 0); n];
        let mut fix = 0;
        for p in p.iter_mut() {
            p.0 = sc.next::<i64>();
            p.1 = sc.next::<i64>();
            p.2 = sc.next::<i64>();
            let v = p.0.min(p.1);
            fix += v;
            p.0 -= v;
            p.1 -= v;
        }
        let fix = fix;
        let mut ord = (0..n).collect::<Vec<_>>();
        ord.sort_by_key(|&v| p[v].0 - p[v].1);
        let pos = ord.iter().position(|&v| p[v].0 - p[v].1 >= 0).unwrap_or(n);
        let mut l = ord[..pos].iter()
            .map(|&k| (p[k].2, p[k].1, k))
            .collect::<Vec<_>>();
        let mut r = ord[pos..].iter()
            .map(|&k| (p[k].2, p[k].0, k))
            .collect::<Vec<_>>();
        l.sort();
        r.sort();
        let mut ng = 0;
        let mut ok = 10i64.pow(12 + 5 + 1);
        while ok - ng > 1 {
            let mid = (ok + ng) / 2;
            if let (Some(_), Some(_)) = (calc(&l, fix, mid), calc(&r, fix, mid)) {
                ok = mid;
            } else {
                ng = mid;
            }
        }
        let l = calc(&l, fix, ok).unwrap();
        let r = calc(&r, fix, ok).unwrap();
        let ans = l
            .into_iter()
            .chain(r.into_iter().rev())
            .map(|p| p + 1)
            .collect::<Vec<_>>();
        let mut val = 0;
        let mut sum = fix + p.iter().map(|p| p.1).sum::<i64>();
        for &x in ans.iter() {
            let x = x - 1;
            sum += p[x].0;
            val = val.max(sum * p[x].2);
            sum -= p[x].1;
        }
        use util::*;
        writeln!(out, "{}", ans.iter().join(" ")).ok();
    }
}

fn calc(p: &[(i64, i64, usize)], geta: i64, mid: i64) -> Option<Vec<usize>> {
    let mut sum = geta + p.iter().map(|p| p.1).sum::<i64>();
    let mut h = std::collections::BinaryHeap::new();
    let mut x = 0;
    let mut ans = vec![];
    for _ in 0..p.len() {
        while x < p.len() && p[x].0 * sum <= mid {
            h.push((p[x].1, p[x].2));
            x += 1;
        }
        if let Some((a, k)) = h.pop() {
            ans.push(k);
            sum -= a;
        } else {
            return None;
        }
    }
    Some(ans)
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 2036kb

input:

2
4
1 1 4
5 1 5
1 9 1
9 8 1
9
3 1 4
1 5 9
2 6 5
3 5 8
9 7 9
3 2 3
8 4 6
2 6 8
3 2 7

output:

3 1 2 4
3 8 2 4 6 9 1 5 7

result:

wrong answer Wrong Answer on Case#2