aboutsummaryrefslogtreecommitdiff
path: root/codeforces
diff options
context:
space:
mode:
authoromagdy7 <omar.professional8777@gmail.com>2023-07-28 23:49:17 +0300
committeromagdy7 <omar.professional8777@gmail.com>2023-07-28 23:49:17 +0300
commit350518c931e4a9fa8445f47f4dadc019132a7b8a (patch)
tree69b386567dd7422ca8545a96686272cc15668fa5 /codeforces
parent75d27a9d569208041107785353aed66b7a50f091 (diff)
downloadcompetitive-programming-350518c931e4a9fa8445f47f4dadc019132a7b8a.tar.xz
competitive-programming-350518c931e4a9fa8445f47f4dadc019132a7b8a.zip
Solved a problem on codeforce div3(A)
Diffstat (limited to 'codeforces')
-rwxr-xr-xcodeforces/CipherShifer/mainbin0 -> 24424 bytes
-rwxr-xr-xcodeforces/CipherShifer/main.cpp146
-rw-r--r--codeforces/CipherShifer/main_input0.txt7
-rw-r--r--codeforces/CipherShifer/main_output0.txt3
-rwxr-xr-xcodeforces/YetAnotherPromotion/mainbin17832 -> 16728 bytes
-rwxr-xr-xcodeforces/YetAnotherPromotion/main.cpp109
6 files changed, 215 insertions, 50 deletions
diff --git a/codeforces/CipherShifer/main b/codeforces/CipherShifer/main
new file mode 100755
index 0000000..460bc46
--- /dev/null
+++ b/codeforces/CipherShifer/main
Binary files differ
diff --git a/codeforces/CipherShifer/main.cpp b/codeforces/CipherShifer/main.cpp
new file mode 100755
index 0000000..190bf49
--- /dev/null
+++ b/codeforces/CipherShifer/main.cpp
@@ -0,0 +1,146 @@
+#include <bits/stdc++.h>
+using namespace std;
+
+using ll = long long;
+using pii = pair<int, int>;
+using vpi = vector<pii>;
+using vi = vector<int>;
+using vll = vector<long long>;
+using mpii = map<int, int>;
+using mpll = map<ll, ll>;
+using db = long double;
+
+#define pb push_back
+#define all(x) (x).begin(), (x).end()
+#define rall(x) (x).rbegin(), (x).rend()
+#define lb lower_bound
+#define ub upper_bound
+#define make_unique(x) \
+ sort(all((x))); \
+ (x).resize(unique(all((x))) - (x).begin())
+#define ceil(a, b) ((a) + (b) - 1) / (b))
+
+const int MOD = (int)1e9 + 7;
+const db PI = acos((db)-1);
+const int dx[4]{1, 0, -1, 0};
+const int dy[4]{0, 1, 0, -1};
+
+template <typename K, typename V>
+ostream &operator<<(ostream &os, const pair<K, V> &p);
+template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec);
+template <typename K, typename V>
+ostream &operator<<(ostream &os, const map<K, V> &m);
+template <typename K, typename V>
+ostream &operator<<(ostream &os, const unordered_map<K, V> &m);
+template <typename T> ostream &operator<<(ostream &os, const set<T> &s);
+template <typename T>
+ostream &operator<<(ostream &os, const unordered_set<T> &s);
+
+template <typename K, typename V>
+ostream &operator<<(ostream &os, const pair<K, V> &p) {
+ os << "(" << p.first << ", " << p.second << ")";
+ return os;
+}
+
+template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
+ os << "{";
+ for (size_t i = 0; i < vec.size(); ++i) {
+ if (i > 0)
+ os << ", ";
+ os << vec[i];
+ }
+ os << "}";
+ return os;
+}
+
+template <typename K, typename V>
+ostream &operator<<(ostream &os, const map<K, V> &m) {
+ os << "{";
+ for (const auto &p : m) {
+ os << p.first << ": " << p.second << ", ";
+ }
+ os << "}";
+ return os;
+}
+
+template <typename K, typename V>
+ostream &operator<<(ostream &os, const unordered_map<K, V> &m) {
+ os << "{";
+ for (const auto &p : m) {
+ os << p.first << ": " << p.second << ", ";
+ }
+ os << "}";
+ return os;
+}
+
+template <typename T> ostream &operator<<(ostream &os, const set<T> &s) {
+ int i = 0;
+ os << "{";
+ for (const auto &e : s) {
+ if (i > 0)
+ os << ", ";
+ os << e;
+ i++;
+ }
+ os << "}";
+ return os;
+}
+
+template <typename T>
+ostream &operator<<(ostream &os, const unordered_set<T> &s) {
+ int i = 0;
+ os << "{";
+ for (const auto &e : s) {
+ if (i > 0)
+ os << ", ";
+ os << e;
+ i++;
+ }
+ os << "}";
+ return os;
+}
+
+void dbg() { cerr << "\n"; }
+
+template <typename T, typename... TS> void dbg(T val, TS... vals) {
+ cerr << val << " ";
+ dbg(vals...);
+}
+
+/* stuff you should look for:
+ ---------------------------
+ * special cases (n=1?)
+ * int overflow, array bounds
+ * do smth instead of nothing and stay organized
+ * WRITE STUFF DOWN
+ * DON'T GET STUCK ON ONE APPROACH
+ */
+
+void solve() {
+ int n;
+ cin >> n;
+ string s;
+ cin >> s;
+ string ans = "";
+ int i = 0;
+ int j = 1;
+ while (i < n) {
+ ans += s[i];
+ while (j < n && s[j] != s[i]) {
+ j++;
+ }
+ i = j + 1;
+ j += 2;
+ }
+ cout << ans << '\n';
+}
+
+int main() {
+ ios_base::sync_with_stdio(false);
+ cin.tie(NULL);
+ int tt;
+ cin >> tt;
+ while (tt--) {
+ solve();
+ }
+}
diff --git a/codeforces/CipherShifer/main_input0.txt b/codeforces/CipherShifer/main_input0.txt
new file mode 100644
index 0000000..a58e56c
--- /dev/null
+++ b/codeforces/CipherShifer/main_input0.txt
@@ -0,0 +1,7 @@
+3
+8
+abacabac
+5
+qzxcq
+20
+ccooddeeffoorrcceess
diff --git a/codeforces/CipherShifer/main_output0.txt b/codeforces/CipherShifer/main_output0.txt
new file mode 100644
index 0000000..a3d9715
--- /dev/null
+++ b/codeforces/CipherShifer/main_output0.txt
@@ -0,0 +1,3 @@
+ac
+q
+codeforces
diff --git a/codeforces/YetAnotherPromotion/main b/codeforces/YetAnotherPromotion/main
index 798f6a8..9b890d0 100755
--- a/codeforces/YetAnotherPromotion/main
+++ b/codeforces/YetAnotherPromotion/main
Binary files differ
diff --git a/codeforces/YetAnotherPromotion/main.cpp b/codeforces/YetAnotherPromotion/main.cpp
index 1bb5eb9..a772000 100755
--- a/codeforces/YetAnotherPromotion/main.cpp
+++ b/codeforces/YetAnotherPromotion/main.cpp
@@ -1,4 +1,4 @@
-#include<bits/stdc++.h>
+#include <bits/stdc++.h>
using namespace std;
using ll = long long;
@@ -10,12 +10,14 @@ using mpii = map<int, int>;
using mpll = map<ll, ll>;
using db = long double;
-#define pb push_back
+#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define lb lower_bound
#define ub upper_bound
-#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
+#define make_unique(x) \
+ sort(all((x))); \
+ (x).resize(unique(all((x))) - (x).begin())
#define ceil(a, b) ((a) + (b) - 1) / (b))
const int MOD = (int)1e9 + 7;
@@ -23,57 +25,60 @@ const db PI = acos((db)-1);
const int dx[4]{1, 0, -1, 0};
const int dy[4]{0, 1, 0, -1};
-template<typename K, typename V> ostream& operator<<(ostream& os, const pair<K, V>& p);
-template<typename T> ostream& operator<<(ostream& os, const vector<T>& vec);
-template<typename K, typename V> ostream& operator<<(ostream& os, const map<K, V>& m);
-template<typename K, typename V> ostream& operator<<(ostream& os, const unordered_map<K, V>& m);
-template<typename T> ostream& operator<<(ostream& os, const set<T>& s);
-template<typename T> ostream& operator<<(ostream& os, const unordered_set<T>& s);
-
-template<typename K, typename V>
-ostream& operator<<(ostream& os, const pair<K, V>& p) {
+template <typename K, typename V>
+ostream &operator<<(ostream &os, const pair<K, V> &p);
+template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec);
+template <typename K, typename V>
+ostream &operator<<(ostream &os, const map<K, V> &m);
+template <typename K, typename V>
+ostream &operator<<(ostream &os, const unordered_map<K, V> &m);
+template <typename T> ostream &operator<<(ostream &os, const set<T> &s);
+template <typename T>
+ostream &operator<<(ostream &os, const unordered_set<T> &s);
+
+template <typename K, typename V>
+ostream &operator<<(ostream &os, const pair<K, V> &p) {
os << "(" << p.first << ", " << p.second << ")";
return os;
}
-template<typename T>
-ostream& operator<<(ostream& os, const vector<T>& vec) {
+template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
os << "{";
for (size_t i = 0; i < vec.size(); ++i) {
- if (i > 0) os << ", ";
+ if (i > 0)
+ os << ", ";
os << vec[i];
}
os << "}";
return os;
}
-
-template<typename K, typename V>
-ostream& operator<<(ostream& os, const map<K, V>& m) {
+template <typename K, typename V>
+ostream &operator<<(ostream &os, const map<K, V> &m) {
os << "{";
- for (const auto& p : m) {
+ for (const auto &p : m) {
os << p.first << ": " << p.second << ", ";
}
os << "}";
return os;
}
-template<typename K, typename V>
-ostream& operator<<(ostream& os, const unordered_map<K, V>& m) {
+template <typename K, typename V>
+ostream &operator<<(ostream &os, const unordered_map<K, V> &m) {
os << "{";
- for (const auto& p : m) {
+ for (const auto &p : m) {
os << p.first << ": " << p.second << ", ";
}
os << "}";
return os;
}
-template<typename T>
-ostream& operator<<(ostream& os, const set<T>& s) {
+template <typename T> ostream &operator<<(ostream &os, const set<T> &s) {
int i = 0;
os << "{";
- for (const auto& e : s) {
- if (i > 0) os << ", ";
+ for (const auto &e : s) {
+ if (i > 0)
+ os << ", ";
os << e;
i++;
}
@@ -81,12 +86,13 @@ ostream& operator<<(ostream& os, const set<T>& s) {
return os;
}
-template<typename T>
-ostream& operator<<(ostream& os, const unordered_set<T>& s) {
+template <typename T>
+ostream &operator<<(ostream &os, const unordered_set<T> &s) {
int i = 0;
os << "{";
- for (const auto& e : s) {
- if (i > 0) os << ", ";
+ for (const auto &e : s) {
+ if (i > 0)
+ os << ", ";
os << e;
i++;
}
@@ -94,18 +100,13 @@ ostream& operator<<(ostream& os, const unordered_set<T>& s) {
return os;
}
-void print() {
- cerr << "\n";
-}
+void print() { cerr << "\n"; }
-template<typename T, typename... TS>
-void print(T val, TS... vals) {
+template <typename T, typename... TS> void print(T val, TS... vals) {
cerr << val << " ";
print(vals...);
}
-
-
/* stuff you should look for:
---------------------------
* special cases (n=1?)
@@ -116,27 +117,35 @@ void print(T val, TS... vals) {
*/
void solve() {
- int a, b;
- cin >> a >> b;
- int n, m;
- cin >> n >> m;
+ ll a, b, n, m;
+ cin >> a >> b >> n >> m;
+ if (m >= n) {
+ cout << min(a, b) * n << '\n';
+ return;
+ }
ll ans = 0;
- ll tmp = (a / (m + 1));
- ans += a * tmp;
- n -= tmp + (tmp / m);
- print(tmp);
- ans += min(a * n, b * n);
+ if (m < n) {
+ if ((a * m) / (m + 1) <= b) {
+ ans += (n * m / (m + 1)) * a;
+ int x = (n * m / (m + 1));
+ n -= x + x / m;
+ } else {
+ ans += b * n;
+ n = 0;
+ }
+ }
+ if (n == 1) {
+ ans += min(a, b);
+ }
cout << ans << '\n';
}
-int main () {
+int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tt;
cin >> tt;
- while(tt--) {
+ while (tt--) {
solve();
}
}
-
-