Task: | Järjestäminen |
Sender: | antti_p |
Submission time: | 2021-01-23 18:30:38 +0200 |
Language: | Rust |
Status: | READY |
Result: | 100 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 36 |
#2 | ACCEPTED | 64 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.01 s | 1, 2 | details |
#2 | ACCEPTED | 0.01 s | 2 | details |
#3 | ACCEPTED | 0.01 s | 1, 2 | details |
#4 | ACCEPTED | 0.01 s | 1, 2 | details |
Code
use std::io::{self, BufRead}; /* fn suurempi(s: &str) { let mut chars = s.chars().enumerate().skip_while(|&(_, x)| x == '0'); let (size, first) = chars.next().unwrap(); let size = s.len() - size; let mut chars = chars.map(|(_, x)| x); for c in chars { match c { '0'..='9' => { if c as u8 > first as u8 { println!("{}", [((first as u8 + 1) as char)].iter().cycle().take(size).collect::<String>()); return; } else if (c as u8) < first as u8 { println!("{}", [first].iter().cycle().take(size).collect::<String>()); return } } '\n' => { break; } _ => panic!(), } } if first != '9' { println!("{}", [((first as u8 + 1) as char)].iter().cycle().take(size).collect::<String>()); } else { println!("{}", ['1'].iter().cycle().take(size + 1).collect::<String>()); } } */ fn jarjesta(a: &mut [usize]) -> bool { if a.len() < 5 { match a { [0, 1, 2, 3] => return true, [2, 3, 0, 1] => return true, [0, 1, 2] => return true, [0, 1] => return true, [0] => return true, _ => return false, } } for n in 0..a.len() { //println!("State of the array: {:?}", a); let mut pos = a.iter().enumerate().find(|(_, &x)| x == n).unwrap().0; if pos == n { continue } if pos + 1 == a.len() { if n + 2 >= a.len() { //println!("Returning false from b"); return false; } // ABC -> CAB let tmp = a[pos]; a[pos] = a[pos - 1]; a[pos - 1] = a[pos - 2]; a[pos - 2] = tmp; pos = pos - 2; } if pos == n { continue } if pos == n + 1 { if pos + 1 >= a.len() { //println!("Returning false from a"); return false; } // ABC -> BCA let tmp = a[pos - 1]; a[pos - 1] = a[pos]; a[pos] = a[pos + 1]; a[pos + 1] = tmp; continue } let tmp = a[pos]; a[pos] = a[n]; a[n] = tmp; let tmp = a[pos + 1]; a[pos + 1] = a[n + 1]; a[n + 1] = tmp; } true } fn main() { let stdin = io::stdin(); let mut lines = stdin.lock().lines(); let count = lines.next().unwrap().unwrap().parse::<usize>().unwrap(); let mut ignore = true; for line in lines.take(count*2) { /* suurempi(&line.unwrap()); */ if !ignore { let mut v : Vec<_> = line.unwrap().split_whitespace().map(|x| x.parse::<usize>().unwrap() - 1).collect(); if jarjesta(&mut v) { println!("YES"); } else { println!("NO"); } } ignore = !ignore; } }
Test details
Test 1
Group: 1, 2
Verdict: ACCEPTED
input |
---|
153 1 1 2 1 2 ... |
correct output |
---|
YES YES NO NO NO ... |
user output |
---|
YES YES NO NO NO ... Truncated |
Test 2
Group: 2
Verdict: ACCEPTED
input |
---|
1000 59 35 29 32 50 11 15 9 21 19 45 2... |
correct output |
---|
YES NO YES NO YES ... |
user output |
---|
YES NO YES NO YES ... Truncated |
Test 3
Group: 1, 2
Verdict: ACCEPTED
input |
---|
720 6 1 6 4 5 2 3 6 6 3 2 1 5 4 ... |
correct output |
---|
YES NO NO NO YES ... |
user output |
---|
YES NO NO NO YES ... Truncated |
Test 4
Group: 1, 2
Verdict: ACCEPTED
input |
---|
1000 8 7 4 2 8 6 3 5 1 8 3 8 2 7 5 4 6 1 ... |
correct output |
---|
NO NO YES NO YES ... |
user output |
---|
NO NO YES NO YES ... Truncated |