use proconio::{fastout, input, marker::Bytes}; #[fastout] fn main() { input! { n: usize, m: usize, s: [Bytes; n], } println!("{}", output(solve(n, m, s))); } fn solve(n: usize, m: usize, mut s: Vec>) -> Option { let mut ans = String::with_capacity(m); for i in 0..m { let mut count_g = 0; let mut count_c = 0; let mut count_p = 0; for j in 0..n { match s[j].get(i) { Some(b'G') => count_g += 1, Some(b'C') => count_c += 1, Some(b'P') => count_p += 1, _ => (), }; } let (count_g, count_c, count_p) = (count_g, count_c, count_p); if count_g == 0 { if count_p == 0 { ans.push_str(&String::from("G").repeat(m - i)); return Some(ans); } if count_c == 0 { ans.push_str(&String::from("C").repeat(m - i)); return Some(ans); } ans.push('C'); for j in 0..n { match s[j].get(i) { Some(b'P') => s[j].clear(), _ => (), } } } else if count_c == 0 { if count_g == 0 { ans.push_str(&String::from("C").repeat(m - i)); return Some(ans); } if count_p == 0 { ans.push_str(&String::from("P").repeat(m - i)); return Some(ans); } ans.push('P'); for j in 0..n { match s[j].get(i) { Some(b'G') => s[j].clear(), _ => (), } } } else if count_p == 0 { if count_c == 0 { ans.push_str(&String::from("P").repeat(m - i)); return Some(ans); } if count_g == 0 { ans.push_str(&String::from("G").repeat(m - i)); } ans.push('G'); for j in 0..n { match s[j].get(i) { Some(b'C') => s[j].clear(), _ => (), } } } } None } fn output(ans: Option) -> String { match ans { Some(s) => s, None => String::from("-1"), } }