first 7 Introductory problems
This commit is contained in:
1
.autocp
Normal file
1
.autocp
Normal file
@@ -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"}]}}}
|
||||
22
CSES - CSES Problem Set/Increasing_Array.cpp
Normal file
22
CSES - CSES Problem Set/Increasing_Array.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
// Increasing Array
|
||||
|
||||
#include<bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
typedef long long ll;
|
||||
|
||||
int main() {
|
||||
int n;
|
||||
cin >> n;
|
||||
vector<ll> 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;
|
||||
}
|
||||
23
CSES - CSES Problem Set/Missing_Number.cpp
Normal file
23
CSES - CSES Problem Set/Missing_Number.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
// Missing Number
|
||||
|
||||
#include<bits/stdc++.h>
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
27
CSES - CSES Problem Set/Number_Spiral.cpp
Normal file
27
CSES - CSES Problem Set/Number_Spiral.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
// Number Spiral
|
||||
|
||||
#include<bits/stdc++.h>
|
||||
|
||||
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;
|
||||
}
|
||||
30
CSES - CSES Problem Set/Permutations.cpp
Normal file
30
CSES - CSES Problem Set/Permutations.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
// Permutations
|
||||
|
||||
#include<bits/stdc++.h>
|
||||
|
||||
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;
|
||||
}
|
||||
25
CSES - CSES Problem Set/Repetitions.cpp
Normal file
25
CSES - CSES Problem Set/Repetitions.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
// Repetitions
|
||||
|
||||
#include<bits/stdc++.h>
|
||||
|
||||
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;
|
||||
}
|
||||
16
CSES - CSES Problem Set/Two_Knights.cpp
Normal file
16
CSES - CSES Problem Set/Two_Knights.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
// Two Knights
|
||||
|
||||
#include<bits/stdc++.h>
|
||||
|
||||
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;
|
||||
}
|
||||
23
CSES - CSES Problem Set/Weird_Algorithm.cpp
Normal file
23
CSES - CSES Problem Set/Weird_Algorithm.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
// Weird Algorithm
|
||||
|
||||
#include<bits/stdc++.h>
|
||||
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user