Skip to content

Commit 2264d85

Browse files
committed
Solve A in agc039
1 parent 6caa0ba commit 2264d85

File tree

14 files changed

+1079
-0
lines changed

14 files changed

+1079
-0
lines changed

atcoder/rust/agc039/Cargo.lock

Lines changed: 638 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

atcoder/rust/agc039/Cargo.toml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
[package]
2+
name = "agc039"
3+
version = "0.1.0"
4+
authors = ["k-yomo <kanji.yy@gmail.com>"]
5+
edition = "2018"
6+
7+
[package.metadata.cargo-compete]
8+
config = "../compete.toml"
9+
10+
[package.metadata.cargo-compete.bin]
11+
a = { name = "agc039-a", problem = { platform = "atcoder", contest = "agc039", index = "A", url = "https://atcoder.jp/contests/agc039/tasks/agc039_a" } }
12+
b = { name = "agc039-b", problem = { platform = "atcoder", contest = "agc039", index = "B", url = "https://atcoder.jp/contests/agc039/tasks/agc039_b" } }
13+
c = { name = "agc039-c", problem = { platform = "atcoder", contest = "agc039", index = "C", url = "https://atcoder.jp/contests/agc039/tasks/agc039_c" } }
14+
d = { name = "agc039-d", problem = { platform = "atcoder", contest = "agc039", index = "D", url = "https://atcoder.jp/contests/agc039/tasks/agc039_d" } }
15+
e = { name = "agc039-e", problem = { platform = "atcoder", contest = "agc039", index = "E", url = "https://atcoder.jp/contests/agc039/tasks/agc039_e" } }
16+
f = { name = "agc039-f", problem = { platform = "atcoder", contest = "agc039", index = "F", url = "https://atcoder.jp/contests/agc039/tasks/agc039_f" } }
17+
18+
[[bin]]
19+
name = "agc039-a"
20+
path = "src/bin/a.rs"
21+
22+
[[bin]]
23+
name = "agc039-b"
24+
path = "src/bin/b.rs"
25+
26+
[[bin]]
27+
name = "agc039-c"
28+
path = "src/bin/c.rs"
29+
30+
[[bin]]
31+
name = "agc039-d"
32+
path = "src/bin/d.rs"
33+
34+
[[bin]]
35+
name = "agc039-e"
36+
path = "src/bin/e.rs"
37+
38+
[[bin]]
39+
name = "agc039-f"
40+
path = "src/bin/f.rs"
41+
[dependencies]
42+
num = "=0.2.1"
43+
num-bigint = "=0.2.6"
44+
num-complex = "=0.2.4"
45+
num-integer = "=0.1.42"
46+
num-iter = "=0.1.40"
47+
num-rational = "=0.2.4"
48+
num-traits = "=0.2.11"
49+
num-derive = "=0.3.0"
50+
ndarray = "=0.13.0"
51+
nalgebra = "=0.20.0"
52+
alga = "=0.9.3"
53+
libm = "=0.2.1"
54+
rand = { version = "=0.7.3", features = ["small_rng"] }
55+
getrandom = "=0.1.14"
56+
rand_chacha = "=0.2.2"
57+
rand_core = "=0.5.1"
58+
rand_hc = "=0.2.0"
59+
rand_pcg = "=0.2.1"
60+
rand_distr = "=0.2.2"
61+
petgraph = "=0.5.0"
62+
indexmap = "=1.3.2"
63+
regex = "=1.3.6"
64+
lazy_static = "=1.4.0"
65+
ordered-float = "=1.0.2"
66+
ascii = "=1.0.0"
67+
permutohedron = "=0.2.4"
68+
superslice = "=1.0.0"
69+
itertools = "=0.9.0"
70+
itertools-num = "=0.1.3"
71+
maplit = "=1.0.2"
72+
either = "=1.5.3"
73+
im-rc = "=14.3.0"
74+
fixedbitset = "=0.2.0"
75+
bitset-fixed = "=0.1.0"
76+
proconio = { version = "=0.3.6", features = ["derive"] }
77+
text_io = "=0.1.8"
78+
whiteread = "=0.5.0"
79+
rustc-hash = "=1.1.0"
80+
smallvec = "=1.2.0"

