Submission #1675240
Source Code Expand
#![allow(unused_imports, unused_variables, dead_code)] use std::io::*; use std::fmt::*; use std::str::*; use std::cmp::*; use std::collections::*; trait InputValue { fn parse(s: &str) -> Self; } fn read<T: InputValue>() -> T { let mut buf = String::new(); let _ = stdin().read_line(&mut buf); T::parse(&buf.trim()) } fn readnc<T: InputValue>() -> Vec<T> { let mut vec = vec![]; let line: String = read(); for token in line.split_whitespace() { vec.push(T::parse(token)); } vec } fn readn<T: InputValue>(n: usize) -> Vec<T> { let mut vec = vec![]; for _ in 0..n { vec.push(read()); } vec } macro_rules! parse_single_value { ($($t:ty),*) => { $( impl InputValue for $t { fn parse(s: &str) -> $t { s.parse().unwrap() } } )* } } parse_single_value!(i32, i64, f32, f64, usize, String); macro_rules! parse_tuple { ($($t:ident),*) => { impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* { fn parse(s: &str) -> ($($t),*) { let mut tokens = s.split_whitespace(); let t = ($($t::parse(tokens.next().unwrap())),*); t } } } } parse_tuple!(A, B); parse_tuple!(A, B, C); // === fn main() { let n: usize = read(); let s: Vec<char> = read::<String>().into_bytes().into_iter().map(|a| a as char).collect(); let mut res = vec![false; n]; let mut is_ok = false; for ptn in 0..4 { res[0] = ptn & 1 == 1; res[1] = ptn & 2 == 2; fill(&mut res, &s); if is_valid(&mut res, &s) { is_ok = true; break; } } if is_ok { for i in 0..n { print!("{}", if res[i] { 'S' } else { 'W' }); } println!(); } else { println!("-1"); } } fn fill(animals: &mut Vec<bool>, statement: &Vec<char>) { let n = animals.len(); for ri in 2..n { let li = ri-2; let i = ri-1; animals[ri] = animals[i] ^ animals[li] ^ (statement[i] == 'o'); } } fn is_valid(animals: &Vec<bool>, statement: &Vec<char>) -> bool { let n = animals.len(); for i in 0..n { let li = (i+n-1)%n; let ri = (i+1)%n; if animals[i] ^ (animals[li] == animals[ri]) ^ (statement[i] == 'x') { return false; } } true }
Submission Info
Submission Time | |
---|---|
Task | D - Menagerie |
User | hamadu |
Language | Rust (1.15.1) |
Score | 500 |
Code Size | 2454 Byte |
Status | AC |
Exec Time | 17 ms |
Memory | 4352 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 500 / 500 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 00_example_01.txt, 00_example_02.txt, 00_example_03.txt |
All | 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
00_example_01.txt | AC | 2 ms | 4352 KB |
00_example_02.txt | AC | 2 ms | 4352 KB |
00_example_03.txt | AC | 2 ms | 4352 KB |
01.txt | AC | 12 ms | 4352 KB |
02.txt | AC | 9 ms | 4352 KB |
03.txt | AC | 2 ms | 4352 KB |
04.txt | AC | 2 ms | 4352 KB |
05.txt | AC | 15 ms | 4352 KB |
06.txt | AC | 17 ms | 4352 KB |
07.txt | AC | 5 ms | 4352 KB |
08.txt | AC | 5 ms | 4352 KB |
09.txt | AC | 3 ms | 4352 KB |
10.txt | AC | 2 ms | 4352 KB |
11.txt | AC | 16 ms | 4352 KB |
12.txt | AC | 17 ms | 4352 KB |
13.txt | AC | 17 ms | 4352 KB |