diff --git a/.autocp b/.autocp index c567e8f..a628a29 100644 --- a/.autocp +++ b/.autocp @@ -1 +1 @@ -{"version":1,"problems":{"CSES - CSES Problem Set":{"Weird Algorithm":{"name":"Weird Algorithm","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1068/","sampleTestcases":[{"name":"Sample Testcase #1","input":"3\n","output":"3 10 5 16 8 4 2 1\n"}],"memoryLimit":512,"timeLimit":1000},"Missing Number":{"name":"Missing Number","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1083","sampleTestcases":[{"name":"Sample Testcase #1","input":"5\n2 3 1 5\n","output":"4\n"}],"memoryLimit":512,"timeLimit":1000},"Repetitions":{"name":"Repetitions","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1069","sampleTestcases":[{"name":"Sample Testcase #1","input":"ATTCGGGA\n","output":"3\n"}],"memoryLimit":512,"timeLimit":1000},"Increasing Array":{"name":"Increasing Array","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1094","sampleTestcases":[{"name":"Sample Testcase #1","input":"5\n3 2 5 1 7\n","output":"5\n"}],"memoryLimit":512,"timeLimit":1000},"Permutations":{"name":"Permutations","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1070","sampleTestcases":[{"name":"Sample Testcase #1","input":"5\n","output":"4 2 5 3 1\n"},{"name":"Sample Testcase #2","input":"3\n","output":"NO SOLUTION\n"}],"memoryLimit":512,"timeLimit":1000},"Number Spiral":{"name":"Number Spiral","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1071","sampleTestcases":[{"name":"Sample Testcase #1","input":"3\n2 3\n1 1\n4 2\n","output":"8\n1\n15\n"}],"memoryLimit":512,"timeLimit":1000},"Two Knights":{"name":"Two Knights","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1072","sampleTestcases":[{"name":"Sample Testcase #1","input":"8\n","output":"0\n6\n28\n96\n252\n550\n1056\n1848\n"}],"memoryLimit":512,"timeLimit":1000}}},"solutionFiles":{"CSES - CSES Problem Set/Weird_Algorithm.cpp":{"pathString":"CSES - CSES Problem Set/Weird_Algorithm.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Weird Algorithm"},"testcases":[{"name":"Sample Testcase #1","input":"3\n","output":"3 10 5 16 8 4 2 1\n"}]},"CSES - CSES Problem Set/Missing_Number.cpp":{"pathString":"CSES - CSES Problem Set/Missing_Number.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Missing Number"},"testcases":[{"name":"Sample Testcase #1","input":"5\n2 3 1 5\n","output":"4\n"}]},"CSES - CSES Problem Set/Repetitions.cpp":{"pathString":"CSES - CSES Problem Set/Repetitions.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Repetitions"},"testcases":[{"name":"Sample Testcase #1","input":"ATTCGGGA\n","output":"3\n"}]},"CSES - CSES Problem Set/Increasing_Array.cpp":{"pathString":"CSES - CSES Problem Set/Increasing_Array.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Increasing Array"},"testcases":[{"name":"Sample Testcase #1","input":"5\n3 2 5 1 7\n","output":"5\n"}]},"CSES - CSES Problem Set/Permutations.cpp":{"pathString":"CSES - CSES Problem Set/Permutations.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Permutations"},"testcases":[{"name":"Sample Testcase #1","input":"5\n","output":"4 2 5 3 1\n"},{"name":"Sample Testcase #2","input":"3\n","output":"NO SOLUTION\n"}]},"CSES - CSES Problem Set/Number_Spiral.cpp":{"pathString":"CSES - CSES Problem Set/Number_Spiral.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Number Spiral"},"testcases":[{"name":"Sample Testcase #1","input":"3\n2 3\n1 1\n4 2\n","output":"8\n1\n15\n"}]},"CSES - CSES Problem Set/Two_Knights.cpp":{"pathString":"CSES - CSES Problem Set/Two_Knights.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Two Knights"},"testcases":[{"name":"Sample Testcase #1","input":"8\n","output":"0\n6\n28\n96\n252\n550\n1056\n1848\n"}]}}} \ No newline at end of file +{"version":1,"problems":{"CSES - CSES Problem Set":{"Weird Algorithm":{"name":"Weird Algorithm","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1068/","sampleTestcases":[{"name":"Sample Testcase #1","input":"3\n","output":"3 10 5 16 8 4 2 1\n"}],"memoryLimit":512,"timeLimit":1000},"Missing Number":{"name":"Missing Number","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1083","sampleTestcases":[{"name":"Sample Testcase #1","input":"5\n2 3 1 5\n","output":"4\n"}],"memoryLimit":512,"timeLimit":1000},"Repetitions":{"name":"Repetitions","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1069","sampleTestcases":[{"name":"Sample Testcase #1","input":"ATTCGGGA\n","output":"3\n"}],"memoryLimit":512,"timeLimit":1000},"Increasing Array":{"name":"Increasing Array","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1094","sampleTestcases":[{"name":"Sample Testcase #1","input":"5\n3 2 5 1 7\n","output":"5\n"}],"memoryLimit":512,"timeLimit":1000},"Permutations":{"name":"Permutations","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1070","sampleTestcases":[{"name":"Sample Testcase #1","input":"5\n","output":"4 2 5 3 1\n"},{"name":"Sample Testcase #2","input":"3\n","output":"NO SOLUTION\n"}],"memoryLimit":512,"timeLimit":1000},"Number Spiral":{"name":"Number Spiral","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1071","sampleTestcases":[{"name":"Sample Testcase #1","input":"3\n2 3\n1 1\n4 2\n","output":"8\n1\n15\n"}],"memoryLimit":512,"timeLimit":1000},"Two Knights":{"name":"Two Knights","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1072","sampleTestcases":[{"name":"Sample Testcase #1","input":"8\n","output":"0\n6\n28\n96\n252\n550\n1056\n1848\n"}],"memoryLimit":512,"timeLimit":1000},"Two Sets":{"name":"Two Sets","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1092","sampleTestcases":[{"name":"Sample Testcase #1","input":"7\n","output":"YES\n4\n1 2 4 7\n3\n3 5 6\n"},{"name":"Sample Testcase #2","input":"6\n","output":"NO\n"}],"memoryLimit":512,"timeLimit":1000},"Bit Strings":{"name":"Bit Strings","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1617","sampleTestcases":[{"name":"Sample Testcase #1","input":"3\n","output":"8\n"}],"memoryLimit":512,"timeLimit":1000},"Trailing Zeros":{"name":"Trailing Zeros","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1618","sampleTestcases":[{"name":"Sample Testcase #1","input":"20\n","output":"4\n"}],"memoryLimit":512,"timeLimit":1000},"Coin Piles":{"name":"Coin Piles","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1754","sampleTestcases":[{"name":"Sample Testcase #1","input":"3\n2 1\n2 2\n3 3\n","output":"YES\nNO\nYES\n"}],"memoryLimit":512,"timeLimit":1000},"Palindrome Reorder":{"name":"Palindrome Reorder","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1755","sampleTestcases":[{"name":"Sample Testcase #1","input":"AAAACACBA\n","output":"AACABACAA\n"}],"memoryLimit":512,"timeLimit":1000},"Gray Code":{"name":"Gray Code","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/2205","sampleTestcases":[{"name":"Sample Testcase #1","input":"2\n","output":"00\n01\n11\n10\n"}],"memoryLimit":512,"timeLimit":1000},"Tower of Hanoi":{"name":"Tower of Hanoi","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/2165","sampleTestcases":[{"name":"Sample Testcase #1","input":"2\n","output":"3\n1 2\n1 3\n2 3\n"}],"memoryLimit":512,"timeLimit":1000}}},"solutionFiles":{"CSES - CSES Problem Set/Weird_Algorithm.cpp":{"pathString":"CSES - CSES Problem Set/Weird_Algorithm.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Weird Algorithm"},"testcases":[{"name":"Sample Testcase #1","input":"3\n","output":"3 10 5 16 8 4 2 1\n"}]},"CSES - CSES Problem Set/Missing_Number.cpp":{"pathString":"CSES - CSES Problem Set/Missing_Number.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Missing Number"},"testcases":[{"name":"Sample Testcase #1","input":"5\n2 3 1 5\n","output":"4\n"}]},"CSES - CSES Problem Set/Repetitions.cpp":{"pathString":"CSES - CSES Problem Set/Repetitions.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Repetitions"},"testcases":[{"name":"Sample Testcase #1","input":"ATTCGGGA\n","output":"3\n"}]},"CSES - CSES Problem Set/Increasing_Array.cpp":{"pathString":"CSES - CSES Problem Set/Increasing_Array.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Increasing Array"},"testcases":[{"name":"Sample Testcase #1","input":"5\n3 2 5 1 7\n","output":"5\n"}]},"CSES - CSES Problem Set/Permutations.cpp":{"pathString":"CSES - CSES Problem Set/Permutations.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Permutations"},"testcases":[{"name":"Sample Testcase #1","input":"5\n","output":"4 2 5 3 1\n"},{"name":"Sample Testcase #2","input":"3\n","output":"NO SOLUTION\n"}]},"CSES - CSES Problem Set/Number_Spiral.cpp":{"pathString":"CSES - CSES Problem Set/Number_Spiral.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Number Spiral"},"testcases":[{"name":"Sample Testcase #1","input":"3\n2 3\n1 1\n4 2\n","output":"8\n1\n15\n"}]},"CSES - CSES Problem Set/Two_Knights.cpp":{"pathString":"CSES - CSES Problem Set/Two_Knights.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Two Knights"},"testcases":[{"name":"Sample Testcase #1","input":"8\n","output":"0\n6\n28\n96\n252\n550\n1056\n1848\n"}]},"CSES - CSES Problem Set/Two_Sets.cpp":{"pathString":"CSES - CSES Problem Set/Two_Sets.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Two Sets"},"testcases":[{"name":"Sample Testcase #1","input":"7\n","output":"YES\n4\n1 2 4 7\n3\n3 5 6\n"},{"name":"Sample Testcase #2","input":"6\n","output":"NO\n"}]},"CSES - CSES Problem Set/Bit_Strings.cpp":{"pathString":"CSES - CSES Problem Set/Bit_Strings.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Bit Strings"},"testcases":[{"name":"Sample Testcase #1","input":"3\n","output":"8\n"}]},"CSES - CSES Problem Set/Trailing_Zeros.cpp":{"pathString":"CSES - CSES Problem Set/Trailing_Zeros.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Trailing Zeros"},"testcases":[{"name":"Sample Testcase #1","input":"20\n","output":"4\n"}]},"CSES - CSES Problem Set/Coin_Piles.cpp":{"pathString":"CSES - CSES Problem Set/Coin_Piles.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Coin Piles"},"testcases":[{"name":"Sample Testcase #1","input":"3\n2 1\n2 2\n3 3\n","output":"YES\nNO\nYES\n"}]},"CSES - CSES Problem Set/Palindrome_Reorder.cpp":{"pathString":"CSES - CSES Problem Set/Palindrome_Reorder.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Palindrome Reorder"},"testcases":[{"name":"Sample Testcase #1","input":"AAAACACBA\n","output":"AACABACAA\n"}]},"CSES - CSES Problem Set/Gray_Code.cpp":{"pathString":"CSES - CSES Problem Set/Gray_Code.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Gray Code"},"testcases":[{"name":"Sample Testcase #1","input":"2\n","output":"00\n01\n11\n10\n"}]},"CSES - CSES Problem Set/Tower_of_Hanoi.cpp":{"pathString":"CSES - CSES Problem Set/Tower_of_Hanoi.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Tower of Hanoi"},"testcases":[{"name":"Sample Testcase #1","input":"2\n","output":"3\n1 2\n1 3\n2 3\n"}]}}} \ No newline at end of file diff --git a/CSES - CSES Problem Set/Bit_Strings.cpp b/CSES - CSES Problem Set/Bit_Strings.cpp new file mode 100644 index 0000000..7eb4209 --- /dev/null +++ b/CSES - CSES Problem Set/Bit_Strings.cpp @@ -0,0 +1,19 @@ +// Bit Strings + +#include + +using namespace std; +using ll = long long; +ll MOD = 1e9 + 7; + +int main() { + int n; cin >> n; + ll ans = 1; + for (int i{}; i < n; i++) { + ans *= 2; + ans %= MOD; + } + ans %= MOD; + cout << ans; + return 0; +} diff --git a/CSES - CSES Problem Set/Coin_Piles.cpp b/CSES - CSES Problem Set/Coin_Piles.cpp new file mode 100644 index 0000000..c9a6b17 --- /dev/null +++ b/CSES - CSES Problem Set/Coin_Piles.cpp @@ -0,0 +1,23 @@ +// Coin Piles + +#include + +using namespace std; +using ll = long long; + +int main() { + int t; cin >> t; + for (int T{}; T < t; T++) { + ll a, b; cin >> a >> b; + if (a < b) swap(a, b); + if ((a + b) % 3 != 0) { + cout << "NO" << endl; + continue; + } else if (a > 2*b) { + cout << "NO" << endl; + continue; + } + cout << "YES" << endl; + } + return 0; +} diff --git a/CSES - CSES Problem Set/Gray_Code.cpp b/CSES - CSES Problem Set/Gray_Code.cpp new file mode 100644 index 0000000..afb2100 --- /dev/null +++ b/CSES - CSES Problem Set/Gray_Code.cpp @@ -0,0 +1,32 @@ +// Gray Code + +#include + +using namespace std; + +vector gray_code(int size, bool print) { + if (size == 1) { + if (print) { + cout << "0" << '\n' << "1" << endl; + } + return {"0", "1"}; + } + auto prev_gray_code = gray_code(size - 1, false); + vector output; + for (auto &s: prev_gray_code) { + if (print) cout << "0"+s << endl; + output.push_back("0"+s); + } + std::reverse(prev_gray_code.begin(), prev_gray_code.end()); + for (auto &s: prev_gray_code) { + if (print) cout << "1"+s << endl; + output.push_back("1"+s); + } + return output; +} + +int main() { + int n; cin >> n; + gray_code(n, true); + return 0; +} diff --git a/CSES - CSES Problem Set/Palindrome_Reorder.cpp b/CSES - CSES Problem Set/Palindrome_Reorder.cpp new file mode 100644 index 0000000..70a04dc --- /dev/null +++ b/CSES - CSES Problem Set/Palindrome_Reorder.cpp @@ -0,0 +1,31 @@ +// Palindrome Reorder + +#include + +using namespace std; + +int main() { + map char_to_count; + string s; cin >> s; + for (auto c: s) char_to_count[c]++; + string forward; + char middle = ' '; + for (auto &[ch, c]: char_to_count) { + if (c & 1) { + if (middle != ' ') { + cout << "NO SOLUTION" << endl; + return 0; + } + middle = ch; + forward.append(string((c - 1) / 2, ch)); + } else { + forward.append(string(c/2, ch)); + } + } + + cout << forward; + if (middle != ' ') cout << middle; + std::reverse(forward.begin(), forward.end()); + cout << forward << endl; + return 0; +} diff --git a/CSES - CSES Problem Set/Tower_of_Hanoi.cpp b/CSES - CSES Problem Set/Tower_of_Hanoi.cpp new file mode 100644 index 0000000..4094427 --- /dev/null +++ b/CSES - CSES Problem Set/Tower_of_Hanoi.cpp @@ -0,0 +1,38 @@ +// Tower of Hanoi + +#include +using namespace std; + +void hanoi(deque ¤t, deque &destination, deque &tmp, int n, vector> &remember, tuple stack_names) { + if (n == 1) { + auto top = current.back(); + current.pop_back(); + destination.push_back(top); + remember.push_back({get<0>(stack_names), get<1>(stack_names)}); + return; + } + hanoi(current, tmp, destination, n - 1, remember, {get<0>(stack_names), get<2>(stack_names), get<1>(stack_names)}); + auto top = current.back(); + current.pop_back(); + destination.push_back(top); + remember.push_back({get<0>(stack_names), get<1>(stack_names)}); + hanoi(tmp, destination, current, n - 1, remember, {get<2>(stack_names), get<1>(stack_names), get<0>(stack_names)}); + return ; +}; + +int main() { + int size; + cin >> size; + deque start; + deque s2; + deque s3; + for (int i = size; i > 0; i--) { + start.push_front(i); + } + vector> r; //c, t, d + hanoi(start, s2, s3, size, r, {1, 3, 2}); + cout << r.size() << endl; + for (auto &[a, b]: r) cout << a << " " << b << endl; + cout << endl; + return 0; +} \ No newline at end of file diff --git a/CSES - CSES Problem Set/Trailing_Zeros.cpp b/CSES - CSES Problem Set/Trailing_Zeros.cpp new file mode 100644 index 0000000..396fc76 --- /dev/null +++ b/CSES - CSES Problem Set/Trailing_Zeros.cpp @@ -0,0 +1,16 @@ +// Trailing Zeros + +#include + +using namespace std; +using ll = long long; + +int main() { + int count = 0; + ll n; cin >> n; + for (int i = 1; i <= 15; i++) { + count += n / pow(5, i); + } + cout << count; + return 0; +} diff --git a/CSES - CSES Problem Set/Two_Sets.cpp b/CSES - CSES Problem Set/Two_Sets.cpp new file mode 100644 index 0000000..893b2e6 --- /dev/null +++ b/CSES - CSES Problem Set/Two_Sets.cpp @@ -0,0 +1,28 @@ +// Two Sets + +#include + +using namespace std; +using ll = long long; + +int main() { + ll n; cin >> n; + if ((n * (n+1) / 2) & 1) { + cout << "NO" << endl; + return 0; + } + cout << "YES" << endl; + ll target_sum = n * (n+1) / 4; + vector first; + vector second; + for (ll i = n; i > 0; i--) { + if (i <= target_sum) {first.push_back(i); target_sum -= i;} + else second.push_back(i); + } + cout << first.size() << endl; + for (auto e : first) cout << e << " "; + cout << '\n' << second.size() << '\n'; + for (auto e: second) cout << e << " "; + cout << endl; + return 0; +}