Skip to content

Commit

Permalink
agc023 a, b
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Jun 21, 2021
1 parent 5f7f0c9 commit 9e06c09
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 28 deletions.
88 changes: 86 additions & 2 deletions agc023/Cargo.lock

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

1 change: 1 addition & 0 deletions agc023/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition = "2018"

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

Expand Down
33 changes: 19 additions & 14 deletions agc023/src/bin/a.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
use std::collections::BTreeMap;

use proconio::input;

fn cumsum(a: &[i64]) -> Vec<i64> {
std::iter::once(0)
.chain(a.iter().scan(0, |acc, &i| {
*acc += i;
Some(*acc)
}))
.collect()
}

fn main() {
input! {
n: usize,
a: [i64; n],
};
let s = std::iter::once(0)
.chain(a.iter().scan(0, |acc, &a_i| {
*acc += a_i;
Some(*acc)
}))
.collect::<Vec<i64>>();
let mut m = std::collections::BTreeMap::new();
let s = cumsum(&a);
let mut map = BTreeMap::new();
for &s_i in s.iter() {
let entry = m.entry(s_i).or_insert(0);
*entry += 1;
*map.entry(s_i).or_insert(0) += 1;
}
let mut count = 0_usize;
for (_, v) in map {
count += v * (v - 1) / 2;
}
let ans = m
.values()
.filter(|&&v| v >= 2)
.map(|&v| v * (v - 1) / 2)
.sum::<i64>();
let ans = count;
println!("{}", ans);
}
28 changes: 24 additions & 4 deletions agc023/src/bin/b.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
use proconio::input;
use proconio::marker::Usize1;
use proconio::{input, marker::Chars};

fn main() {
input! {
n: usize,
a: [Usize1; n],
s: [Chars; n],
};
let ans = n - a.len();
let mut count = 0;
for a in 0..n {
let b = 0;
let mut t = vec![vec![' '; n]; n];
for i in 0..n {
for j in 0..n {
t[i][j] = s[(i + a) % n][(j + b) % n];
}
}
let mut ok = true;
for i in 0..n {
for j in 0..n {
if t[i][j] != t[j][i] {
ok = false;
}
}
}
if ok {
count += 1;
}
}
let ans = count * n;
println!("{}", ans);
}
3 changes: 1 addition & 2 deletions agc023/src/bin/c.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use proconio::input;
use proconio::marker::Usize1;
use proconio::{input, marker::Usize1};

fn main() {
input! {
Expand Down
3 changes: 1 addition & 2 deletions agc023/src/bin/d.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use proconio::input;
use proconio::marker::Usize1;
use proconio::{input, marker::Usize1};

fn main() {
input! {
Expand Down
3 changes: 1 addition & 2 deletions agc023/src/bin/e.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use proconio::input;
use proconio::marker::Usize1;
use proconio::{input, marker::Usize1};

fn main() {
input! {
Expand Down
3 changes: 1 addition & 2 deletions agc023/src/bin/f.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use proconio::input;
use proconio::marker::Usize1;
use proconio::{input, marker::Usize1};

fn main() {
input! {
Expand Down

0 comments on commit 9e06c09

Please sign in to comment.