Submission #32161014
Source Code Expand
use std::collections::HashMap;
use proconio::input;
fn main() {
input! {
n: usize,
mut a: [usize; n],
b: [usize; n]
};
let mut m_a = HashMap::new();
for a_i in a.iter().copied() {
*m_a.entry(a_i).or_insert(0) += 1;
}
let mut m_b = HashMap::new();
for b_i in b.iter().copied() {
*m_b.entry(b_i).or_insert(0) += 1;
}
if m_a != m_b {
println!("No");
return;
}
if m_a.values().any(|&v| v >= 2) {
println!("Yes");
return;
}
for (i, b_i) in b.iter().copied().enumerate().take(n - 2) {
let mut j = i;
while j < n && a[j] != b_i {
j += 1;
}
if j == n {
println!("No");
return;
}
while i < j {
if i + 1 == j {
a[j - 1..=j + 1].rotate_right(2);
break;
} else {
a[j - 2..=j].rotate_right(1);
j -= 2;
}
}
}
let ans = a[n - 2] == b[n - 2] && a[n - 1] == b[n - 1];
println!("{}", if ans { "Yes" } else { "No" });
}
Submission Info
| Submission Time | |
|---|---|
| Task | B - Triple Shift |
| User | bouzuya |
| Language | Rust (1.42.0) |
| Score | 400 |
| Code Size | 1134 Byte |
| Status | AC |
| Exec Time | 42 ms |
| Memory | 2656 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 400 / 400 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00-sample-001.txt, 00-sample-002.txt, 00-sample-003.txt |
| All | 00-sample-001.txt, 00-sample-002.txt, 00-sample-003.txt, 01-001.txt, 01-002.txt, 01-003.txt, 01-004.txt, 01-005.txt, 01-006.txt, 01-007.txt, 01-008.txt, 01-009.txt, 01-010.txt, 01-011.txt, 01-012.txt, 01-013.txt, 01-014.txt, 01-015.txt, 01-016.txt, 01-017.txt, 01-018.txt, 01-019.txt, 01-020.txt, 01-021.txt, 01-022.txt, 01-023.txt, 01-024.txt, 01-025.txt, 01-026.txt, 01-027.txt, 01-028.txt, 01-029.txt, 01-030.txt, 01-031.txt, 01-032.txt, 01-033.txt, 01-034.txt, 01-035.txt, 01-036.txt, 01-037.txt, 01-038.txt, 01-039.txt, 01-040.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00-sample-001.txt | AC | 6 ms | 2064 KiB |
| 00-sample-002.txt | AC | 2 ms | 2084 KiB |
| 00-sample-003.txt | AC | 1 ms | 2060 KiB |
| 01-001.txt | AC | 2 ms | 2436 KiB |
| 01-002.txt | AC | 4 ms | 2312 KiB |
| 01-003.txt | AC | 5 ms | 2276 KiB |
| 01-004.txt | AC | 2 ms | 2156 KiB |
| 01-005.txt | AC | 2 ms | 2096 KiB |
| 01-006.txt | AC | 3 ms | 2332 KiB |
| 01-007.txt | AC | 2 ms | 2296 KiB |
| 01-008.txt | AC | 3 ms | 2316 KiB |
| 01-009.txt | AC | 2 ms | 2236 KiB |
| 01-010.txt | AC | 3 ms | 2208 KiB |
| 01-011.txt | AC | 18 ms | 2372 KiB |
| 01-012.txt | AC | 9 ms | 2236 KiB |
| 01-013.txt | AC | 42 ms | 2656 KiB |
| 01-014.txt | AC | 20 ms | 2356 KiB |
| 01-015.txt | AC | 7 ms | 2204 KiB |
| 01-016.txt | AC | 34 ms | 2560 KiB |
| 01-017.txt | AC | 2 ms | 2124 KiB |
| 01-018.txt | AC | 3 ms | 2012 KiB |
| 01-019.txt | AC | 31 ms | 2588 KiB |
| 01-020.txt | AC | 5 ms | 2096 KiB |
| 01-021.txt | AC | 3 ms | 2440 KiB |
| 01-022.txt | AC | 3 ms | 2316 KiB |
| 01-023.txt | AC | 4 ms | 2244 KiB |
| 01-024.txt | AC | 4 ms | 2336 KiB |
| 01-025.txt | AC | 3 ms | 2412 KiB |
| 01-026.txt | AC | 3 ms | 2388 KiB |
| 01-027.txt | AC | 11 ms | 2300 KiB |
| 01-028.txt | AC | 4 ms | 2212 KiB |
| 01-029.txt | AC | 3 ms | 2344 KiB |
| 01-030.txt | AC | 4 ms | 2344 KiB |
| 01-031.txt | AC | 39 ms | 2620 KiB |
| 01-032.txt | AC | 37 ms | 2524 KiB |
| 01-033.txt | AC | 39 ms | 2652 KiB |
| 01-034.txt | AC | 36 ms | 2544 KiB |
| 01-035.txt | AC | 37 ms | 2596 KiB |
| 01-036.txt | AC | 38 ms | 2632 KiB |
| 01-037.txt | AC | 32 ms | 2504 KiB |
| 01-038.txt | AC | 40 ms | 2596 KiB |
| 01-039.txt | AC | 37 ms | 2644 KiB |
| 01-040.txt | AC | 36 ms | 2584 KiB |