diff --git a/.autocp b/.autocp new file mode 100644 index 0000000..c567e8f --- /dev/null +++ b/.autocp @@ -0,0 +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 diff --git a/CSES - CSES Problem Set/Increasing_Array.cpp b/CSES - CSES Problem Set/Increasing_Array.cpp new file mode 100644 index 0000000..53adc40 --- /dev/null +++ b/CSES - CSES Problem Set/Increasing_Array.cpp @@ -0,0 +1,22 @@ +// Increasing Array + +#include + +using namespace std; +typedef long long ll; + +int main() { + int n; + cin >> n; + vector array(n); + for (auto &e : array) cin >> e; + ll count = 0; + for (int i = 1; i < n; i++) { + if (array[i] < array[i-1]) { + count += array[i-1] - array[i]; + array[i] = array[i-1]; + } + } + cout << count << endl; + return 0; +} diff --git a/CSES - CSES Problem Set/Missing_Number.cpp b/CSES - CSES Problem Set/Missing_Number.cpp new file mode 100644 index 0000000..e2d1980 --- /dev/null +++ b/CSES - CSES Problem Set/Missing_Number.cpp @@ -0,0 +1,23 @@ +// Missing Number + +#include + +using namespace std; + +int main() { + bitset<2 * (int)1e5> input; + int n; cin >> n; + for (int i{}; i < n; i++) { + int a; cin >> a; + input[a-1] = true; + } + input = ~input; + for (int i = 0; i < n; i++) { + if (input[i]) { + cout << i + 1<< endl; + break; + } + } + return 0; + +} diff --git a/CSES - CSES Problem Set/Number_Spiral.cpp b/CSES - CSES Problem Set/Number_Spiral.cpp new file mode 100644 index 0000000..ec07e0c --- /dev/null +++ b/CSES - CSES Problem Set/Number_Spiral.cpp @@ -0,0 +1,27 @@ +// Number Spiral + +#include + +using namespace std; +using ll = long long; + +int main() { + int t; cin >> t; + for (int i{}; i < t; i++) { + ll x, y; + cin >> y >> x; + + if (y >= x) { + ll yy = y * (y-1) + 1; + if (y & 1) yy -= (y - x); + else yy += (y - x); + cout << yy << endl; + } else { + ll xx = x * (x - 1) + 1; + if (x & 1) xx += (x - y); + else xx -= (x - y); + cout << xx << endl; + } + } + return 0; +} diff --git a/CSES - CSES Problem Set/Permutations.cpp b/CSES - CSES Problem Set/Permutations.cpp new file mode 100644 index 0000000..7f7a306 --- /dev/null +++ b/CSES - CSES Problem Set/Permutations.cpp @@ -0,0 +1,30 @@ +// Permutations + +#include + +using namespace std; + +int main() { + int n; cin >> n; + if (n == 2 || n == 3) { + cout << "NO SOLUTION" << endl; + return 0; + } + if (n & 1) { + for (int i = n; i >= 1; i -= 2) { + cout << i << " "; + } + for (int i = n-1; i > 1; i -= 2) { + cout << i << " "; + } + } else { + for (int i = n - 1; i >= 1; i -= 2) { + cout << i << " "; + } + for (int i = n; i > 1; i -= 2) { + cout << i << " "; + } + } + cout << endl; + return 0; +} diff --git a/CSES - CSES Problem Set/Repetitions.cpp b/CSES - CSES Problem Set/Repetitions.cpp new file mode 100644 index 0000000..06a57a6 --- /dev/null +++ b/CSES - CSES Problem Set/Repetitions.cpp @@ -0,0 +1,25 @@ +// Repetitions + +#include + +using namespace std; + +int main() { + string s; + cin >> s; + int max_count = 0; + int current_count = 0; + char current = ' '; + for (auto c : s) { + if (c == current) { + current_count ++; + max_count = max(max_count, current_count); + } else { + current = c; + current_count = 1; + max_count = max(max_count, current_count); + } + } + cout << max_count << endl; + return 0; +} diff --git a/CSES - CSES Problem Set/Two_Knights.cpp b/CSES - CSES Problem Set/Two_Knights.cpp new file mode 100644 index 0000000..063567b --- /dev/null +++ b/CSES - CSES Problem Set/Two_Knights.cpp @@ -0,0 +1,16 @@ +// Two Knights + +#include + +using namespace std; +using ll = long long; + +int main() { + int n; + cin >> n; + for (ll i = 1; i <= n; i++) { + ll total_possibilities = i * i * (i*i - 1) / 2; + cout << total_possibilities - (4 * (i-1) * (i - 2)) << endl; + } + return 0; +} diff --git a/CSES - CSES Problem Set/Weird_Algorithm.cpp b/CSES - CSES Problem Set/Weird_Algorithm.cpp new file mode 100644 index 0000000..f5f1dc6 --- /dev/null +++ b/CSES - CSES Problem Set/Weird_Algorithm.cpp @@ -0,0 +1,23 @@ +// Weird Algorithm + +#include + +using namespace std; +typedef long long ll; + + +int main() { + ll n; + cin >> n; + while (n != 1) { + cout << n << " "; + if (n & 1) { + n *= 3; + n++; + } else { + n /= 2; + } + } + cout << n << endl; + return 0; +}