diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..a6b014e --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,2 @@ +[build] +target-dir = "target" diff --git a/atcoder/beginner_contests/249/a.cpp b/atcoder/beginner_contests/249/a.cpp new file mode 100644 index 0000000..0ed25e8 --- /dev/null +++ b/atcoder/beginner_contests/249/a.cpp @@ -0,0 +1,33 @@ +#include + +using namespace std; + + +int main(){ + ios::sync_with_stdio(0); + cin.tie(0); + + int a, b, c, d, e, f, x; + cin >> a >> b >> c >> d >> e >> f >> x; + + int t_loops = x / (a + c); + int a_loops = x / (d + f); + + int t_rest = x - t_loops * (a + c); + int a_rest = x - a_loops * (d + f); + + int taka = t_loops * b * a + b * min(t_rest, a); + int aoki = a_loops * e * d + e * min(a_rest, d); + + if(taka > aoki){ + cout << "Takahashi" << endl; + } else if(aoki > taka){ + cout << "Aoki" << endl; + } else{ + cout << "Draw" << endl; + } + + cout << flush; + + return 0; +} \ No newline at end of file diff --git a/atcoder/beginner_contests/249/b.cpp b/atcoder/beginner_contests/249/b.cpp new file mode 100644 index 0000000..edd124f --- /dev/null +++ b/atcoder/beginner_contests/249/b.cpp @@ -0,0 +1,40 @@ +#include + +using namespace std; + + +int main(){ + ios::sync_with_stdio(0); + cin.tie(0); + + string s; + cin >> s; + + set seen; + bool lower = false, upper = false; + + for(char c : s){ + if(isupper(c)){ + upper = true; + } + else if(islower(c)){ + lower = true; + } + + if(seen.count(c)){ + cout << "No" << endl; + return 0; + } + seen.insert(c); + } + + if(lower && upper){ + cout << "Yes" << endl; + } else{ + cout << "No" << endl; + } + + cout << flush; + + return 0; +} \ No newline at end of file diff --git a/atcoder/beginner_contests/249/c.cpp b/atcoder/beginner_contests/249/c.cpp new file mode 100644 index 0000000..c2dede1 --- /dev/null +++ b/atcoder/beginner_contests/249/c.cpp @@ -0,0 +1,19 @@ +#include + +using namespace std; + + +int main(){ + ios::sync_with_stdio(0); + cin.tie(0); + + int n, k; + + cin >> n >> k; + + vector> s; + + cout << flush; + + return 0; +} \ No newline at end of file diff --git a/atcoder/beginner_contests/249/d.cpp b/atcoder/beginner_contests/249/d.cpp new file mode 100644 index 0000000..0c03bec --- /dev/null +++ b/atcoder/beginner_contests/249/d.cpp @@ -0,0 +1,25 @@ +#include + +using namespace std; + +void test_case(int tc){ + +} + + + +int main(){ + ios::sync_with_stdio(0); + cin.tie(0); + + int t; + cin >> t; + + for(int tc = 1; tc <= t; ++tc){ + test_case(tc); + } + + cout << flush; + + return 0; +} \ No newline at end of file diff --git a/atcoder/beginner_contests/249/e.cpp b/atcoder/beginner_contests/249/e.cpp new file mode 100644 index 0000000..0c03bec --- /dev/null +++ b/atcoder/beginner_contests/249/e.cpp @@ -0,0 +1,25 @@ +#include + +using namespace std; + +void test_case(int tc){ + +} + + + +int main(){ + ios::sync_with_stdio(0); + cin.tie(0); + + int t; + cin >> t; + + for(int tc = 1; tc <= t; ++tc){ + test_case(tc); + } + + cout << flush; + + return 0; +} \ No newline at end of file diff --git a/atcoder/beginner_contests/249/ex.cpp b/atcoder/beginner_contests/249/ex.cpp new file mode 100644 index 0000000..0c03bec --- /dev/null +++ b/atcoder/beginner_contests/249/ex.cpp @@ -0,0 +1,25 @@ +#include + +using namespace std; + +void test_case(int tc){ + +} + + + +int main(){ + ios::sync_with_stdio(0); + cin.tie(0); + + int t; + cin >> t; + + for(int tc = 1; tc <= t; ++tc){ + test_case(tc); + } + + cout << flush; + + return 0; +} \ No newline at end of file diff --git a/atcoder/beginner_contests/249/f.cpp b/atcoder/beginner_contests/249/f.cpp new file mode 100644 index 0000000..0c03bec --- /dev/null +++ b/atcoder/beginner_contests/249/f.cpp @@ -0,0 +1,25 @@ +#include + +using namespace std; + +void test_case(int tc){ + +} + + + +int main(){ + ios::sync_with_stdio(0); + cin.tie(0); + + int t; + cin >> t; + + for(int tc = 1; tc <= t; ++tc){ + test_case(tc); + } + + cout << flush; + + return 0; +} \ No newline at end of file diff --git a/atcoder/beginner_contests/249/g.cpp b/atcoder/beginner_contests/249/g.cpp new file mode 100644 index 0000000..0c03bec --- /dev/null +++ b/atcoder/beginner_contests/249/g.cpp @@ -0,0 +1,25 @@ +#include + +using namespace std; + +void test_case(int tc){ + +} + + + +int main(){ + ios::sync_with_stdio(0); + cin.tie(0); + + int t; + cin >> t; + + for(int tc = 1; tc <= t; ++tc){ + test_case(tc); + } + + cout << flush; + + return 0; +} \ No newline at end of file diff --git a/atcoder/beginner_contests/abc042/Cargo.lock b/atcoder/beginner_contests/abc042/Cargo.lock new file mode 100644 index 0000000..1174a44 --- /dev/null +++ b/atcoder/beginner_contests/abc042/Cargo.lock @@ -0,0 +1,25 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "abc042" +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", +] diff --git a/atcoder/beginner_contests/abc042/Cargo.toml b/atcoder/beginner_contests/abc042/Cargo.toml new file mode 100644 index 0000000..00edab5 --- /dev/null +++ b/atcoder/beginner_contests/abc042/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "abc042" +version = "0.1.0" +edition = "2021" + +# dependencies added to new project +[dependencies] +proconio = "0.4.3" + +[profile.release] +lto = true +panic = 'abort' diff --git a/atcoder/beginner_contests/abc042/src/bin/a.rs b/atcoder/beginner_contests/abc042/src/bin/a.rs new file mode 100644 index 0000000..b81c519 --- /dev/null +++ b/atcoder/beginner_contests/abc042/src/bin/a.rs @@ -0,0 +1,11 @@ +use proconio::input; + +fn main() { + input!{ + mut abc: [u8; 3], + }; + abc.sort(); + let ans = abc == vec![5, 5, 7]; + + println!("{}", if ans {"YES"} else {"NO"}); +} diff --git a/atcoder/beginner_contests/abc042/src/bin/b.rs b/atcoder/beginner_contests/abc042/src/bin/b.rs new file mode 100644 index 0000000..8a97063 --- /dev/null +++ b/atcoder/beginner_contests/abc042/src/bin/b.rs @@ -0,0 +1,14 @@ +use proconio::input; + +fn main() { + input!{ + n: u8, + _l: u8, + mut s: [String; n], + }; + + s.sort(); + for substring in s { + print!("{}", substring); + } +} diff --git a/atcoder/beginner_contests/abc042/src/bin/c.rs b/atcoder/beginner_contests/abc042/src/bin/c.rs new file mode 100644 index 0000000..004dfe0 --- /dev/null +++ b/atcoder/beginner_contests/abc042/src/bin/c.rs @@ -0,0 +1,40 @@ +use proconio::input; + +fn check_number(n: u32, likes: &[bool; 10]) -> bool { + let mut result = true; + + let mut m = n; + while m > 0 { + let l = m % 10; + + if !likes[l as usize] { + result = false; + break; + } + + m /= 10; + } + + result +} + +fn main() { + input!{ + mut n: u32, + k: u32, + d: [u32; k], + }; + + let mut likes = [true; 10]; + for dislike in d { + likes[dislike as usize] = false; + } + + let mut check = false; + while !check { + check = check_number(n, &likes); + n += 1; + } + + print!("{}", n - 1); +} diff --git a/atcoder/beginner_contests/abc042/src/bin/d.rs b/atcoder/beginner_contests/abc042/src/bin/d.rs new file mode 100644 index 0000000..5de5197 --- /dev/null +++ b/atcoder/beginner_contests/abc042/src/bin/d.rs @@ -0,0 +1,43 @@ +use proconio::input; + +const MAX: u128 = u128::pow(10, 9) + 7; + +fn main() { + input!{ + h: u128, + w: u128, + a: u128, + b: u128, + }; + + // Ok it seems like this way is too naive for this problem and I actually have + // to do some magic with combinations or something else I haven't even thought of + + // But I don't think you can do combinations because you need to divide big numbers + // and you can't do that with modulo iirc + + let mut dp = vec![vec![0; w as usize]; h as usize]; + for i in 0..(h-a) { + dp[i as usize][0] = 1; + } + for j in 0..w { + dp[0][j as usize] = 1; + } + + for i in 1..h { + for j in 1..w { + if !(i >= h - a && j < b) { + dp[i as usize][j as usize] = (dp[(i - 1) as usize][j as usize] + dp[i as usize][(j - 1) as usize]) % MAX; + } + } + } + + // for row in &dp { + // for cell in row { + // print!("{} ", {cell}); + // } + // print!("\n"); + // } + + println!("{}", {dp[(h-1) as usize][(w-1) as usize]}); +} \ No newline at end of file diff --git a/atcoder/beginner_contests/abc043/Cargo.lock b/atcoder/beginner_contests/abc043/Cargo.lock new file mode 100644 index 0000000..9bfa4f3 --- /dev/null +++ b/atcoder/beginner_contests/abc043/Cargo.lock @@ -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", +] diff --git a/atcoder/beginner_contests/abc043/Cargo.toml b/atcoder/beginner_contests/abc043/Cargo.toml new file mode 100644 index 0000000..850bbbf --- /dev/null +++ b/atcoder/beginner_contests/abc043/Cargo.toml @@ -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' diff --git a/atcoder/beginner_contests/abc043/src/bin/a.rs b/atcoder/beginner_contests/abc043/src/bin/a.rs new file mode 100644 index 0000000..e169df4 --- /dev/null +++ b/atcoder/beginner_contests/abc043/src/bin/a.rs @@ -0,0 +1,11 @@ +use proconio::input; + +fn main() { + input!{ + n: u32, + }; + + let result = n * (n + 1) / 2; + + println!("{}", {result}); +} diff --git a/atcoder/beginner_contests/abc043/src/bin/b.rs b/atcoder/beginner_contests/abc043/src/bin/b.rs new file mode 100644 index 0000000..4110e51 --- /dev/null +++ b/atcoder/beginner_contests/abc043/src/bin/b.rs @@ -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}); +} diff --git a/atcoder/beginner_contests/abc043/src/bin/c.rs b/atcoder/beginner_contests/abc043/src/bin/c.rs new file mode 100644 index 0000000..c6efd2f --- /dev/null +++ b/atcoder/beginner_contests/abc043/src/bin/c.rs @@ -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}); +} diff --git a/atcoder/beginner_contests/abc043/src/bin/d.rs b/atcoder/beginner_contests/abc043/src/bin/d.rs new file mode 100644 index 0000000..0dd3e0c --- /dev/null +++ b/atcoder/beginner_contests/abc043/src/bin/d.rs @@ -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"); +} diff --git a/projecteuler/081/main.cpp b/projecteuler/081/main.cpp index c12afe4..fe56779 100644 --- a/projecteuler/081/main.cpp +++ b/projecteuler/081/main.cpp @@ -7,8 +7,51 @@ int main(){ cout << "Hello this is Patrick" << endl; auto start = chrono::high_resolution_clock::now(); - // Insert code here + // I imagine we have to do something with memoization, building up the cheapest path from + // the bottom right corner up to the top left corner + // First read the matrix file + + vector> matrix(80); + + ifstream matrixFile("matrix.txt"); + + for(int i = 0; i < 80; ++i){ + for(int j = 0; j < 80; ++j){ + int n; + matrixFile >> n; + + matrix[i].push_back(n); + + if(j != 79){ + char c; + matrixFile >> c; + } + } + } + + vector> dp(80); + for(int i = 0; i < 80; ++i){ + for(int j = 0; j < 80; ++j){ + dp[i].push_back(-1); + } + } + + dp[79][79] = matrix[79][79]; + for(int i = 78; i >= 0; --i){ + dp[i][79] = matrix[i][79] + dp[i+1][79]; + } + for(int j = 78; j >= 0; --j){ + dp[79][j] = matrix[79][j] + dp[79][j+1]; + } + + for(int i = 78; i >= 0; --i){ + for(int j = 78; j >= 0; --j){ + dp[i][j] = matrix[i][j] + min(dp[i+1][j], dp[i][j+1]); + } + } + + cout << dp[0][0] << endl; auto duration = chrono::duration_cast(chrono::high_resolution_clock::now() - start); cout << (float)duration.count()/1000 << endl; return 0;