atcoder/rust/agc039/src/bin/a.rs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#![allow(unused_imports)]
2+
3+
use std::cmp::*;
4+
use std::collections::*;
5+
use std::io::Write;
6+
use std::ops::Bound::*;
7+
8+
use itertools::__std_iter::once;
9+
use itertools::*;
10+
use itertools_num::ItertoolsNum;
11+
use proconio::marker::*;
12+
use proconio::*;
13+
use superslice::*;
14+
15+
fn main() {
16+
input! {
17+
s: Chars,
18+
k: usize,
19+
}
20+
21+
if s.len() == 1 {
22+
return println!("{}", k / 2);
23+
}
24+
25+
let dup_counts = s
26+
.iter()
27+
.map(|c| (c, 1))
28+
.coalesce(|(prev_c, prev_dup), (cur_c, cur_dup)| {
29+
if prev_c == cur_c {
30+
Ok((prev_c, prev_dup + cur_dup))
31+
} else {
32+
Err(((prev_c, prev_dup), (cur_c, cur_dup)))
33+
}
34+
})
35+
.map(|(_, count)| count)
36+
.filter(|&count| count > 1)
37+
.collect::<Vec<usize>>();
38+
if dup_counts.len() == 1 {
39+
return println!("{}", s.len() * k / 2);
40+
} else {
41+
if s[0] == s[s.len() - 1] {
42+
let len = dup_counts.len();
43+
let mut dup_count = 0;
44+
dup_count += dup_counts[0] / 2;
45+
dup_count += dup_counts[len - 1] / 2;
46+
dup_count += (dup_counts[0] + dup_counts[len - 1]) / 2 * (k - 1);
47+
if len >= 3 {
48+
dup_count += dup_counts[1..(len - 1)]
49+
.iter()
50+
.map(|count| count / 2 * k)
51+
.sum::<usize>();
52+
}
53+
println!("{}", dup_count)
54+
} else {
55+
println!(
56+
"{}",
57+
dup_counts.iter().map(|count| count / 2 * k).sum::<usize>()
58+
)
59+
}
60+
}
61+
}

atcoder/rust/agc039/src/bin/b.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#![allow(unused_imports)]
2+
3+
use std::cmp::*;
4+
use std::collections::*;
5+
use std::io::Write;
6+
use std::ops::Bound::*;
7+
8+
use itertools::*;
9+
use itertools::__std_iter::once;
10+
use itertools_num::ItertoolsNum;
11+
use proconio::*;
12+
use proconio::marker::*;
13+
use superslice::*;
14+
15+
fn main() {
16+
input! {
17+
18+
}
19+
}

atcoder/rust/agc039/src/bin/c.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#![allow(unused_imports)]
2+
3+
use std::cmp::*;
4+
use std::collections::*;
5+
use std::io::Write;
6+
use std::ops::Bound::*;
7+
8+
use itertools::*;
9+
use itertools::__std_iter::once;
10+
use itertools_num::ItertoolsNum;
11+
use proconio::*;
12+
use proconio::marker::*;
13+
use superslice::*;
14+
15+
fn main() {
16+
input! {
17+
18+
}
19+
}

atcoder/rust/agc039/src/bin/d.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#![allow(unused_imports)]
2+
3+
use std::cmp::*;
4+
use std::collections::*;
5+
use std::io::Write;
6+
use std::ops::Bound::*;
7+
8+
use itertools::*;
9+
use itertools::__std_iter::once;
10+
use itertools_num::ItertoolsNum;
11+
use proconio::*;
12+
use proconio::marker::*;
13+
use superslice::*;
14+
15+
fn main() {
16+
input! {
17+
18+
}
19+
}

atcoder/rust/agc039/src/bin/e.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#![allow(unused_imports)]
2+
3+
use std::cmp::*;
4+
use std::collections::*;
5+
use std::io::Write;
6+
use std::ops::Bound::*;
7+
8+
use itertools::*;
9+
use itertools::__std_iter::once;
10+
use itertools_num::ItertoolsNum;
11+
use proconio::*;
12+
use proconio::marker::*;
13+
use superslice::*;
14+
15+
fn main() {
16+
input! {
17+
18+
}
19+
}

atcoder/rust/agc039/src/bin/f.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#![allow(unused_imports)]
2+
3+
use std::cmp::*;
4+
use std::collections::*;
5+
use std::io::Write;
6+
use std::ops::Bound::*;
7+
8+
use itertools::*;
9+
use itertools::__std_iter::once;
10+
use itertools_num::ItertoolsNum;
11+
use proconio::*;
12+
use proconio::marker::*;
13+
use superslice::*;
14+
15+
fn main() {
16+
input! {
17+
18+
}
19+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
type: Batch
3+
timelimit: 2s
4+
match: Lines
5+
6+
cases:
7+
- name: sample1
8+
in: |
9+
issii
10+
2
11+
out: |
12+
4
13+
- name: sample2
14+
in: |
15+
qq
16+
81
17+
out: |
18+
81
19+
- name: sample3
20+
in: |
21+
cooooooooonteeeeeeeeeest
22+
999993333
23+
out: |
24+
8999939997
25+
26+
extend: []
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
type: Batch
3+
timelimit: 2s
4+
match: Lines
5+
6+
cases:
7+
- name: sample1
8+
in: |
9+
2
10+
01
11+
10
12+
out: |
13+
2
14+
- name: sample2
15+
in: |
16+
3
17+
011
18+
101
19+
110
20+
out: |
21+
-1
22+
- name: sample3
23+
in: |
24+
6
25+
010110
26+
101001
27+
010100
28+
101000
29+
100000
30+
010000
31+
out: |
32+
4
33+
34+
extend: []

0 commit comments

Comments
 (0)