Merge branch 'master' of ssh://git.pzwietering.nl:55555/flip/contests

This commit is contained in:
2022-05-29 16:23:38 +02:00
22 changed files with 549 additions and 1 deletions

2
.cargo/config.toml Normal file
View File

@@ -0,0 +1,2 @@
[build]
target-dir = "target"

View File

@@ -0,0 +1,33 @@
#include <bits/stdc++.h>
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;
}

View File

@@ -0,0 +1,40 @@
#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
string s;
cin >> s;
set<char> 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;
}

View File

@@ -0,0 +1,19 @@
#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n, k;
cin >> n >> k;
vector<map<char, int>> s;
cout << flush;
return 0;
}

View File

@@ -0,0 +1,25 @@
#include <bits/stdc++.h>
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;
}

View File

@@ -0,0 +1,25 @@
#include <bits/stdc++.h>
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;
}

View File

@@ -0,0 +1,25 @@
#include <bits/stdc++.h>
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;
}

View File

@@ -0,0 +1,25 @@
#include <bits/stdc++.h>
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;
}

View File

@@ -0,0 +1,25 @@
#include <bits/stdc++.h>
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;
}

View File

@@ -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",
]

View File

@@ -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'

View File

@@ -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"});
}

View File

@@ -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);
}
}

View File

@@ -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);
}

View File

@@ -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]});
}

View 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",
]

View 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'

View File

@@ -0,0 +1,11 @@
use proconio::input;
fn main() {
input!{
n: u32,
};
let result = n * (n + 1) / 2;
println!("{}", {result});
}

View 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});
}

View 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});
}

View 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");
}

View File

@@ -7,8 +7,51 @@ int main(){
cout << "Hello this is Patrick" << endl; cout << "Hello this is Patrick" << endl;
auto start = chrono::high_resolution_clock::now(); 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<vector<long long>> 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<vector<long long>> 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::milliseconds>(chrono::high_resolution_clock::now() - start); auto duration = chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start);
cout << (float)duration.count()/1000 << endl; cout << (float)duration.count()/1000 << endl;
return 0; return 0;