Skip to content

Commit

Permalink
abc272 a, b, c, d
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Oct 8, 2022
1 parent 1b0eeed commit 11befa9
Show file tree
Hide file tree
Showing 11 changed files with 361 additions and 0 deletions.
161 changes: 161 additions & 0 deletions abc272/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 abc272/Cargo.toml
@@ -0,0 +1,14 @@
[package]
name = "abc272"
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 abc272/rust-toolchain
@@ -0,0 +1 @@
1.42.0
10 changes: 10 additions & 0 deletions abc272/src/bin/a.rs
@@ -0,0 +1,10 @@
use proconio::input;

fn main() {
input! {
n: usize,
a: [usize; n],
};
let ans = a.iter().sum::<usize>();
println!("{}", ans);
}
38 changes: 38 additions & 0 deletions abc272/src/bin/b.rs
@@ -0,0 +1,38 @@
use std::collections::HashSet;

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

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

let mut x = vec![];
for _ in 0..m {
input! {
k_i: usize,
x_i: [Usize1; k_i]
}
x.push(x_i);
}

let mut set = HashSet::new();
for x_i in x {
for j1 in 0..x_i.len() {
for j2 in j1 + 1..x_i.len() {
set.insert((x_i[j1], x_i[j2]));
}
}
}

for i in 0..n {
for j in i + 1..n {
if !set.contains(&(i, j)) {
println!("No");
return;
}
}
}
println!("Yes");
}
38 changes: 38 additions & 0 deletions abc272/src/bin/c.rs
@@ -0,0 +1,38 @@
use proconio::input;

fn main() {
input! {
n: usize,
a: [i64; n],
};
let mut e = a
.iter()
.copied()
.filter(|a_i| a_i % 2 == 0)
.collect::<Vec<i64>>();
let mut o = a
.iter()
.copied()
.filter(|a_i| a_i % 2 != 0)
.collect::<Vec<i64>>();
if e.len() <= 1 && o.len() <= 1 {
println!("-1");
return;
}
e.sort();
o.sort();

let esum = if e.len() >= 2 {
e[e.len() - 1] + e[e.len() - 2]
} else {
-1
};
let osum = if o.len() >= 2 {
o[o.len() - 1] + o[o.len() - 2]
} else {
-1
};

let ans = esum.max(osum);
println!("{}", ans);
}
59 changes: 59 additions & 0 deletions abc272/src/bin/d.rs
@@ -0,0 +1,59 @@
use std::{cmp::Reverse, collections::BinaryHeap};

use proconio::input;

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

let mut dij = vec![];
for i in -(n as i64)..=(n as i64) {
for j in -(n as i64)..=(n as i64) {
if (i.pow(2) + j.pow(2)) as usize == m {
dij.push((i, j));
}
}
}

let inf = 1_usize << 60;
let mut dist = vec![vec![inf; n]; n];
dist[0][0] = 0_usize;
let mut pq = BinaryHeap::new();
pq.push((Reverse(0_usize), (0_usize, 0_usize)));
while let Some((Reverse(d), (r, c))) = pq.pop() {
if d != dist[r][c] {
continue;
}
let nd = d + 1;
for (di, dj) in dij.iter().copied() {
let (nr, nc) = (r as i64 + di, c as i64 + dj);
if !(0..n as i64).contains(&nr) || !(0..n as i64).contains(&nc) {
continue;
}
if ((r as i64 - nr).pow(2) + (c as i64 - nc).pow(2)) as usize != m {
continue;
}
let (nr, nc) = (nr as usize, nc as usize);
if nd < dist[nr][nc] {
dist[nr][nc] = nd;
pq.push((Reverse(nd), (nr, nc)));
}
}
}

for i in 0..n {
for j in 0..n {
print!(
"{}{}",
if dist[i][j] == inf {
-1
} else {
dist[i][j] as i64
},
if j == n - 1 { '\n' } else { ' ' }
);
}
}
}
10 changes: 10 additions & 0 deletions abc272/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 abc272/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 abc272/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);
}
10 changes: 10 additions & 0 deletions abc272/src/bin/g.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 11befa9

Please sign in to comment.