Submission #63036688
Source Code Expand
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
//#[derive_readable]
#[derive(Debug, Clone)]
struct Problem {
xs: Vec<char>,
}
impl Problem {
fn read() -> Problem {
input! {
xs: Chars,
}
Problem { xs }
}
fn solve0(&self) -> bool {
let xs = &self.xs;
let mut stack: Stack<char> = Stack::new();
let map = maplit::hashmap! {
')' => '(',
']' => '[',
'>' => '<',
};
for &x in xs {
if x == '(' || x == '[' || x == '<' {
stack.push(x);
}
if x == ')' || x == ']' || x == '>' {
let req = map[&x];
if stack.peek() == Some(&req) {
stack.pop();
} else {
return false;
}
}
}
stack.is_empty()
}
fn solve(&self) -> Answer {
let ans = self.solve0();
Answer { ans }
}
#[allow(dead_code)]
fn solve_naive(&self) -> Answer {
todo!();
// let ans = 0;
// Answer { ans }
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
struct Answer {
ans: bool,
}
impl Answer {
fn print(&self) {
print_yesno(self.ans);
}
}
fn main() {
Problem::read().solve().print();
}
#[cfg(test)]
mod tests {
#[allow(unused_imports)]
use super::*;
#[allow(unused_imports)]
use rand::{rngs::SmallRng, seq::SliceRandom, *};
#[test]
fn test_problem() {
assert_eq!(1 + 1, 2);
}
#[allow(dead_code)]
#[derive(Debug)]
struct WrongTestCase {
problem: Problem,
main_ans: Answer,
naive_ans: Answer,
}
#[allow(dead_code)]
fn check(p: &Problem) -> Option<WrongTestCase> {
let main_ans = p.solve();
let naive_ans = p.solve_naive();
if main_ans != naive_ans {
Some(WrongTestCase {
problem: p.clone(),
main_ans,
naive_ans,
})
} else {
None
}
}
#[allow(dead_code)]
fn make_random_problem(rng: &mut SmallRng) -> Problem {
todo!()
// let n = rng.gen_range(1..=10);
// let p = Problem { _a: n };
// println!("{:?}", &p);
// p
}
#[allow(unreachable_code)]
#[test]
fn test_with_naive() {
let num_tests = 0;
let max_wrong_case = 10; // この件数間違いが見つかったら打ち切り
let mut rng = SmallRng::seed_from_u64(42);
// let mut rng = SmallRng::from_entropy();
let mut wrong_cases: Vec<WrongTestCase> = vec![];
for _ in 0..num_tests {
let p = make_random_problem(&mut rng);
let result = check(&p);
if let Some(wrong_test_case) = result {
wrong_cases.push(wrong_test_case);
}
if wrong_cases.len() >= max_wrong_case {
break;
}
}
if !wrong_cases.is_empty() {
for t in &wrong_cases {
println!("{:?}", t.problem);
println!("main ans : {:?}", t.main_ans);
println!("naive ans: {:?}", t.naive_ans);
println!();
}
println!("{} cases are wrong.", wrong_cases.len());
panic!();
}
}
}
// ====== import ======
#[allow(unused_imports)]
use itertools::{chain, iproduct, izip, Itertools};
#[allow(unused_imports)]
use proconio::{
derive_readable, fastout, input,
marker::{Bytes, Chars, Usize1},
};
#[allow(unused_imports)]
use std::cmp::Reverse;
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap, HashSet};
// ====== output func ======
#[allow(unused_imports)]
use print_vec::*;
pub mod print_vec {
use itertools::Itertools;
use proconio::fastout;
#[fastout]
pub fn print_vec<T: std::fmt::Display>(arr: &[T]) {
for a in arr {
println!("{}", a);
}
}
#[fastout]
pub fn print_vec_1line<T: std::fmt::Display>(arr: &[T]) {
let msg = arr.iter().map(|x| format!("{}", x)).join(" ");
println!("{}", msg);
}
#[fastout]
pub fn print_vec2<T: std::fmt::Display>(arr: &Vec<Vec<T>>) {
for row in arr {
let msg = row.iter().map(|x| format!("{}", x)).join(" ");
println!("{}", msg);
}
}
pub fn print_bytes(bytes: &[u8]) {
let msg = String::from_utf8(bytes.to_vec()).unwrap();
println!("{}", msg);
}
pub fn print_chars(chars: &[char]) {
let msg = chars.iter().collect::<String>();
println!("{}", msg);
}
#[fastout]
pub fn print_vec_bytes(vec_bytes: &[Vec<u8>]) {
for row in vec_bytes {
let msg = String::from_utf8(row.to_vec()).unwrap();
println!("{}", msg);
}
}
}
#[allow(unused)]
fn print_yesno(ans: bool) {
let msg = if ans { "Yes" } else { "No" };
println!("{}", msg);
}
// ====== snippet ======
use mod_stack::*;
pub mod mod_stack {
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Stack<T> {
raw: Vec<T>,
}
impl<T> Stack<T> {
pub fn new() -> Self {
Stack { raw: Vec::new() }
}
pub fn push(&mut self, value: T) {
self.raw.push(value)
}
pub fn pop(&mut self) -> Option<T> {
self.raw.pop()
}
pub fn peek(&self) -> Option<&T> {
self.raw.last()
}
pub fn is_empty(&self) -> bool {
self.raw.is_empty()
}
pub fn len(&self) -> usize {
self.raw.len()
}
}
impl<T> Default for Stack<T> {
fn default() -> Self {
Self::new()
}
}
}
Submission Info
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
400 / 400 |
Status |
|
|
Set Name |
Test Cases |
Sample |
example_00.txt, example_01.txt, example_02.txt |
All |
example_00.txt, example_01.txt, example_02.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt |
Case Name |
Status |
Exec Time |
Memory |
example_00.txt |
AC |
0 ms |
2064 KB |
example_01.txt |
AC |
0 ms |
1936 KB |
example_02.txt |
AC |
0 ms |
2008 KB |
hand_00.txt |
AC |
3 ms |
3232 KB |
hand_01.txt |
AC |
3 ms |
2896 KB |
hand_02.txt |
AC |
3 ms |
3076 KB |
hand_03.txt |
AC |
0 ms |
1904 KB |
hand_04.txt |
AC |
3 ms |
3152 KB |
hand_05.txt |
AC |
1 ms |
1800 KB |
hand_06.txt |
AC |
0 ms |
1912 KB |
random_00.txt |
AC |
1 ms |
2964 KB |
random_01.txt |
AC |
3 ms |
3244 KB |
random_02.txt |
AC |
3 ms |
3232 KB |
random_03.txt |
AC |
3 ms |
3168 KB |
random_04.txt |
AC |
2 ms |
3248 KB |
random_05.txt |
AC |
3 ms |
3156 KB |
random_06.txt |
AC |
1 ms |
2828 KB |
random_07.txt |
AC |
2 ms |
2928 KB |
random_08.txt |
AC |
2 ms |
3160 KB |
random_09.txt |
AC |
3 ms |
3180 KB |
random_10.txt |
AC |
3 ms |
2880 KB |
random_11.txt |
AC |
3 ms |
2844 KB |
random_12.txt |
AC |
3 ms |
2756 KB |
random_13.txt |
AC |
2 ms |
2692 KB |
random_14.txt |
AC |
3 ms |
2848 KB |
random_15.txt |
AC |
3 ms |
2896 KB |
random_16.txt |
AC |
3 ms |
2808 KB |
random_17.txt |
AC |
2 ms |
2824 KB |
random_18.txt |
AC |
3 ms |
2824 KB |
random_19.txt |
AC |
2 ms |
2832 KB |
random_20.txt |
AC |
3 ms |
2896 KB |
random_21.txt |
AC |
3 ms |
2788 KB |
random_22.txt |
AC |
3 ms |
2740 KB |
random_23.txt |
AC |
3 ms |
2748 KB |
random_24.txt |
AC |
3 ms |
2812 KB |
random_25.txt |
AC |
2 ms |
2820 KB |
random_26.txt |
AC |
3 ms |
2772 KB |
random_27.txt |
AC |
3 ms |
2756 KB |
random_28.txt |
AC |
3 ms |
2736 KB |
random_29.txt |
AC |
3 ms |
2808 KB |