QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#361500 | #8509. Expanding STACKS! | ucup-team635# | WA | 0ms | 2328kb | Rust | 2.6kb | 2024-03-23 10:48:57 | 2024-03-23 10:48:58 |
Judging History
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);
} else {
println!("*");
return;
}
} else {
let x = (-a) as usize;
ans.push(c[memo[x]]);
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: 2328kb
input:
2 +2 +1 -1 -2
output:
GG
result:
ok correct
Test #2:
score: 0
Accepted
time: 0ms
memory: 2060kb
input:
2 +1 +2 -1 -2
output:
GS
result:
ok correct
Test #3:
score: 0
Accepted
time: 0ms
memory: 2252kb
input:
3 +1 +2 +3 -1 -2 -3
output:
*
result:
ok correct
Test #4:
score: 0
Accepted
time: 0ms
memory: 2128kb
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: 2052kb
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