From 350518c931e4a9fa8445f47f4dadc019132a7b8a Mon Sep 17 00:00:00 2001 From: omagdy7 Date: Fri, 28 Jul 2023 23:49:17 +0300 Subject: Solved a problem on codeforce div3(A) --- codeforces/CipherShifer/main | Bin 0 -> 24424 bytes codeforces/CipherShifer/main.cpp | 146 +++++++++++++++++++++++++++++++ codeforces/CipherShifer/main_input0.txt | 7 ++ codeforces/CipherShifer/main_output0.txt | 3 + codeforces/YetAnotherPromotion/main | Bin 17832 -> 16728 bytes codeforces/YetAnotherPromotion/main.cpp | 109 ++++++++++++----------- 6 files changed, 215 insertions(+), 50 deletions(-) create mode 100755 codeforces/CipherShifer/main create mode 100755 codeforces/CipherShifer/main.cpp create mode 100644 codeforces/CipherShifer/main_input0.txt create mode 100644 codeforces/CipherShifer/main_output0.txt (limited to 'codeforces') diff --git a/codeforces/CipherShifer/main b/codeforces/CipherShifer/main new file mode 100755 index 0000000..460bc46 Binary files /dev/null and b/codeforces/CipherShifer/main 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 +using namespace std; + +using ll = long long; +using pii = pair; +using vpi = vector; +using vi = vector; +using vll = vector; +using mpii = map; +using mpll = map; +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 +ostream &operator<<(ostream &os, const pair &p); +template ostream &operator<<(ostream &os, const vector &vec); +template +ostream &operator<<(ostream &os, const map &m); +template +ostream &operator<<(ostream &os, const unordered_map &m); +template ostream &operator<<(ostream &os, const set &s); +template +ostream &operator<<(ostream &os, const unordered_set &s); + +template +ostream &operator<<(ostream &os, const pair &p) { + os << "(" << p.first << ", " << p.second << ")"; + return os; +} + +template ostream &operator<<(ostream &os, const vector &vec) { + os << "{"; + for (size_t i = 0; i < vec.size(); ++i) { + if (i > 0) + os << ", "; + os << vec[i]; + } + os << "}"; + return os; +} + +template +ostream &operator<<(ostream &os, const map &m) { + os << "{"; + for (const auto &p : m) { + os << p.first << ": " << p.second << ", "; + } + os << "}"; + return os; +} + +template +ostream &operator<<(ostream &os, const unordered_map &m) { + os << "{"; + for (const auto &p : m) { + os << p.first << ": " << p.second << ", "; + } + os << "}"; + return os; +} + +template ostream &operator<<(ostream &os, const set &s) { + int i = 0; + os << "{"; + for (const auto &e : s) { + if (i > 0) + os << ", "; + os << e; + i++; + } + os << "}"; + return os; +} + +template +ostream &operator<<(ostream &os, const unordered_set &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 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 Binary files a/codeforces/YetAnotherPromotion/main and b/codeforces/YetAnotherPromotion/main 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 +#include using namespace std; using ll = long long; @@ -10,12 +10,14 @@ using mpii = map; using mpll = map; 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 ostream& operator<<(ostream& os, const pair& p); -template ostream& operator<<(ostream& os, const vector& vec); -template ostream& operator<<(ostream& os, const map& m); -template ostream& operator<<(ostream& os, const unordered_map& m); -template ostream& operator<<(ostream& os, const set& s); -template ostream& operator<<(ostream& os, const unordered_set& s); - -template -ostream& operator<<(ostream& os, const pair& p) { +template +ostream &operator<<(ostream &os, const pair &p); +template ostream &operator<<(ostream &os, const vector &vec); +template +ostream &operator<<(ostream &os, const map &m); +template +ostream &operator<<(ostream &os, const unordered_map &m); +template ostream &operator<<(ostream &os, const set &s); +template +ostream &operator<<(ostream &os, const unordered_set &s); + +template +ostream &operator<<(ostream &os, const pair &p) { os << "(" << p.first << ", " << p.second << ")"; return os; } -template -ostream& operator<<(ostream& os, const vector& vec) { +template ostream &operator<<(ostream &os, const vector &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 -ostream& operator<<(ostream& os, const map& m) { +template +ostream &operator<<(ostream &os, const map &m) { os << "{"; - for (const auto& p : m) { + for (const auto &p : m) { os << p.first << ": " << p.second << ", "; } os << "}"; return os; } -template -ostream& operator<<(ostream& os, const unordered_map& m) { +template +ostream &operator<<(ostream &os, const unordered_map &m) { os << "{"; - for (const auto& p : m) { + for (const auto &p : m) { os << p.first << ": " << p.second << ", "; } os << "}"; return os; } -template -ostream& operator<<(ostream& os, const set& s) { +template ostream &operator<<(ostream &os, const set &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& s) { return os; } -template -ostream& operator<<(ostream& os, const unordered_set& s) { +template +ostream &operator<<(ostream &os, const unordered_set &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& s) { return os; } -void print() { - cerr << "\n"; -} +void print() { cerr << "\n"; } -template -void print(T val, TS... vals) { +template 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(); } } - - -- cgit v1.2.3