diff --git a/solved/domino-tiles/domino-tiles.in b/solved/domino-tiles/domino-tiles.in new file mode 100644 index 0000000..e69de29 diff --git a/solved/domino-tiles/main.cpp b/solved/domino-tiles/main.cpp new file mode 100644 index 0000000..7889140 --- /dev/null +++ b/solved/domino-tiles/main.cpp @@ -0,0 +1,154 @@ +#include +using namespace std; + + +// ----- TYPES ----- +typedef long long ll; +typedef pair pii; +typedef vector vi; + +// ----- FILE IO ----- +#define STDIN(filename) freopen(filename, "r", stdin) +#define STDOUT(filename) freopen(filename, "w", stdout) +#define FASTIO cin.tie(0)->sync_with_stdio(0) +#define STDIO(filename) \ + FASTIO; \ + string filenamee(filename); \ + STDIN((filenamee + ".in").c_str()); \ + STDOUT((filenamee + ".out").c_str()) +#define NL '\n' +#define CM ", " +#define SP " " + +// ----- FOR LOOPS ----- +#define F(i, L, R) for (int i = L; i < R; i++) +#define FE(i, L, R) for (int i = L; i <= R; i++) +#define FD(i, L, R) for (int i = L; i > R; i--) +#define FDE(i, L, R) for (int i = L; i >= R; i--) + +// ----- WEZ ----- +#define takeI(n) \ + int n; \ + cin >> n +#define takeII(n, m) \ + int n, m; \ + cin >> n >> m +#define takeIII(n, m, k) \ + int n, m, k; \ + cin >> n >> m >> k +#define takeL(n) \ + ll n; \ + cin >> n +#define takeS(s) \ + string s; \ + cin >> s +#define takeV(v, n) \ + vi v(n); \ + for (auto &x : v) \ + cin >> x +#define takeVL(v, n) \ + vector v(n); \ + for (auto &x : v) \ + cin >> x +#define whileZ \ + takeI(T); \ + while (T--) +// +// ----- MAX MIN ----- +#define REMAX(a, b) (a) = max((a), (b)) +#define REMIN(a, b) (a) = min((a), (b)) + +// ----- PAIRS ----- +#define fi first +#define se second + +// ----- OUTPUT ----- +#define YESNO(b) cout << ((b) ? "YES" : "NO") << NL + +// ----- DEBUG ----- +#define DBG(vari) cerr << #vari << " = " << (vari) << endl +#define DBG2(a, b) cerr << #a "=" << (a) << CM << #b "=" << (b) << endl +#define printA(a, L, R) FE(i, L, R) cerr << a[i] << (i == R ? '\n' : ' ') +#define printV(a) printA(a, 0, SZ(a) - 1) + +// ----- STL DS +#define ALL(c) (c).begin(), (c).end() +#define SZ(c) ((int)(c).size()) +#define SORT(c) sort(ALL(c)) +#define RSORT(c) sort(ALL(c), greater<>()) +#define UNIQ(c) SORT(c), (c).erase(unique(ALL(c)), (c).end()) +#define pb push_back + +int main() { + FASTIO; + int MOD = 998244353; + + takeI(t); + while (t--) { + takeI(n); + takeS(s); + int res = 0; + + // The current row is represented by a string s + // of length n. Each character of s is 0, 1, or ?. + // Replace every ? with either 0 or 1. + + // After replacement, for every 1≤i [2, ] -> Must be 0, otherwise next domino will have score 2 + 01 -> [1, ] -> Must be 1, otherwise next domino has score 1 + 10 -> [1, ] -> Can be anything + 00 -> [0, ] -> Must be 1 + + The logic follows for the next step + Consider 0?1 + ? = 1 -> 011 (OK) + ? = 0 -> 001 (OK) + Consider 0?0 + ? = 0 -> 000 (NOT OK) + ? = 1 -? 010 (NOT OK) + + // We want s_i != s_(i+2) + // Therefor s_(i+2) = 1 - s_i + + ??? will be all possible tiles of length 3 + 2 * 2 + How can we find all poss + + * */ + // First digit can only be 0 or 1 + for (int s0 = 0; s0 < 2; s0++) { + // Second digit can only be 0 or 1 + for (int s1 = 0; s1 < 2; s1++) { + bool ok = true; + for (int i = 0; i < n; i++) { + // Expeced value follows the formula + // If i is even, we deal with s0, else we check against s1 + // To find if we deal with s0 or !s1, we need to flip bit + // With XOR, if (a,1) then we get !a, (a,0) we get a + int v = ((i%2 == 0) ? s0 : s1) ^ ((i/2) & 1); + if (s[i] != '?' && s[i] - '0' != v) {ok = false; break;} + } + res += ok; + } + } + + cout << res << NL; + } +} diff --git a/solved/the-cake-is-a-lie/main.cpp b/solved/the-cake-is-a-lie/main.cpp index 50d6f1a..93d6c70 100644 --- a/solved/the-cake-is-a-lie/main.cpp +++ b/solved/the-cake-is-a-lie/main.cpp @@ -1,7 +1,6 @@ #include using namespace std; - // ----- TYPES ----- typedef long long ll; typedef pair pii; diff --git a/solving/and-or-sort/and-or-sort.in b/solving/and-or-sort/and-or-sort.in new file mode 100644 index 0000000..e69de29 diff --git a/solving/and-or-sort/main.cpp b/solving/and-or-sort/main.cpp new file mode 100644 index 0000000..c7888df --- /dev/null +++ b/solving/and-or-sort/main.cpp @@ -0,0 +1,115 @@ +#include +#include +#include +using namespace std; + +// ----- TYPES ----- +typedef long long ll; +typedef pair pii; +typedef vector vi; + +// ----- FILE IO ----- +#define STDIN(filename) freopen(filename, "r", stdin) +#define STDOUT(filename) freopen(filename, "w", stdout) +#define FASTIO cin.tie(0)->sync_with_stdio(0) +#define STDIO(filename) \ + FASTIO; \ + string filenamee(filename); \ + STDIN((filenamee + ".in").c_str()); \ + STDOUT((filenamee + ".out").c_str()) +#define NL '\n' +#define CM ", " + +// ----- FOR LOOPS ----- +#define F(i, L, R) for (int i = L; i < R; i++) +#define FE(i, L, R) for (int i = L; i <= R; i++) +#define FD(i, L, R) for (int i = L; i > R; i--) +#define FDE(i, L, R) for (int i = L; i >= R; i--) + +// ----- WEZ ----- +#define takeI(n) \ + int n; \ + cin >> n +#define takeII(n, m) \ + int n, m; \ + cin >> n >> m +#define takeIII(n, m, k) \ + int n, m, k; \ + cin >> n >> m >> k +#define takeL(n) \ + ll n; \ + cin >> n +#define takeS(s) \ + string s; \ + cin >> s +#define takeV(v, n) \ + vi v(n); \ + for (auto &x : v) \ + cin >> x +#define takeVL(v, n) \ + vector v(n); \ + for (auto &x : v) \ + cin >> x +#define whileZ \ + takeI(T); \ + while (T--) +// +// ----- MAX MIN ----- +#define REMAX(a, b) (a) = max((a), (b)) +#define REMIN(a, b) (a) = min((a), (b)) + +// ----- PAIRS ----- +#define fi first +#define se second + +// ----- OUTPUT ----- +#define YESNO(b) cout << ((b) ? "YES" : "NO") << NL + +// ----- DEBUG ----- +#define DBG(vari) cerr << #vari << " = " << (vari) << endl +#define DBG2(a, b) cerr << #a "=" << (a) << CM << #b "=" << (b) << endl +#define printA(a, L, R) FE(i, L, R) cerr << a[i] << (i == R ? '\n' : ' ') +#define printV(a) printA(a, 0, SZ(a) - 1) + +// ----- STL DS +#define ALL(c) (c).begin(), (c).end() +#define SZ(c) ((int)(c).size()) +#define SORT(c) sort(ALL(c)) +#define RSORT(c) sort(ALL(c), greater<>()) +#define UNIQ(c) SORT(c), (c).erase(unique(ALL(c)), (c).end()) +#define pb push_back + +int main() { + FASTIO; + takeI(t); + while (t--) { + takeI(n); + takeS(s); + + // If prefix is 1, then only option is to convert all zeros to ones + int numZeros = 0; + for (auto x : s) if (x == '0') numZeros++; + + if (s[0] == '1') { + cout << numZeros << '\n'; + continue; + } + + // Skip leading 0s + // Index i is at position of first 1 + int seenZeros = 0, seenOnes = 0; + int i = 0; while (i < n && s[i] == '0') {seenZeros++; i++;} + + // Cost to flip remaining 0s to 1s + int min_cost = numZeros - seenZeros; + for (int j = i; j < n; j++) { + if (s[j] == '1') seenOnes++; + else seenZeros++; + + int curr_cost = (numZeros - seenZeros) + seenOnes; + min_cost = min(min_cost, curr_cost); + } + + cout << min_cost << '\n'; + } +} diff --git a/solving/and-or-sort/tests/1.in b/solving/and-or-sort/tests/1.in new file mode 100644 index 0000000..f890a86 --- /dev/null +++ b/solving/and-or-sort/tests/1.in @@ -0,0 +1,13 @@ +6 +4 +0011 +4 +1000 +5 +01000 +8 +01001101 +7 +0101010 +7 +0111101 diff --git a/solving/deque-malfunction/deque-malfunction.in b/solving/deque-malfunction/deque-malfunction.in new file mode 100644 index 0000000..e69de29 diff --git a/solving/deque-malfunction/main.cpp b/solving/deque-malfunction/main.cpp new file mode 100644 index 0000000..d3b2dd1 --- /dev/null +++ b/solving/deque-malfunction/main.cpp @@ -0,0 +1,102 @@ +#include +#include +#include +using namespace std; + +// ----- TYPES ----- +typedef long long ll; +typedef pair pii; +typedef vector vi; + +// ----- FILE IO ----- +#define STDIN(filename) freopen(filename, "r", stdin) +#define STDOUT(filename) freopen(filename, "w", stdout) +#define FASTIO cin.tie(0)->sync_with_stdio(0) +#define STDIO(filename) \ + FASTIO; \ + string filenamee(filename); \ + STDIN((filenamee + ".in").c_str()); \ + STDOUT((filenamee + ".out").c_str()) +#define NL '\n' +#define CM ", " + +// ----- FOR LOOPS ----- +#define F(i, L, R) for (int i = L; i < R; i++) +#define FE(i, L, R) for (int i = L; i <= R; i++) +#define FD(i, L, R) for (int i = L; i > R; i--) +#define FDE(i, L, R) for (int i = L; i >= R; i--) + +// ----- WEZ ----- +#define takeI(n) \ + int n; \ + cin >> n +#define takeII(n, m) \ + int n, m; \ + cin >> n >> m +#define takeIII(n, m, k) \ + int n, m, k; \ + cin >> n >> m >> k +#define takeL(n) \ + ll n; \ + cin >> n +#define takeS(s) \ + string s; \ + cin >> s +#define takeV(v, n) \ + vi v(n); \ + for (auto &x : v) \ + cin >> x +#define takeVL(v, n) \ + vector v(n); \ + for (auto &x : v) \ + cin >> x +#define whileZ \ + takeI(T); \ + while (T--) +// +// ----- MAX MIN ----- +#define REMAX(a, b) (a) = max((a), (b)) +#define REMIN(a, b) (a) = min((a), (b)) + +// ----- PAIRS ----- +#define fi first +#define se second + +// ----- OUTPUT ----- +#define YESNO(b) cout << ((b) ? "YES" : "NO") << NL + +// ----- DEBUG ----- +#define DBG(vari) cerr << #vari << " = " << (vari) << endl +#define DBG2(a, b) cerr << #a "=" << (a) << CM << #b "=" << (b) << endl +#define printA(a, L, R) FE(i, L, R) cerr << a[i] << (i == R ? '\n' : ' ') +#define printV(a) printA(a, 0, SZ(a) - 1) + +// ----- STL DS +#define ALL(c) (c).begin(), (c).end() +#define SZ(c) ((int)(c).size()) +#define SORT(c) sort(ALL(c)) +#define RSORT(c) sort(ALL(c), greater<>()) +#define UNIQ(c) SORT(c), (c).erase(unique(ALL(c)), (c).end()) +#define pb push_back + +int main() { + takeI(t); + while (t--) { + takeII(n, m); + takeV(b, m); + + // The last occurance of bi is at i + + for (int i = 0; i < m; i++) + if (i <= n) + lastIndex[b[i]] = i; + + if (lastIndex.size() != n) { + cout << -1 << '\n'; + continue; + } + + for (auto [k, v] : lastIndex) cout << k << ' ' << v << '\n'; + cout << 1 << '\n'; + } +} diff --git a/solving/dr-agos-dark-mode/.url b/solving/dr-agos-dark-mode/.url new file mode 100644 index 0000000..b2c3767 --- /dev/null +++ b/solving/dr-agos-dark-mode/.url @@ -0,0 +1 @@ +https://codeforces.com/problemset/problem/2264/D diff --git a/solving/dr-agos-dark-mode/dr-agos-dark-mode.in b/solving/dr-agos-dark-mode/dr-agos-dark-mode.in new file mode 100644 index 0000000..e69de29 diff --git a/solving/dr-agos-dark-mode/main.cpp b/solving/dr-agos-dark-mode/main.cpp new file mode 100644 index 0000000..66197b1 --- /dev/null +++ b/solving/dr-agos-dark-mode/main.cpp @@ -0,0 +1,90 @@ +#include +#include +#include +#include +using namespace std; + +// ----- TYPES ----- +typedef long long ll; +typedef pair pii; +typedef vector vi; + +// ----- FILE IO ----- +#define STDIN(filename) freopen(filename, "r", stdin) +#define STDOUT(filename) freopen(filename, "w", stdout) +#define FASTIO cin.tie(0)->sync_with_stdio(0) +#define STDIO(filename) \ + FASTIO; \ + string filenamee(filename); \ + STDIN((filenamee + ".in").c_str()); \ + STDOUT((filenamee + ".out").c_str()) +#define NL '\n' +#define CM ", " + +// ----- FOR LOOPS ----- +#define F(i, L, R) for (int i = L; i < R; i++) +#define FE(i, L, R) for (int i = L; i <= R; i++) +#define FD(i, L, R) for (int i = L; i > R; i--) +#define FDE(i, L, R) for (int i = L; i >= R; i--) + +// ----- WEZ ----- +#define takeI(n) \ + int n; \ + cin >> n +#define takeII(n, m) \ + int n, m; \ + cin >> n >> m +#define takeIII(n, m, k) \ + int n, m, k; \ + cin >> n >> m >> k +#define takeL(n) \ + ll n; \ + cin >> n +#define takeS(s) \ + string s; \ + cin >> s +#define takeV(v, n) \ + vi v(n); \ + for (auto &x : v) \ + cin >> x +#define takeVL(v, n) \ + vector v(n); \ + for (auto &x : v) \ + cin >> x +#define whileZ \ + takeI(T); \ + while (T--) +// +// ----- MAX MIN ----- +#define REMAX(a, b) (a) = max((a), (b)) +#define REMIN(a, b) (a) = min((a), (b)) + +// ----- PAIRS ----- +#define fi first +#define se second + +// ----- OUTPUT ----- +#define YESNO(b) cout << ((b) ? "YES" : "NO") << NL + +// ----- DEBUG ----- +#define DBG(vari) cerr << #vari << " = " << (vari) << endl +#define DBG2(a, b) cerr << #a "=" << (a) << CM << #b "=" << (b) << endl +#define printA(a, L, R) FE(i, L, R) cerr << a[i] << (i == R ? '\n' : ' ') +#define printV(a) printA(a, 0, SZ(a) - 1) + +// ----- STL DS +#define ALL(c) (c).begin(), (c).end() +#define SZ(c) ((int)(c).size()) +#define SORT(c) sort(ALL(c)) +#define RSORT(c) sort(ALL(c), greater<>()) +#define UNIQ(c) SORT(c), (c).erase(unique(ALL(c)), (c).end()) +#define pb push_back + +int main() { + FASTIO; + takeI(t); + while (t--) { + takeI(n); + // 1010101 + } +} diff --git a/solving/falling-concrete/falling-concrete.in b/solving/falling-concrete/falling-concrete.in new file mode 100644 index 0000000..e69de29 diff --git a/solving/falling-concrete/main.cpp b/solving/falling-concrete/main.cpp new file mode 100644 index 0000000..d19e2f2 --- /dev/null +++ b/solving/falling-concrete/main.cpp @@ -0,0 +1,96 @@ +#include +#include +#include +using namespace std; + +// ----- TYPES ----- +typedef long long ll; +typedef pair pii; +typedef vector vi; + +// ----- FILE IO ----- +#define STDIN(filename) freopen(filename, "r", stdin) +#define STDOUT(filename) freopen(filename, "w", stdout) +#define FASTIO cin.tie(0)->sync_with_stdio(0) +#define STDIO(filename) \ + FASTIO; \ + string filenamee(filename); \ + STDIN((filenamee + ".in").c_str()); \ + STDOUT((filenamee + ".out").c_str()) +#define NL '\n' +#define CM ", " + +// ----- FOR LOOPS ----- +#define F(i, L, R) for (int i = L; i < R; i++) +#define FE(i, L, R) for (int i = L; i <= R; i++) +#define FD(i, L, R) for (int i = L; i > R; i--) +#define FDE(i, L, R) for (int i = L; i >= R; i--) + +// ----- WEZ ----- +#define takeI(n) \ + int n; \ + cin >> n +#define takeII(n, m) \ + int n, m; \ + cin >> n >> m +#define takeIII(n, m, k) \ + int n, m, k; \ + cin >> n >> m >> k +#define takeL(n) \ + ll n; \ + cin >> n +#define takeS(s) \ + string s; \ + cin >> s +#define takeV(v, n) \ + vi v(n); \ + for (auto &x : v) \ + cin >> x +#define takeVL(v, n) \ + vector v(n); \ + for (auto &x : v) \ + cin >> x +#define whileZ \ + takeI(T); \ + while (T--) +// +// ----- MAX MIN ----- +#define REMAX(a, b) (a) = max((a), (b)) +#define REMIN(a, b) (a) = min((a), (b)) + +// ----- PAIRS ----- +#define fi first +#define se second + +// ----- OUTPUT ----- +#define YESNO(b) cout << ((b) ? "YES" : "NO") << NL + +// ----- DEBUG ----- +#define DBG(vari) cerr << #vari << " = " << (vari) << endl +#define DBG2(a, b) cerr << #a "=" << (a) << CM << #b "=" << (b) << endl +#define printA(a, L, R) FE(i, L, R) cerr << a[i] << (i == R ? '\n' : ' ') +#define printV(a) printA(a, 0, SZ(a) - 1) + +// ----- STL DS +#define ALL(c) (c).begin(), (c).end() +#define SZ(c) ((int)(c).size()) +#define SORT(c) sort(ALL(c)) +#define RSORT(c) sort(ALL(c), greater<>()) +#define UNIQ(c) SORT(c), (c).erase(unique(ALL(c)), (c).end()) +#define pb push_back + +int main() { + FASTIO; + takeI(t); + while (t--) { + takeI(n); + takeV(a, n); + int res = 0; + + // can move a[j] to a[i] + // [ai, ai+1, ai+2 ... aj] + // [aj - (j - i), ai+1, ai+2, ... aj-1 + 1] + + cout << res << '\n'; + } +} diff --git a/solving/good-contest/good-contest.in b/solving/good-contest/good-contest.in new file mode 100644 index 0000000..e69de29 diff --git a/solving/good-contest/main.cpp b/solving/good-contest/main.cpp new file mode 100644 index 0000000..9436553 --- /dev/null +++ b/solving/good-contest/main.cpp @@ -0,0 +1,94 @@ +#include +#include +#include +using namespace std; + +// ----- TYPES ----- +typedef long long ll; +typedef pair pii; +typedef vector vi; + +// ----- FILE IO ----- +#define STDIN(filename) freopen(filename, "r", stdin) +#define STDOUT(filename) freopen(filename, "w", stdout) +#define FASTIO cin.tie(0)->sync_with_stdio(0) +#define STDIO(filename) \ + FASTIO; \ + string filenamee(filename); \ + STDIN((filenamee + ".in").c_str()); \ + STDOUT((filenamee + ".out").c_str()) +#define NL '\n' +#define CM ", " + +// ----- FOR LOOPS ----- +#define F(i, L, R) for (int i = L; i < R; i++) +#define FE(i, L, R) for (int i = L; i <= R; i++) +#define FD(i, L, R) for (int i = L; i > R; i--) +#define FDE(i, L, R) for (int i = L; i >= R; i--) + +// ----- WEZ ----- +#define takeI(n) \ + int n; \ + cin >> n +#define takeII(n, m) \ + int n, m; \ + cin >> n >> m +#define takeIII(n, m, k) \ + int n, m, k; \ + cin >> n >> m >> k +#define takeL(n) \ + ll n; \ + cin >> n +#define takeS(s) \ + string s; \ + cin >> s +#define takeV(v, n) \ + vi v(n); \ + for (auto &x : v) \ + cin >> x +#define takeVL(v, n) \ + vector v(n); \ + for (auto &x : v) \ + cin >> x +#define whileZ \ + takeI(T); \ + while (T--) +// +// ----- MAX MIN ----- +#define REMAX(a, b) (a) = max((a), (b)) +#define REMIN(a, b) (a) = min((a), (b)) + +// ----- PAIRS ----- +#define fi first +#define se second + +// ----- OUTPUT ----- +#define YESNO(b) cout << ((b) ? "YES" : "NO") << NL + +// ----- DEBUG ----- +#define DBG(vari) cerr << #vari << " = " << (vari) << endl +#define DBG2(a, b) cerr << #a "=" << (a) << CM << #b "=" << (b) << endl +#define printA(a, L, R) FE(i, L, R) cerr << a[i] << (i == R ? '\n' : ' ') +#define printV(a) printA(a, 0, SZ(a) - 1) + +// ----- STL DS +#define ALL(c) (c).begin(), (c).end() +#define SZ(c) ((int)(c).size()) +#define SORT(c) sort(ALL(c)) +#define RSORT(c) sort(ALL(c), greater<>()) +#define UNIQ(c) SORT(c), (c).erase(unique(ALL(c)), (c).end()) +#define pb push_back + +int main() { + FASTIO; + takeI(t); + while (t--) { + takeI(n); + takeIII(a1,a2,a3); + int res = 0; + + res = max({n-a1, n-a2, n-a3}); + + cout << res << '\n'; + } +} diff --git a/solving/hot-potatoes-at-the-fairy-warehouse/hot-potatoes-at-the-fairy-warehouse.in b/solving/hot-potatoes-at-the-fairy-warehouse/hot-potatoes-at-the-fairy-warehouse.in new file mode 100644 index 0000000..e69de29 diff --git a/solving/hot-potatoes-at-the-fairy-warehouse/main.cpp b/solving/hot-potatoes-at-the-fairy-warehouse/main.cpp new file mode 100644 index 0000000..7caf828 --- /dev/null +++ b/solving/hot-potatoes-at-the-fairy-warehouse/main.cpp @@ -0,0 +1,99 @@ +#include +using namespace std; + + +// ----- TYPES ----- +typedef long long ll; +typedef pair pii; +typedef vector vi; + +// ----- FILE IO ----- +#define STDIN(filename) freopen(filename, "r", stdin) +#define STDOUT(filename) freopen(filename, "w", stdout) +#define FASTIO cin.tie(0)->sync_with_stdio(0) +#define STDIO(filename) \ + FASTIO; \ + string filenamee(filename); \ + STDIN((filenamee + ".in").c_str()); \ + STDOUT((filenamee + ".out").c_str()) +#define NL '\n' +#define CM ", " +#define SP " " + +// ----- FOR LOOPS ----- +#define F(i, L, R) for (int i = L; i < R; i++) +#define FE(i, L, R) for (int i = L; i <= R; i++) +#define FD(i, L, R) for (int i = L; i > R; i--) +#define FDE(i, L, R) for (int i = L; i >= R; i--) + +// ----- WEZ ----- +#define takeI(n) \ + int n; \ + cin >> n +#define takeII(n, m) \ + int n, m; \ + cin >> n >> m +#define takeIII(n, m, k) \ + int n, m, k; \ + cin >> n >> m >> k +#define takeL(n) \ + ll n; \ + cin >> n +#define takeS(s) \ + string s; \ + cin >> s +#define takeV(v, n) \ + vi v(n); \ + for (auto &x : v) \ + cin >> x +#define takeVL(v, n) \ + vector v(n); \ + for (auto &x : v) \ + cin >> x +#define whileZ \ + takeI(T); \ + while (T--) +// +// ----- MAX MIN ----- +#define REMAX(a, b) (a) = max((a), (b)) +#define REMIN(a, b) (a) = min((a), (b)) + +// ----- PAIRS ----- +#define fi first +#define se second + +// ----- OUTPUT ----- +#define YESNO(b) cout << ((b) ? "YES" : "NO") << NL + +// ----- DEBUG ----- +#define DBG(vari) cerr << #vari << " = " << (vari) << endl +#define DBG2(a, b) cerr << #a "=" << (a) << CM << #b "=" << (b) << endl +#define printA(a, L, R) FE(i, L, R) cerr << a[i] << (i == R ? '\n' : ' ') +#define printV(a) printA(a, 0, SZ(a) - 1) + +// ----- STL DS +#define ALL(c) (c).begin(), (c).end() +#define SZ(c) ((int)(c).size()) +#define SORT(c) sort(ALL(c)) +#define RSORT(c) sort(ALL(c), greater<>()) +#define UNIQ(c) SORT(c), (c).erase(unique(ALL(c)), (c).end()) +#define pb push_back + +int main() { + FASTIO; + takeI(t); + while (t--) { + takeII(n, k); + takeS(s); + int redTeamScore = 0, blueTeamScore = 0; + + // Initially, some s[i] = 1 + // The game then lasts for k rounds. + // + // For all s[i] == 1 + // Keep s[i] == 1 or if (s[i+1 % (2n)] == 0) then s[i+1 % (2n)] = 1 + // Find the scores of the Red Team and the Blue Team if both teams play optimally. It can be shown that the scores under optimal play are uniquely determined. + + cout << redTeamScore << SP << blueTeamScore << NL; + } +} diff --git a/solving/prime-destruction/main.cpp b/solving/prime-destruction/main.cpp new file mode 100644 index 0000000..f5e7480 --- /dev/null +++ b/solving/prime-destruction/main.cpp @@ -0,0 +1,112 @@ +#include +#include +#include +using namespace std; + +// ----- TYPES ----- +typedef long long ll; +typedef pair pii; +typedef vector vi; + +// ----- FILE IO ----- +#define STDIN(filename) freopen(filename, "r", stdin) +#define STDOUT(filename) freopen(filename, "w", stdout) +#define FASTIO cin.tie(0)->sync_with_stdio(0) +#define STDIO(filename) \ + FASTIO; \ + string filenamee(filename); \ + STDIN((filenamee + ".in").c_str()); \ + STDOUT((filenamee + ".out").c_str()) +#define NL '\n' +#define CM ", " + +// ----- FOR LOOPS ----- +#define F(i, L, R) for (int i = L; i < R; i++) +#define FE(i, L, R) for (int i = L; i <= R; i++) +#define FD(i, L, R) for (int i = L; i > R; i--) +#define FDE(i, L, R) for (int i = L; i >= R; i--) + +// ----- WEZ ----- +#define takeI(n) \ + int n; \ + cin >> n +#define takeII(n, m) \ + int n, m; \ + cin >> n >> m +#define takeIII(n, m, k) \ + int n, m, k; \ + cin >> n >> m >> k +#define takeL(n) \ + ll n; \ + cin >> n +#define takeS(s) \ + string s; \ + cin >> s +#define takeV(v, n) \ + vi v(n); \ + for (auto &x : v) \ + cin >> x +#define takeVL(v, n) \ + vector v(n); \ + for (auto &x : v) \ + cin >> x +#define whileZ \ + takeI(T); \ + while (T--) +// +// ----- MAX MIN ----- +#define REMAX(a, b) (a) = max((a), (b)) +#define REMIN(a, b) (a) = min((a), (b)) + +// ----- PAIRS ----- +#define fi first +#define se second + +// ----- OUTPUT ----- +#define YESNO(b) cout << ((b) ? "YES" : "NO") << NL + +// ----- DEBUG ----- +#define DBG(vari) cerr << #vari << " = " << (vari) << endl +#define DBG2(a, b) cerr << #a "=" << (a) << CM << #b "=" << (b) << endl +#define printA(a, L, R) FE(i, L, R) cerr << a[i] << (i == R ? '\n' : ' ') +#define printV(a) printA(a, 0, SZ(a) - 1) + +// ----- STL DS +#define ALL(c) (c).begin(), (c).end() +#define SZ(c) ((int)(c).size()) +#define SORT(c) sort(ALL(c)) +#define RSORT(c) sort(ALL(c), greater<>()) +#define UNIQ(c) SORT(c), (c).erase(unique(ALL(c)), (c).end()) +#define pb push_back + +int main() { + FASTIO; + takeI(t); + while (t--) { + takeII(n, k); + takeV(a, n); + + // We don't care if x <= k + map multiset; + for (auto x : a) if (x > k) multiset[x]++; + + // Multiset contains all 'naughty elements' + // Fastest idea is to remove largest prime factor of x + // + + int fk; + // Choose an integer x>1 from the multiset + // Choose prime divisor p of x. + // + // Then + // + // Remove one occurrence of x from the multiset + // add p copies of x / p. + + // Let f(k) be the minimum number of operations required + // starting from the original multiset + // until every integer in the multiset is at most k. + + cout << fk << '\n'; + } +} diff --git a/solving/prime-destruction/prime-destruction.in b/solving/prime-destruction/prime-destruction.in new file mode 100644 index 0000000..e69de29 diff --git a/solving/social-experiment/.url b/solving/social-experiment/.url new file mode 100644 index 0000000..ef822e1 --- /dev/null +++ b/solving/social-experiment/.url @@ -0,0 +1 @@ +https://codeforces.com/contest/2184/problem/A diff --git a/solving/social-experiment/main.cpp b/solving/social-experiment/main.cpp new file mode 100644 index 0000000..511151a --- /dev/null +++ b/solving/social-experiment/main.cpp @@ -0,0 +1,114 @@ +#include +#include +#include +#include +using namespace std; + +// ----- TYPES ----- +typedef long long ll; +typedef pair pii; +typedef vector vi; + +// ----- FILE IO ----- +#define STDIN(filename) freopen(filename, "r", stdin) +#define STDOUT(filename) freopen(filename, "w", stdout) +#define FASTIO cin.tie(0)->sync_with_stdio(0) +#define STDIO(filename) \ + FASTIO; \ + string filenamee(filename); \ + STDIN((filenamee + ".in").c_str()); \ + STDOUT((filenamee + ".out").c_str()) +#define NL '\n' +#define CM ", " + +// ----- FOR LOOPS ----- +#define F(i, L, R) for (int i = L; i < R; i++) +#define FE(i, L, R) for (int i = L; i <= R; i++) +#define FD(i, L, R) for (int i = L; i > R; i--) +#define FDE(i, L, R) for (int i = L; i >= R; i--) + +// ----- WEZ ----- +#define takeI(n) \ + int n; \ + cin >> n +#define takeII(n, m) \ + int n, m; \ + cin >> n >> m +#define takeIII(n, m, k) \ + int n, m, k; \ + cin >> n >> m >> k +#define takeL(n) \ + ll n; \ + cin >> n +#define takeS(s) \ + string s; \ + cin >> s +#define takeV(v, n) \ + vi v(n); \ + for (auto &x : v) \ + cin >> x +#define takeVL(v, n) \ + vector v(n); \ + for (auto &x : v) \ + cin >> x +#define whileZ \ + takeI(T); \ + while (T--) +// +// ----- MAX MIN ----- +#define REMAX(a, b) (a) = max((a), (b)) +#define REMIN(a, b) (a) = min((a), (b)) + +// ----- PAIRS ----- +#define fi first +#define se second + +// ----- OUTPUT ----- +#define YESNO(b) cout << ((b) ? "YES" : "NO") << NL + +// ----- DEBUG ----- +#define DBG(vari) cerr << #vari << " = " << (vari) << endl +#define DBG2(a, b) cerr << #a "=" << (a) << CM << #b "=" << (b) << endl +#define printA(a, L, R) FE(i, L, R) cerr << a[i] << (i == R ? '\n' : ' ') +#define printV(a) printA(a, 0, SZ(a) - 1) + +// ----- STL DS +#define ALL(c) (c).begin(), (c).end() +#define SZ(c) ((int)(c).size()) +#define SORT(c) sort(ALL(c)) +#define RSORT(c) sort(ALL(c), greater<>()) +#define UNIQ(c) SORT(c), (c).erase(unique(ALL(c)), (c).end()) +#define pb push_back + +int main() { + FASTIO; + takeI(t); + while (t--) { + takeI(n); + int res; + + /** + + Keep putting 3, 3 in each civ + We will be left with n % 6 + + Keep putting 2, 2 in each civ + We are left with n % 4 + + 2 -> 2 + 3 -> 3 + 4 -> 0 + 5 -> 1 + 6 -> 0 + 7 -> 1 + 8 -> 0 + 9 -> 1 + 10 -> 0 + 11 -> 1 + 12 -> 0 + + * */ + + cout << res << NL; + } +} diff --git a/solving/social-experiment/social-experiment.in b/solving/social-experiment/social-experiment.in new file mode 100644 index 0000000..e69de29 diff --git a/solving/three-number-on-the-blackboard/main.cpp b/solving/three-number-on-the-blackboard/main.cpp new file mode 100644 index 0000000..03bf8a3 --- /dev/null +++ b/solving/three-number-on-the-blackboard/main.cpp @@ -0,0 +1,101 @@ +#include +using namespace std; + + +// ----- TYPES ----- +typedef long long ll; +typedef pair pii; +typedef vector vi; + +// ----- FILE IO ----- +#define STDIN(filename) freopen(filename, "r", stdin) +#define STDOUT(filename) freopen(filename, "w", stdout) +#define FASTIO cin.tie(0)->sync_with_stdio(0) +#define STDIO(filename) \ + FASTIO; \ + string filenamee(filename); \ + STDIN((filenamee + ".in").c_str()); \ + STDOUT((filenamee + ".out").c_str()) +#define NL '\n' +#define CM ", " +#define SP " " + +// ----- FOR LOOPS ----- +#define F(i, L, R) for (int i = L; i < R; i++) +#define FE(i, L, R) for (int i = L; i <= R; i++) +#define FD(i, L, R) for (int i = L; i > R; i--) +#define FDE(i, L, R) for (int i = L; i >= R; i--) + +// ----- WEZ ----- +#define takeI(n) \ + int n; \ + cin >> n +#define takeII(n, m) \ + int n, m; \ + cin >> n >> m +#define takeIII(n, m, k) \ + int n, m, k; \ + cin >> n >> m >> k +#define takeL(n) \ + ll n; \ + cin >> n +#define takeS(s) \ + string s; \ + cin >> s +#define takeV(v, n) \ + vi v(n); \ + for (auto &x : v) \ + cin >> x +#define takeVL(v, n) \ + vector v(n); \ + for (auto &x : v) \ + cin >> x +#define whileZ \ + takeI(T); \ + while (T--) +// +// ----- MAX MIN ----- +#define REMAX(a, b) (a) = max((a), (b)) +#define REMIN(a, b) (a) = min((a), (b)) + +// ----- PAIRS ----- +#define fi first +#define se second + +// ----- OUTPUT ----- +#define YESNO(b) cout << ((b) ? "YES" : "NO") << NL + +// ----- DEBUG ----- +#define DBG(vari) cerr << #vari << " = " << (vari) << endl +#define DBG2(a, b) cerr << #a "=" << (a) << CM << #b "=" << (b) << endl +#define printA(a, L, R) FE(i, L, R) cerr << a[i] << (i == R ? '\n' : ' ') +#define printV(a) printA(a, 0, SZ(a) - 1) + +// ----- STL DS +#define ALL(c) (c).begin(), (c).end() +#define SZ(c) ((int)(c).size()) +#define SORT(c) sort(ALL(c)) +#define RSORT(c) sort(ALL(c), greater<>()) +#define UNIQ(c) SORT(c), (c).erase(unique(ALL(c)), (c).end()) +#define pb push_back + +int maxDiff(int a, int b, int c) { + return max({abs(a-b), abs(a-c), abs(b-c)}); +} + +int main() { + FASTIO; + takeI(t); + while (t--) { + takeIII(a,b,c); + int rng = min({maxDiff(a,b,c), maxDiff(a,b,a+b), maxDiff(a,a+c,c), maxDiff(b+c, b,c)}); + + // Choose one of the three current integers and replace it with the sum of the other two current integers. The other two integers remain unchanged. + // Do this any number of times + // Find minumum range of integers + // (a,b,c) -> (b+c, b, c) + + + cout << rng << NL; + } +} diff --git a/solving/three-number-on-the-blackboard/three-number-on-the-blackboard.in b/solving/three-number-on-the-blackboard/three-number-on-the-blackboard.in new file mode 100644 index 0000000..e69de29 diff --git a/solving/three-piles/main.cpp b/solving/three-piles/main.cpp new file mode 100644 index 0000000..cd795a0 --- /dev/null +++ b/solving/three-piles/main.cpp @@ -0,0 +1,94 @@ +#include +#include +using namespace std; + +// ----- TYPES ----- +typedef long long ll; +typedef pair pii; +typedef vector vi; + +// ----- FILE IO ----- +#define STDIN(filename) freopen(filename, "r", stdin) +#define STDOUT(filename) freopen(filename, "w", stdout) +#define FASTIO cin.tie(0)->sync_with_stdio(0) +#define STDIO(filename) \ + FASTIO; \ + string filenamee(filename); \ + STDIN((filenamee + ".in").c_str()); \ + STDOUT((filenamee + ".out").c_str()) +#define NL '\n' +#define CM ", " + +// ----- FOR LOOPS ----- +#define F(i, L, R) for (int i = L; i < R; i++) +#define FE(i, L, R) for (int i = L; i <= R; i++) +#define FD(i, L, R) for (int i = L; i > R; i--) +#define FDE(i, L, R) for (int i = L; i >= R; i--) + +// ----- WEZ ----- +#define takeI(n) \ + int n; \ + cin >> n +#define takeII(n, m) \ + int n, m; \ + cin >> n >> m +#define takeIII(n, m, k) \ + int n, m, k; \ + cin >> n >> m >> k +#define takeL(n) \ + ll n; \ + cin >> n +#define takeS(s) \ + string s; \ + cin >> s +#define takeV(v, n) \ + vi v(n); \ + for (auto &x : v) \ + cin >> x +#define takeVL(v, n) \ + vector v(n); \ + for (auto &x : v) \ + cin >> x +#define whileZ \ + takeI(T); \ + while (T--) +// +// ----- MAX MIN ----- +#define REMAX(a, b) (a) = max((a), (b)) +#define REMIN(a, b) (a) = min((a), (b)) + +// ----- PAIRS ----- +#define fi first +#define se second + +// ----- OUTPUT ----- +#define YESNO(b) cout << ((b) ? "YES" : "NO") << NL + +// ----- DEBUG ----- +#define DBG(vari) cerr << #vari << " = " << (vari) << endl +#define DBG2(a, b) cerr << #a "=" << (a) << CM << #b "=" << (b) << endl +#define printA(a, L, R) FE(i, L, R) cerr << a[i] << (i == R ? '\n' : ' ') +#define printV(a) printA(a, 0, SZ(a) - 1) + +// ----- STL DS +#define ALL(c) (c).begin(), (c).end() +#define SZ(c) ((int)(c).size()) +#define SORT(c) sort(ALL(c)) +#define RSORT(c) sort(ALL(c), greater<>()) +#define UNIQ(c) SORT(c), (c).erase(unique(ALL(c)), (c).end()) +#define pb push_back + +int main() { + FASTIO; + takeI(t); + while (t--) { + long long a, b, c; + cin >> a >> b >> c; + + long long res = 0; + + res = max(abs(a-b), abs(a+c) - b); + + cout << res << '\n'; + } +} diff --git a/solving/three-piles/three-piles.in b/solving/three-piles/three-piles.in new file mode 100644 index 0000000..e69de29