QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#530038#9221. Missing Boundariesucup-team635#WA 64ms18076kbRust4.1kb2024-08-24 14:42:482024-08-24 14:42:48

Judging History

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

  • [2024-08-24 14:42:48]
  • 评测
  • 测评结果:WA
  • 用时:64ms
  • 内存:18076kb
  • [2024-08-24 14:42:48]
  • 提交

answer

// ---------- 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 _ in 0..t {
        let n: usize = sc.next();
        let l: i64 = sc.next();
        let mut p = vec![(0i64, 0i64); n];
        for p in p.iter_mut() {
            p.0 = sc.next();
            p.1 = sc.next();
        }
        let ans = if solve(p, l) { "TAK" } else { "NIE" };
        writeln!(out, "{}", ans).ok();
    }
}

fn solve(mut p: Vec<(i64, i64)>, l: i64) -> bool {
    let n = p.len();
    p.retain(|p| *p != (-1, -1));
    let free = (n - p.len()) as i64;
    if p.is_empty() {
        return free <= l;
    }
    let mut map = Map::<i64, i64>::new();
    for &(l, r) in p.iter() {
        if l != -1 && r != -1 {
            if let Some((k, v)) = map.range(..=l).next_back() {
                if l <= *v {
                    return false;
                }
            }
            if let Some((k, v)) = map.range(l..).next() {
                if *k <= r {
                    return false;
                }
            }
            map.insert(l, r);
        }
    }
    for &(l, r) in p.iter() {
        if l != -1 && r != -1 {
            continue;
        }
        if l != -1 {
            if let Some((k, v)) = map.range(..=l).next_back() {
                if l <= *v {
                    return false;
                }
            }
        }
        if r != -1 {
            if let Some((k, v)) = map.range(..=r).next_back() {
                if r <= *v {
                    return false;
                }
            }
        }
    }
    let mut z = vec![];
    for (i, &(l, r)) in p.iter().enumerate() {
        if l != -1 && r != -1 {
            z.push((l, true, i));
            z.push((r, false, i));
        } else if l != -1 {
            z.push((l, true, i));
        } else {
            z.push((r, false, i));
        }
    }
    z.sort();
    let mut range = (0, 0);
    for z in z.windows(2) {
        let l = z[0];
        let r = z[1];
        if l.2 == r.2 {
            continue;
        }
        let d = r.0 - l.0 - 1;
        if !l.1 && r.1 {
            if d > 0 {
                range.0 += 1;
                range.1 += d;
            }
        } else {
            range.1 += d;
        }
    }
    let f = z[0];
    if f.0 == 1 {
    } else {
        let d = f.0 - 1;
        if f.1 {
            range.0 += 1;
            range.1 += d;
        } else {
            range.1 += d;
        }
    }
    let t = z[z.len() - 1];
    if t.0 == l {
    } else {
        let d = l - t.0;
        if !t.1 {
            range.0 += 1;
            range.1 += d;
        } else {
            range.1 += d;
        }
    }
    range.0 <= free && free <= range.1
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 2152kb

input:

3
4 51
1 -1
11 50
-1 -1
-1 10
3 2
-1 -1
-1 -1
-1 -1
2 3
1 2
2 3

output:

TAK
NIE
NIE

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 64ms
memory: 18076kb

input:

1
200000 1000000000
490669427 -1
224278942 224287156
821104480 -1
861696576 861702036
807438935 807440055
574078002 574083717
465630141 -1
195378188 -1
-1 13500961
-1 977536179
92893115 -1
-1 661145418
-1 215804863
-1 685338515
544348999 -1
465532902 -1
130346949 -1
-1 526666304
635604584 635605404
...

output:

TAK

result:

ok single line: 'TAK'

Test #3:

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

input:

3
4 51
1 -1
11 50
-1 -1
-1 10
3 2
-1 -1
-1 -1
-1 -1
2 3
1 2
2 3

output:

TAK
NIE
NIE

result:

ok 3 lines

Test #4:

score: 0
Accepted
time: 60ms
memory: 15864kb

input:

1
197838 400000
34167 34169
352180 -1
235963 -1
-1 -1
160401 160405
347288 -1
270353 270354
214502 214504
183243 183245
-1 -1
-1 36193
-1 -1
-1 17557
273498 273500
269137 -1
395099 395100
285515 285518
-1 -1
71041 71042
324060 -1
-1 385151
-1 379645
-1 -1
-1 185142
-1 191584
89259 89261
328347 32834...

output:

TAK

result:

ok single line: 'TAK'

Test #5:

score: -100
Wrong Answer
time: 41ms
memory: 9172kb

input:

2
97340 150000
-1 101927
105937 -1
-1 107253
-1 47307
110550 -1
84061 84062
125176 125177
-1 15915
29617 -1
-1 -1
-1 43147
115958 -1
101807 101808
24866 -1
66826 66828
-1 31640
-1 5610
1281 1284
-1 -1
-1 -1
-1 73973
-1 2945
29064 -1
30653 -1
-1 63714
-1 -1
141389 141390
-1 27465
57358 -1
47388 47389...

output:

TAK
NIE

result:

wrong answer 1st lines differ - expected: 'NIE', found: 'TAK'