AC043 in rust, finished all. (D doesn't get tested correctly locally)
This commit is contained in:
25
atcoder/beginner_contests/abc043/Cargo.lock
generated
Normal file
25
atcoder/beginner_contests/abc043/Cargo.lock
generated
Normal file
@@ -0,0 +1,25 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "abc043"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"proconio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||
|
||||
[[package]]
|
||||
name = "proconio"
|
||||
version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "91c333be3af2936f8e810300bc74fe4d0cc168ebc04ab02a28c5b1060fa1bd59"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
]
|
||||
12
atcoder/beginner_contests/abc043/Cargo.toml
Normal file
12
atcoder/beginner_contests/abc043/Cargo.toml
Normal file
@@ -0,0 +1,12 @@
|
||||
[package]
|
||||
name = "abc043"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# dependencies added to new project
|
||||
[dependencies]
|
||||
proconio = "0.4.3"
|
||||
|
||||
[profile.release]
|
||||
lto = true
|
||||
panic = 'abort'
|
||||
11
atcoder/beginner_contests/abc043/src/bin/a.rs
Normal file
11
atcoder/beginner_contests/abc043/src/bin/a.rs
Normal file
@@ -0,0 +1,11 @@
|
||||
use proconio::input;
|
||||
|
||||
fn main() {
|
||||
input!{
|
||||
n: u32,
|
||||
};
|
||||
|
||||
let result = n * (n + 1) / 2;
|
||||
|
||||
println!("{}", {result});
|
||||
}
|
||||
21
atcoder/beginner_contests/abc043/src/bin/b.rs
Normal file
21
atcoder/beginner_contests/abc043/src/bin/b.rs
Normal file
@@ -0,0 +1,21 @@
|
||||
use proconio::input;
|
||||
|
||||
fn main() {
|
||||
input!{
|
||||
s: String,
|
||||
};
|
||||
|
||||
let mut result = String::new();
|
||||
|
||||
for c in s.chars() {
|
||||
if c == '0' {
|
||||
result.push('0');
|
||||
} else if c == '1' {
|
||||
result.push('1');
|
||||
} else {
|
||||
result.pop();
|
||||
}
|
||||
}
|
||||
|
||||
println!("{}", {result});
|
||||
}
|
||||
28
atcoder/beginner_contests/abc043/src/bin/c.rs
Normal file
28
atcoder/beginner_contests/abc043/src/bin/c.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
use proconio::input;
|
||||
|
||||
fn cost(target: i32, numbers: &[i32]) -> i32 {
|
||||
let mut result = 0;
|
||||
|
||||
for n in numbers {
|
||||
result += (target - n) * (target - n)
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
fn main() {
|
||||
input!{
|
||||
n: i32,
|
||||
a: [i32; n],
|
||||
};
|
||||
|
||||
let mut min = std::i32::MAX;
|
||||
for t in -100..=100 {
|
||||
let r = cost(t, &a);
|
||||
if r < min {
|
||||
min = r;
|
||||
}
|
||||
}
|
||||
|
||||
println!("{}", {min});
|
||||
}
|
||||
44
atcoder/beginner_contests/abc043/src/bin/d.rs
Normal file
44
atcoder/beginner_contests/abc043/src/bin/d.rs
Normal file
@@ -0,0 +1,44 @@
|
||||
use proconio::input;
|
||||
|
||||
fn main() {
|
||||
input!{
|
||||
s: String,
|
||||
};
|
||||
|
||||
let mut cs = s.chars();
|
||||
let l = s.len();
|
||||
|
||||
if l == 2 {
|
||||
let a = cs.next().unwrap();
|
||||
let b = cs.next().unwrap();
|
||||
|
||||
if a == b {
|
||||
println!("1 2");
|
||||
} else{
|
||||
println!("-1 -1");
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
let mut past_chars = [' '; 3];
|
||||
past_chars[1] = cs.next().unwrap();
|
||||
past_chars[2] = cs.next().unwrap();
|
||||
|
||||
for i in 2..l {
|
||||
past_chars[0] = past_chars[1];
|
||||
past_chars[1] = past_chars[2];
|
||||
past_chars[2] = cs.next().unwrap();
|
||||
|
||||
let mut sorting = [' '; 3];
|
||||
sorting.copy_from_slice(&past_chars);
|
||||
sorting.sort();
|
||||
|
||||
if sorting[0] == sorting[1] || sorting[1] == sorting[2] {
|
||||
println!("{} {}", {i-1}, {i+1});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
println!("-1 -1");
|
||||
}
|
||||
Reference in New Issue
Block a user