Skip to content

Commit cbcaab5

Browse files
Added advent of code
1 parent a386689 commit cbcaab5

File tree

3 files changed

+187
-0
lines changed

3 files changed

+187
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// doot diddly donger cuckerino Hahahahahah
2+
3+
4+
#pragma GCC optimize("Ofast")
5+
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
6+
#pragma GCC optimize("unroll-loops")
7+
8+
#include <bits/stdc++.h>
9+
using namespace std;
10+
11+
using ll = long long;
12+
using ld = long double;
13+
using pii = pair<int, int>;
14+
using vi = vector<int>;
15+
16+
#define all(x) (x).begin(), (x).end()
17+
const ld PI = acos(-1);
18+
19+
template <typename T> inline T mini(T& x, T y) { return x = min(x, y); }
20+
template <typename T> inline T maxi(T& x, T y) { return x = max(x, y); }
21+
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
22+
template <typename T, typename U>
23+
std::ostream& operator<<(std::ostream& stream, const pair<T, U>& p) {
24+
return stream << p.first << " " << p.second;
25+
}
26+
template <typename T>
27+
std::ostream& operator<<(std::ostream& out, const vector<T>& vec) {
28+
for (const T& x: vec) out << x << ' ';
29+
return out;
30+
}
31+
template <typename T>
32+
std::istream& operator>>(std::istream& in, vector<T>& vec) {
33+
for (auto& x: vec) in >> x;
34+
return in;
35+
}
36+
37+
class AOC2b {
38+
public:
39+
40+
const int SUM = 2020;
41+
void solve(std::istream& cin, std::ostream& cout) {
42+
vector<int> a;
43+
int temp;
44+
while (cin >> temp) {
45+
a.push_back(temp);
46+
}
47+
sort(a.begin(), a.end());
48+
int n = a.size();
49+
for (int i = 0; i < n; ++i) {
50+
for (int j = i + 1; j < n; ++j) {
51+
if (binary_search(a.begin() + j + 1, a.end(), SUM - a[i] - a[j])) {
52+
cout << (a[i] * a[j] * (SUM - a[i] - a[j])) << '\n';
53+
}
54+
}
55+
}
56+
}
57+
};
58+
59+
int32_t main() {
60+
std::ios::sync_with_stdio(false);
61+
std::cin.tie(nullptr);
62+
std::cout.tie(nullptr);
63+
AOC2b solver;
64+
std::istream& in(std::cin);
65+
std::ostream& out(std::cout);
66+
solver.solve(in, out);
67+
return 0;
68+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
2+
#include <bits/stdc++.h>
3+
using namespace std;
4+
5+
using ll = long long;
6+
using ld = long double;
7+
8+
template<typename T> inline T mini(T& x, T y) { return x = min(x, y); }
9+
template<typename T> inline T maxi(T& x, T y) { return x = max(x, y); }
10+
template <typename T> T rand(T x, T y) { return rand() % (y - x + 1) + x; }
11+
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
12+
13+
14+
class AOC3 {
15+
public:
16+
vector<string> a;
17+
int n, m;
18+
19+
int Count(int x, int y) {
20+
int cnt = 0;
21+
for (int i = 0, j = 0; i < n; i += y, j = (j + x) % m) {
22+
cnt += a[i][j] == '#';
23+
}
24+
return cnt;
25+
}
26+
27+
void solve(std::istream& cin, std::ostream& cout) {
28+
29+
string temp;
30+
while (cin >> temp) {
31+
a.push_back(temp);
32+
}
33+
n = a.size(), m = a[0].size();
34+
long long pro = 1;
35+
for (auto[x, y]: {make_pair(1, 1), {3, 1}, {5, 1}, {7, 1}, {1, 2}}) {
36+
pro *= Count(x, y);
37+
// cout << make_pair(x, y) << " " << Count(x, y) << '\n';
38+
}
39+
cout << pro << '\n';
40+
}
41+
};
42+
43+
int32_t main() {
44+
std::ios::sync_with_stdio(false);
45+
std::cin.tie(nullptr);
46+
std::cout.tie(nullptr);
47+
AOC3 solver;
48+
std::istream& in(std::cin);
49+
std::ostream& out(std::cout);
50+
solver.solve(in, out);
51+
return 0;
52+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// doot diddly donger cuckerino Hahahahahah
2+
3+
4+
#pragma GCC optimize("Ofast")
5+
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
6+
#pragma GCC optimize("unroll-loops")
7+
8+
#include <bits/stdc++.h>
9+
using namespace std;
10+
11+
using ll = long long;
12+
using ld = long double;
13+
using pii = pair<int, int>;
14+
using vi = vector<int>;
15+
16+
#define all(x) (x).begin(), (x).end()
17+
const ld PI = acos(-1);
18+
19+
template <typename T> inline T mini(T& x, T y) { return x = min(x, y); }
20+
template <typename T> inline T maxi(T& x, T y) { return x = max(x, y); }
21+
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
22+
template <typename T, typename U>
23+
std::ostream& operator<<(std::ostream& stream, const pair<T, U>& p) {
24+
return stream << p.first << " " << p.second;
25+
}
26+
template <typename T>
27+
std::ostream& operator<<(std::ostream& out, const vector<T>& vec) {
28+
for (const T& x: vec) out << x << ' ';
29+
return out;
30+
}
31+
template <typename T>
32+
std::istream& operator>>(std::istream& in, vector<T>& vec) {
33+
for (auto& x: vec) in >> x;
34+
return in;
35+
}
36+
37+
class AdventOfCode1 {
38+
public:
39+
40+
void solve(std::istream& cin, std::ostream& cout) {
41+
vector<int> a;
42+
int x;
43+
while (cin >> x) {
44+
a.push_back(x);
45+
}
46+
int n = a.size();
47+
int sum = 2020;
48+
unordered_map<int, int> mp;
49+
for (int i = 0; i < n; ++i) {
50+
if (mp.count(sum - a[i])) {
51+
cout << (sum - a[i]) * a[i] << '\n';
52+
}
53+
mp[a[i]]++;
54+
}
55+
}
56+
};
57+
58+
int32_t main() {
59+
std::ios::sync_with_stdio(false);
60+
std::cin.tie(nullptr);
61+
std::cout.tie(nullptr);
62+
AdventOfCode1 solver;
63+
std::istream& in(std::cin);
64+
std::ostream& out(std::cout);
65+
solver.solve(in, out);
66+
return 0;
67+
}

0 commit comments

Comments
 (0)