QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#361492#8509. Expanding STACKS!ucup-team635#WA 0ms2256kbRust2.6kb2024-03-23 10:45:512024-03-23 10:45:51

Judging History

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

  • [2024-03-23 10:45:51]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:2256kb
  • [2024-03-23 10:45:51]
  • 提交

answer

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() {
    input! {
        n: usize,
        a: [i32; 2 * n],
    }
    let mut leave = vec![0; n + 1];
    for (i, a) in a.iter().enumerate() {
        if *a < 0 {
            leave[(-*a) as usize] = i;
        }
    }
    let mut stack = vec![vec![2 * n + 4], vec![2 * n + 5]];
    let mut memo = vec![0; n + 1];
    let mut ans = String::new();
    let c = ['G', 'S'];
    for &a in a.iter() {
        if a > 0 {
            let r = leave[a as usize];
            if let Some(x) = (0..2)
                .filter(|&x| r < *stack[x].last().unwrap())
                .min_by_key(|&x| *stack[x].last().unwrap())
            {
                memo[a as usize] = x;
                stack[x].push(r);
                ans.push(c[x]);
            } else {
                println!("*");
                return;
            }
        } else {
            let x = (-a) as usize;
            assert!(stack[memo[x]].pop().unwrap() == leave[x]);
        }
    }
    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 ----------

详细

Test #1:

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

input:

2
+2 +1 -1 -2

output:

GG

result:

ok correct

Test #2:

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

input:

2
+1 +2 -1 -2

output:

GS

result:

ok correct

Test #3:

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

input:

3
+1 +2 +3 -1 -2 -3

output:

*

result:

ok correct

Test #4:

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

input:

10
+3 -3 +4 -4 +6 +2 -2 -6 +7 -7 +5 -5 +10 +1 +9 +8 -8 -9 -1 -10

output:

GGGGGGGGGG

result:

ok correct

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 2256kb

input:

10
+8 -8 +2 +10 -2 -10 +7 -7 +1 -1 +6 -6 +5 +3 +4 +9 -9 -4 -3 -5

output:

GGSGGGGGGG

result:

wrong answer client leaving is not the top of its stack