Skip to content

Commit

Permalink
Add atcoder/abc380/a.rs atcoder/abc380/b.rs atcoder/abc380/c.rs atcod…
Browse files Browse the repository at this point in the history
…er/abc380/d.rs atcoder/abc380/remain.txt
  • Loading branch information
koba-e964 committed Nov 17, 2024
1 parent 324d28f commit c63378e
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 0 deletions.
11 changes: 11 additions & 0 deletions atcoder/abc380/a.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
fn getline() -> String {
let mut ret = String::new();
std::io::stdin().read_line(&mut ret).ok().unwrap();
ret
}

fn main() {
let mut s = getline().trim().bytes().collect::<Vec<_>>();
s.sort();
println!("{}", if s == b"122333" { "Yes" } else { "No" });
}
14 changes: 14 additions & 0 deletions atcoder/abc380/b.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
fn getline() -> String {
let mut ret = String::new();
std::io::stdin().read_line(&mut ret).ok().unwrap();
ret
}

fn main() {
let s = getline().trim().to_string();
let a = s.split("|").map(|x| x.len()).collect::<Vec<_>>();
for &a in &a[1..a.len() - 1] {
print!("{} ", a);
}
println!();
}
62 changes: 62 additions & 0 deletions atcoder/abc380/c.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
($($r:tt)*) => {
let stdin = std::io::stdin();
let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
let mut next = move || -> String{
bytes.by_ref().map(|r|r.unwrap() as char)
.skip_while(|c|c.is_whitespace())
.take_while(|c|!c.is_whitespace())
.collect()
};
input_inner!{next, $($r)*}
};
}

macro_rules! input_inner {
($next:expr) => {};
($next:expr,) => {};
($next:expr, $var:ident : $t:tt $($r:tt)*) => {
let $var = read_value!($next, $t);
input_inner!{$next $($r)*}
};
}

macro_rules! read_value {
($next:expr, chars) => {
read_value!($next, String).chars().collect::<Vec<char>>()
};
($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

// Tags: clustering, dedup
fn main() {
input! {
n: usize, k: usize,
s: chars,
}
let mut con = vec![];
let mut prev = 0;
for i in 0..n {
if s[i] == '1' {
if i > 0 && s[i - 1] == '0' {
prev = i;
}
} else {
if i >= prev + 1 {
con.push((prev, i));
}
prev = i + 1;
}
}
if s[n - 1] == '1' {
con.push((prev, n));
}
let mut s = s;
let (_, y) = con[k - 2];
let (z, w) = con[k - 1];
for i in z..w {
s.swap(i - z + y, i);
}
println!("{}", s.iter().collect::<String>());
}
64 changes: 64 additions & 0 deletions atcoder/abc380/d.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
($($r:tt)*) => {
let stdin = std::io::stdin();
let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
let mut next = move || -> String{
bytes.by_ref().map(|r|r.unwrap() as char)
.skip_while(|c|c.is_whitespace())
.take_while(|c|!c.is_whitespace())
.collect()
};
input_inner!{next, $($r)*}
};
}

macro_rules! input_inner {
($next:expr) => {};
($next:expr,) => {};
($next:expr, $var:ident : $t:tt $($r:tt)*) => {
let $var = read_value!($next, $t);
input_inner!{$next $($r)*}
};
}

macro_rules! read_value {
($next:expr, [ $t:tt ; $len:expr ]) => {
(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
};
($next:expr, chars) => {
read_value!($next, String).chars().collect::<Vec<char>>()
};
($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

fn main() {
let out = std::io::stdout();
let mut out = BufWriter::new(out.lock());
macro_rules! puts {($($format:tt)*) => (let _ = write!(out,$($format)*););}
macro_rules! putvec {
($v:expr) => {
for i in 0..$v.len() {
puts!("{}{}", $v[i], if i + 1 == $v.len() {"\n"} else {" "});
}
}
}
input! {
s: chars,
q: usize,
k: [i64; q],
}
let mut ans = vec![];
for k in k {
let k = k - 1;
let q = k / s.len() as i64;
let r = (k % s.len() as i64) as usize;
let mut cur = s[r];
if q.count_ones() % 2 == 1 {
cur = (cur as u8 ^ 0x20) as char;
}
ans.push(cur);
}
putvec!(ans);
}
3 changes: 3 additions & 0 deletions atcoder/abc380/remain.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
e
f
g

0 comments on commit c63378e

Please sign in to comment.