Submission #2532045
Source Code Expand
fn main() { let mut sc = Scanner::new(); let a: Vec<usize> = sc.read::<String>() .chars() .map(|c| (c as usize) - ('a' as usize)) .collect(); let mut pos = vec![vec![]; 26]; let n = a.len(); for i in 0..n { pos[a[i]].push(i + 1); } let mut k = vec![0; n + 2]; let mut vis = vec![false; 26]; for i in (0..n).rev() { let j = i + 1; vis[a[i]] = true; let mut ok = true; for &b in &vis { ok = ok && b; } if ok { for i in 0..vis.len() { vis[i] = false; } k[j - 1] = k[j] + 1; } else { k[j - 1] = k[j]; } } let mut cur_pos = 0; let mut ans: Vec<usize> = Vec::new(); for _ in 0..(k[0] + 1) { for c in 0..26 { let p: usize = match pos[c].binary_search(&(cur_pos + 1)) { Ok(p) => pos[c][p], Err(p) => if p < pos[c].len() { pos[c][p] } else { n }, }; if p == n || k[cur_pos] == k[p] + 1 { cur_pos = p; ans.push(c); break; } } } for &a in &ans { let c = ((a as u8) + ('a' as u8)) as char; print!("{}", c); } println!(); } struct Scanner { ptr: usize, length: usize, buf: Vec<u8>, small_cache: Vec<u8>, } impl Scanner { fn new() -> Scanner { Scanner { ptr: 0, length: 0, buf: vec![0; 1024], small_cache: vec![0; 1024], } } fn load(&mut self) { use std::io::Read; let mut s = std::io::stdin(); self.length = s.read(&mut self.buf).unwrap(); } fn byte(&mut self) -> u8 { if self.ptr >= self.length { self.ptr = 0; self.load(); if self.length == 0 { self.buf[0] = b'\n'; self.length = 1; } } self.ptr += 1; return self.buf[self.ptr - 1]; } fn is_space(b: u8) -> bool { b == b'\n' || b == b'\r' || b == b'\t' || b == b' ' } fn read<T>(&mut self) -> T where T: std::str::FromStr, T::Err: std::fmt::Debug, { let mut b = self.byte(); while Scanner::is_space(b) { b = self.byte(); } for pos in 0..self.small_cache.len() { self.small_cache[pos] = b; b = self.byte(); if Scanner::is_space(b) { return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)]) .parse() .unwrap(); } } let mut v = self.small_cache.clone(); while !Scanner::is_space(b) { v.push(b); b = self.byte(); } return String::from_utf8_lossy(&v).parse().unwrap(); } }
Submission Info
Submission Time | |
---|---|
Task | E - Don't Be a Subsequence |
User | kenkoooo |
Language | Rust (1.15.1) |
Score | 600 |
Code Size | 3131 Byte |
Status | AC |
Exec Time | 17 ms |
Memory | 10492 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 600 / 600 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample1.txt, sample2.txt, sample3.txt |
All | sample1.txt, sample2.txt, sample3.txt, 1.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 2.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 3.txt, 30.txt, 4.txt, 5.txt, 6.txt, 7.txt, 8.txt, 9.txt, sample1.txt, sample2.txt, sample3.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
1.txt | AC | 2 ms | 4352 KB |
10.txt | AC | 15 ms | 10492 KB |
11.txt | AC | 15 ms | 10492 KB |
12.txt | AC | 15 ms | 10492 KB |
13.txt | AC | 15 ms | 10492 KB |
14.txt | AC | 15 ms | 10492 KB |
15.txt | AC | 17 ms | 10492 KB |
16.txt | AC | 15 ms | 10492 KB |
17.txt | AC | 15 ms | 10492 KB |
18.txt | AC | 15 ms | 10492 KB |
19.txt | AC | 15 ms | 10492 KB |
2.txt | AC | 2 ms | 4352 KB |
20.txt | AC | 15 ms | 10492 KB |
21.txt | AC | 15 ms | 10492 KB |
22.txt | AC | 15 ms | 10492 KB |
23.txt | AC | 15 ms | 10492 KB |
24.txt | AC | 14 ms | 10492 KB |
25.txt | AC | 13 ms | 10492 KB |
26.txt | AC | 13 ms | 10492 KB |
27.txt | AC | 13 ms | 10492 KB |
28.txt | AC | 13 ms | 10492 KB |
29.txt | AC | 13 ms | 10492 KB |
3.txt | AC | 2 ms | 4352 KB |
30.txt | AC | 13 ms | 10492 KB |
4.txt | AC | 2 ms | 4352 KB |
5.txt | AC | 8 ms | 6396 KB |
6.txt | AC | 8 ms | 6396 KB |
7.txt | AC | 15 ms | 10492 KB |
8.txt | AC | 15 ms | 10492 KB |
9.txt | AC | 15 ms | 10492 KB |
sample1.txt | AC | 2 ms | 4352 KB |
sample2.txt | AC | 2 ms | 4352 KB |
sample3.txt | AC | 2 ms | 4352 KB |