aboutsummaryrefslogtreecommitdiff
path: root/cses/IntroductoryProblems
diff options
context:
space:
mode:
authoromagdy7 <omar.professional8777@gmail.com>2024-05-27 16:30:12 +0300
committeromagdy7 <omar.professional8777@gmail.com>2024-05-27 16:30:12 +0300
commit5565beca67266d65b28d0c0ad5d1a06178ede73f (patch)
tree9e932a7e8b778bb8b38d60c196881dcd7e2e0d3c /cses/IntroductoryProblems
parent8e8da93654eedfc65e366fa5c97e08b37673fbbc (diff)
downloadcompetitive-programming-5565beca67266d65b28d0c0ad5d1a06178ede73f.tar.xz
competitive-programming-5565beca67266d65b28d0c0ad5d1a06178ede73f.zip
Solved two dp problems on cses
Diffstat (limited to 'cses/IntroductoryProblems')
-rwxr-xr-xcses/IntroductoryProblems/BitStrings/main.cpp11
-rw-r--r--cses/IntroductoryProblems/BitStrings/main_input1.txt1
-rw-r--r--cses/IntroductoryProblems/BitStrings/main_input2.txt1
-rw-r--r--cses/IntroductoryProblems/BitStrings/main_output2.txt1
-rwxr-xr-xcses/IntroductoryProblems/PalindromeReorder/main.cpp44
-rw-r--r--cses/IntroductoryProblems/PalindromeReorder/main_input0.txt1
-rw-r--r--cses/IntroductoryProblems/PalindromeReorder/main_output0.txt1
7 files changed, 41 insertions, 19 deletions
diff --git a/cses/IntroductoryProblems/BitStrings/main.cpp b/cses/IntroductoryProblems/BitStrings/main.cpp
index cb4a7fb..480a9ae 100755
--- a/cses/IntroductoryProblems/BitStrings/main.cpp
+++ b/cses/IntroductoryProblems/BitStrings/main.cpp
@@ -1,16 +1,17 @@
-#include<bits/stdc++.h>
+#include <bits/stdc++.h>
using namespace std;
-int main () {
+int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
int m = 1e9 + 7;
cin >> n;
- long long ans = 0;
- while(n--) {
- ans += ((2 % m) * (2 % m)) % m;
+ n--;
+ long long ans = 2;
+ while (n--) {
+ ans = ((ans % m) * 2) % m;
}
cout << ans << '\n';
}
diff --git a/cses/IntroductoryProblems/BitStrings/main_input1.txt b/cses/IntroductoryProblems/BitStrings/main_input1.txt
new file mode 100644
index 0000000..c793025
--- /dev/null
+++ b/cses/IntroductoryProblems/BitStrings/main_input1.txt
@@ -0,0 +1 @@
+7 \ No newline at end of file
diff --git a/cses/IntroductoryProblems/BitStrings/main_input2.txt b/cses/IntroductoryProblems/BitStrings/main_input2.txt
new file mode 100644
index 0000000..c793025
--- /dev/null
+++ b/cses/IntroductoryProblems/BitStrings/main_input2.txt
@@ -0,0 +1 @@
+7 \ No newline at end of file
diff --git a/cses/IntroductoryProblems/BitStrings/main_output2.txt b/cses/IntroductoryProblems/BitStrings/main_output2.txt
new file mode 100644
index 0000000..b854a29
--- /dev/null
+++ b/cses/IntroductoryProblems/BitStrings/main_output2.txt
@@ -0,0 +1 @@
+128 \ No newline at end of file
diff --git a/cses/IntroductoryProblems/PalindromeReorder/main.cpp b/cses/IntroductoryProblems/PalindromeReorder/main.cpp
index 411cda8..7875dec 100755
--- a/cses/IntroductoryProblems/PalindromeReorder/main.cpp
+++ b/cses/IntroductoryProblems/PalindromeReorder/main.cpp
@@ -1,10 +1,10 @@
-#include<bits/stdc++.h>
+#include <bits/stdc++.h>
using namespace std;
-int main () {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
+int main() {
+ ios_base::sync_with_stdio(false);
+ cin.tie(NULL);
int n;
string s;
cin >> s;
@@ -13,18 +13,34 @@ int main () {
for (auto ch : s) {
mp[ch]++;
}
- if (n & 1) {
- for (auto [key, value] : mp) {
- if (value & 1) {
- o++;
- } else {
- e++;
+ string ans = "";
+ int odds = 0;
+ for (auto [key, value] : mp) {
+ if (value % 2 == 0) {
+ for (int i = 0; i < value / 2; i++) {
+ ans += key;
}
}
- if (o > 1) {
- cout << "NO SOLUTION" << '\n';
- }
+ }
+ for (auto [key, value] : mp) {
+ if (value % 2 != 0) {
+ odds++;
+ for (int i = 0; i < value; i++) {
+ ans += key;
+ }
+ }
+ }
+ for (auto it = mp.rbegin(); it != mp.rend(); ++it) {
+ auto [key, value] = *it;
+ if (value % 2 == 0) {
+ for (int i = 0; i < value / 2; i++) {
+ ans += key;
+ }
+ }
+ }
+ if (odds > 1) {
+ cout << "NO SOLUTION\n";
} else {
-
+ cout << ans << '\n';
}
}
diff --git a/cses/IntroductoryProblems/PalindromeReorder/main_input0.txt b/cses/IntroductoryProblems/PalindromeReorder/main_input0.txt
new file mode 100644
index 0000000..74ef623
--- /dev/null
+++ b/cses/IntroductoryProblems/PalindromeReorder/main_input0.txt
@@ -0,0 +1 @@
+AAAACACBA
diff --git a/cses/IntroductoryProblems/PalindromeReorder/main_output0.txt b/cses/IntroductoryProblems/PalindromeReorder/main_output0.txt
new file mode 100644
index 0000000..9eea27d
--- /dev/null
+++ b/cses/IntroductoryProblems/PalindromeReorder/main_output0.txt
@@ -0,0 +1 @@
+AACABACAA