Skip to content

Commit

Permalink
abc273 a, b, c, d
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Oct 15, 2022
1 parent 3b7faa3 commit 208442d
Show file tree
Hide file tree
Showing 11 changed files with 390 additions and 0 deletions.
161 changes: 161 additions & 0 deletions abc273/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions abc273/Cargo.toml
@@ -0,0 +1,14 @@
[package]
name = "abc273"
version = "0.1.0"
edition = "2018"

# dependencies added to new project
[dependencies]
num = "=0.2.1"
proconio = { version = "=0.3.6", features = ["derive"] }
superslice = "=1.0.0"

[profile.release]
lto = true
panic = 'abort'
1 change: 1 addition & 0 deletions abc273/rust-toolchain
@@ -0,0 +1 @@
1.42.0
17 changes: 17 additions & 0 deletions abc273/src/bin/a.rs
@@ -0,0 +1,17 @@
use proconio::input;

fn f(n: usize) -> usize {
if n == 0 {
1
} else {
n * f(n - 1)
}
}

fn main() {
input! {
n: usize,
};
let ans = f(n);
println!("{}", ans);
}
33 changes: 33 additions & 0 deletions abc273/src/bin/b.rs
@@ -0,0 +1,33 @@
use proconio::{input, marker::Chars};

fn main() {
input! {
mut x: Chars,
k: usize,
};
x.reverse();
let mut c = 0_usize;
let mut ans = vec![];
for (i, x_i) in x.iter().copied().enumerate() {
let d = (x_i as u8 - b'0') as usize + c;
if i < k {
ans.push('0');
if d <= 4 {
c = 0;
} else {
c = 1;
}
} else {
ans.push(((d % 10) as u8 + b'0') as char);
c = d / 10;
}
}
if c > 0 && k <= x.len() {
ans.push('1');
}
ans.reverse();
println!(
"{}",
ans.iter().collect::<String>().parse::<usize>().unwrap()
);
}
25 changes: 25 additions & 0 deletions abc273/src/bin/c.rs
@@ -0,0 +1,25 @@
use std::collections::{BTreeSet, HashMap};

use proconio::input;
use superslice::Ext;

fn main() {
input! {
n: usize,
a: [usize; n],
};
let set = a
.iter()
.copied()
.collect::<BTreeSet<usize>>()
.into_iter()
.collect::<Vec<usize>>();
let mut map = HashMap::new();
for a_i in a {
let count = set.len() - 1 - set.lower_bound(&a_i);
*map.entry(count).or_insert(0) += 1;
}
for i in 0..n {
println!("{}", map.get(&i).unwrap_or(&0));
}
}
99 changes: 99 additions & 0 deletions abc273/src/bin/d.rs
@@ -0,0 +1,99 @@
use std::collections::{BTreeSet, HashMap};

use proconio::{input, marker::Usize1};

fn main() {
input! {
h: usize,
w: usize,
r_s: Usize1,
c_s: Usize1,
n: usize,
rc: [(Usize1, Usize1); n],
q: usize,
dl: [(char, usize); q],
};

let mut rs = HashMap::new();
for (r, c) in rc.iter().copied() {
rs.entry(r).or_insert_with(BTreeSet::new).insert(c);
}
let mut cs = HashMap::new();
for (r, c) in rc.iter().copied() {
cs.entry(c).or_insert_with(BTreeSet::new).insert(r);
}

let mut cr = r_s;
let mut cc = c_s;
for (d, l) in dl {
match d {
'L' => {
let mut nc = if (0..w as i64).contains(&(cc as i64 - l as i64)) {
cc - l
} else {
0
};
if nc < cc {
if let Some(c) = rs
.get(&cr)
.and_then(|rs_cs| rs_cs.range(nc..cc).rev().next())
{
nc = *c + 1;
}
}
cc = nc;
}
'R' => {
let mut nc = if (0..w as i64).contains(&(cc as i64 + l as i64)) {
cc + l
} else {
w - 1
};
if cc + 1 <= nc {
if let Some(c) = rs
.get(&cr)
.and_then(|rs_cs| rs_cs.range(cc + 1..=nc).next())
{
nc = *c - 1;
}
}
cc = nc;
}
'U' => {
let mut nr = if (0..h as i64).contains(&(cr as i64 - l as i64)) {
cr - l
} else {
0
};
if nr < cr {
if let Some(r) = cs
.get(&cc)
.and_then(|rs_cs| rs_cs.range(nr..cr).rev().next())
{
nr = *r + 1;
}
}
cr = nr;
}
'D' => {
let mut nr = if (0..h as i64).contains(&(cr as i64 + l as i64)) {
cr + l
} else {
h - 1
};
if cr + 1 <= nr {
if let Some(r) = cs
.get(&cc)
.and_then(|rs_cs| rs_cs.range(cr + 1..=nr).next())
{
nr = *r - 1;
}
}
cr = nr;
}
_ => unreachable!(),
}

println!("{} {}", cr + 1, cc + 1);
}
}
10 changes: 10 additions & 0 deletions abc273/src/bin/e.rs
@@ -0,0 +1,10 @@
use proconio::{input, marker::Usize1};

fn main() {
input! {
n: usize,
a: [Usize1; n],
};
let ans = n - a.len();
println!("{}", ans);
}
10 changes: 10 additions & 0 deletions abc273/src/bin/ex.rs
@@ -0,0 +1,10 @@
use proconio::{input, marker::Usize1};

fn main() {
input! {
n: usize,
a: [Usize1; n],
};
let ans = n - a.len();
println!("{}", ans);
}
10 changes: 10 additions & 0 deletions abc273/src/bin/f.rs
@@ -0,0 +1,10 @@
use proconio::{input, marker::Usize1};

fn main() {
input! {
n: usize,
a: [Usize1; n],
};
let ans = n - a.len();
println!("{}", ans);
}

0 comments on commit 208442d

Please sign in to comment.