Skip to content

Commit

Permalink
abc344 a, b, c, d, e
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Mar 9, 2024
1 parent 6c8488b commit 5f1e0b0
Show file tree
Hide file tree
Showing 10 changed files with 400 additions and 0 deletions.
168 changes: 168 additions & 0 deletions cargo-atcoder-1.70.0/contests/abc344/Cargo.lock

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

15 changes: 15 additions & 0 deletions cargo-atcoder-1.70.0/contests/abc344/Cargo.toml
@@ -0,0 +1,15 @@
[package]
name = "abc344"
version = "0.1.0"
edition = "2021"

# dependencies added to new project
[dependencies]
ac-library-rs = "=0.1.1"
num = "=0.4.0"
proconio = { version = "=0.4.3", features = ["derive"] }
superslice = "=1.0.0"

[profile.release]
lto = true
panic = 'abort'
1 change: 1 addition & 0 deletions cargo-atcoder-1.70.0/contests/abc344/rust-toolchain
@@ -0,0 +1 @@
1.70.0
26 changes: 26 additions & 0 deletions cargo-atcoder-1.70.0/contests/abc344/src/bin/a.rs
@@ -0,0 +1,26 @@
use proconio::{input, marker::Chars};

fn main() {
input! {
s: Chars,
};
let mut in_pipe = false;
let mut ans = vec![];
for c in s {
if !in_pipe {
if c == '|' {
in_pipe = true;
} else {
ans.push(c);
}
} else {
if c == '|' {
in_pipe = false;
} else {
// do nothing
}
}
}
let ans = ans.into_iter().collect::<String>();
println!("{}", ans);
}
19 changes: 19 additions & 0 deletions cargo-atcoder-1.70.0/contests/abc344/src/bin/b.rs
@@ -0,0 +1,19 @@
use proconio::input;

fn main() {
let mut ans = vec![];
loop {
input! {
a_i: usize
}

ans.push(a_i);
if a_i == 0 {
break;
}
}
ans.reverse();
for a in ans {
println!("{}", a);
}
}
29 changes: 29 additions & 0 deletions cargo-atcoder-1.70.0/contests/abc344/src/bin/c.rs
@@ -0,0 +1,29 @@
use std::collections::HashSet;

use proconio::input;

fn main() {
input! {
n: usize,
a: [usize; n],
m: usize,
b: [usize; m],
l: usize,
c: [usize; l],
q: usize,
x: [usize; q],
};

let mut set = HashSet::new();
for a_i in a.iter().copied() {
for b_i in b.iter().copied() {
for c_i in c.iter().copied() {
set.insert(a_i + b_i + c_i);
}
}
}
for x_i in x {
let ans = set.contains(&x_i);
println!("{}", if ans { "Yes" } else { "No" });
}
}
41 changes: 41 additions & 0 deletions cargo-atcoder-1.70.0/contests/abc344/src/bin/d.rs
@@ -0,0 +1,41 @@
use std::collections::BTreeMap;

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

fn main() {
input! {
t: Chars,
n: usize,
};

let mut s = vec![];
for _ in 0..n {
input! {
a_i: usize,
s_i: [Chars; a_i],
}
s.push(s_i);
}

let mut map = BTreeMap::new();
map.insert(0_usize, 0_usize);
for s_i in s {
let mut next = map.clone();
for (x, min_x) in map {
for s_ij in s_i.iter() {
if x + s_ij.len() > t.len() {
continue;
}
if s_ij == &t[x..x + s_ij.len()] {
let entry = next.entry(x + s_ij.len()).or_insert(min_x + 1);
*entry = (*entry).min(min_x + 1);
}
}
}
map = next;
}
match map.get(&t.len()) {
Some(x) => println!("{}", x),
None => println!("-1"),
}
}
81 changes: 81 additions & 0 deletions cargo-atcoder-1.70.0/contests/abc344/src/bin/e.rs
@@ -0,0 +1,81 @@
use std::collections::HashMap;

use proconio::input;

fn main() {
input! {
n: usize,
a: [usize; n],
q: usize,
};

let mut query = vec![];
for _ in 0..q {
input! {
t: usize,
}
match t {
1 => {
input! {
x: usize,
y: usize,
}
query.push((t, x, y));
}
2 => {
input! {
x: usize,
}
query.push((t, x, 0));
}
_ => unreachable!(),
}
}

let mut next = HashMap::new();
let mut prev = HashMap::new();
for i in 0..n - 1 {
let a_i = a[i];
let a_j = a[i + 1];
next.entry(a_i).or_insert(a_j);
prev.entry(a_j).or_insert(a_i);
}

let head = 0_usize;
let tail = 1 << 60_usize;
next.insert(head, a[0]);
prev.insert(a[0], head);
next.insert(a[n - 1], tail);
prev.insert(tail, a[n - 1]);

for (t, x, y) in query {
match t {
1 => {
// x -> next_x
// => x -> y -> next_x
let next_x = *next.get(&x).unwrap();
next.insert(x, y);
next.insert(y, next_x);
prev.insert(y, x);
prev.insert(next_x, y);
}
2 => {
// prev_x -> x -> next_x
// => prev_x -> next_x
let prev_x = *prev.get(&x).unwrap();
let next_x = *next.get(&x).unwrap();
next.insert(prev_x, next_x);
prev.insert(next_x, prev_x);
next.remove(&x);
prev.remove(&x);
}
_ => unreachable!(),
}
}

let mut cur = next[&head];
while cur != tail {
println!("{}", cur);
cur = next[&cur];
}
}
10 changes: 10 additions & 0 deletions cargo-atcoder-1.70.0/contests/abc344/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 5f1e0b0

Please sign in to comment.