From ba391960d9d26180335fccc2f3d593021324de76 Mon Sep 17 00:00:00 2001 From: omagdy7 Date: Sun, 19 Mar 2023 11:58:33 +0200 Subject: Solved new problems from codeforces --- codeforces/CormenTheBestFriendOfAMan/main | Bin 0 -> 22296 bytes codeforces/CormenTheBestFriendOfAMan/main.cpp | 17 +++ .../CormenTheBestFriendOfAMan/main_input0.txt | 2 + .../CormenTheBestFriendOfAMan/main_input1.txt | 2 + .../CormenTheBestFriendOfAMan/main_input2.txt | 2 + .../CormenTheBestFriendOfAMan/main_output0.txt | 2 + .../CormenTheBestFriendOfAMan/main_output1.txt | 2 + .../CormenTheBestFriendOfAMan/main_output2.txt | 2 + codeforces/EqualizeByDivide/main | Bin 0 -> 41840 bytes codeforces/EqualizeByDivide/main.cpp | 117 +++++++++++++++ codeforces/EqualizeByDivide/main_input0.txt | 21 +++ codeforces/EqualizeByDivide/main_output0.txt | 43 ++++++ codeforces/IdealPoint/main | Bin 0 -> 22064 bytes codeforces/IdealPoint/main.cpp | 116 +++++++++++++++ codeforces/IdealPoint/main_input0.txt | 15 ++ codeforces/IdealPoint/main_output0.txt | 4 + codeforces/MexMaster/main | Bin 0 -> 22520 bytes codeforces/MexMaster/main.cpp | 153 +++++++++++++++++++ codeforces/MexMaster/main_input0.txt | 7 + codeforces/MexMaster/main_output0.txt | 3 + codeforces/MonstersEasy/main | Bin 0 -> 39880 bytes codeforces/MonstersEasy/main.cpp | 153 +++++++++++++++++++ codeforces/MonstersEasy/main_input0.txt | 5 + codeforces/MonstersEasy/main_input1.txt | 3 + codeforces/MonstersEasy/main_input2.txt | 3 + codeforces/MonstersEasy/main_input3.txt | 3 + codeforces/MonstersEasy/main_input4.txt | 3 + codeforces/MonstersEasy/main_input5.txt | 3 + codeforces/MonstersEasy/main_input6.txt | 3 + codeforces/MonstersEasy/main_input7.txt | 3 + codeforces/MonstersEasy/main_input8.txt | 3 + codeforces/MonstersEasy/main_output0.txt | 2 + codeforces/MonstersEasy/main_output1.txt | 1 + codeforces/MonstersEasy/main_output2.txt | 1 + codeforces/MonstersEasy/main_output3.txt | 1 + codeforces/MonstersEasy/main_output4.txt | 1 + codeforces/MonstersEasy/main_output5.txt | 1 + codeforces/MonstersEasy/main_output6.txt | 1 + codeforces/MonstersEasy/main_output7.txt | 1 + codeforces/MonstersEasy/main_output8.txt | 1 + codeforces/NonAlternatingDeckEasy/main | Bin 0 -> 17912 bytes codeforces/NonAlternatingDeckEasy/main.cpp | 148 +++++++++++++++++++ codeforces/NonAlternatingDeckEasy/main_input0.txt | 6 + codeforces/NonAlternatingDeckEasy/main_output0.txt | 5 + codeforces/NonAlternatingDeckHard/main | Bin 0 -> 26232 bytes codeforces/NonAlternatingDeckHard/main.cpp | 162 +++++++++++++++++++++ codeforces/NonAlternatingDeckHard/main_input0.txt | 6 + codeforces/NonAlternatingDeckHard/main_output0.txt | 5 + codeforces/PolycarpRecoversThePermutation/main.cpp | 138 ++++++++++++++++++ codeforces/RecentActions/main | Bin 0 -> 72984 bytes codeforces/RecentActions/main.cpp | 119 +++++++++++++++ codeforces/RecentActions/main_input0.txt | 21 +++ codeforces/RecentActions/main_output0.txt | 10 ++ .../main | Bin 0 -> 17896 bytes .../main.cpp | 148 +++++++++++++++++++ .../main_input0.txt | 7 + .../main_output0.txt | 6 + codeforces/TwoTowers/main | Bin 0 -> 28920 bytes codeforces/TwoTowers/main.cpp | 113 ++++++++++++++ codeforces/TwoTowers/main_input0.txt | 13 ++ codeforces/TwoTowers/main_output0.txt | 4 + codeforces/TwoTowers/mainl.cpp | 0 codeforces/TwoTowers/mainl_input0.txt | 13 ++ codeforces/TwoTowers/mainl_output0.txt | 4 + codeforces/WalkingMaster/main | Bin 0 -> 17784 bytes codeforces/WalkingMaster/main.cpp | 142 ++++++++++++++++++ codeforces/WalkingMaster/main_input0.txt | 7 + codeforces/WalkingMaster/main_output0.txt | 6 + 68 files changed, 1783 insertions(+) create mode 100755 codeforces/CormenTheBestFriendOfAMan/main create mode 100644 codeforces/CormenTheBestFriendOfAMan/main_input0.txt create mode 100644 codeforces/CormenTheBestFriendOfAMan/main_input1.txt create mode 100644 codeforces/CormenTheBestFriendOfAMan/main_input2.txt create mode 100644 codeforces/CormenTheBestFriendOfAMan/main_output0.txt create mode 100644 codeforces/CormenTheBestFriendOfAMan/main_output1.txt create mode 100644 codeforces/CormenTheBestFriendOfAMan/main_output2.txt create mode 100755 codeforces/EqualizeByDivide/main create mode 100755 codeforces/EqualizeByDivide/main.cpp create mode 100644 codeforces/EqualizeByDivide/main_input0.txt create mode 100644 codeforces/EqualizeByDivide/main_output0.txt create mode 100755 codeforces/IdealPoint/main create mode 100755 codeforces/IdealPoint/main.cpp create mode 100644 codeforces/IdealPoint/main_input0.txt create mode 100644 codeforces/IdealPoint/main_output0.txt create mode 100755 codeforces/MexMaster/main create mode 100755 codeforces/MexMaster/main.cpp create mode 100644 codeforces/MexMaster/main_input0.txt create mode 100644 codeforces/MexMaster/main_output0.txt create mode 100755 codeforces/MonstersEasy/main create mode 100755 codeforces/MonstersEasy/main.cpp create mode 100644 codeforces/MonstersEasy/main_input0.txt create mode 100644 codeforces/MonstersEasy/main_input1.txt create mode 100644 codeforces/MonstersEasy/main_input2.txt create mode 100644 codeforces/MonstersEasy/main_input3.txt create mode 100644 codeforces/MonstersEasy/main_input4.txt create mode 100644 codeforces/MonstersEasy/main_input5.txt create mode 100644 codeforces/MonstersEasy/main_input6.txt create mode 100644 codeforces/MonstersEasy/main_input7.txt create mode 100644 codeforces/MonstersEasy/main_input8.txt create mode 100644 codeforces/MonstersEasy/main_output0.txt create mode 100644 codeforces/MonstersEasy/main_output1.txt create mode 100644 codeforces/MonstersEasy/main_output2.txt create mode 100644 codeforces/MonstersEasy/main_output3.txt create mode 100644 codeforces/MonstersEasy/main_output4.txt create mode 100644 codeforces/MonstersEasy/main_output5.txt create mode 100644 codeforces/MonstersEasy/main_output6.txt create mode 100644 codeforces/MonstersEasy/main_output7.txt create mode 100644 codeforces/MonstersEasy/main_output8.txt create mode 100755 codeforces/NonAlternatingDeckEasy/main create mode 100755 codeforces/NonAlternatingDeckEasy/main.cpp create mode 100644 codeforces/NonAlternatingDeckEasy/main_input0.txt create mode 100644 codeforces/NonAlternatingDeckEasy/main_output0.txt create mode 100755 codeforces/NonAlternatingDeckHard/main create mode 100755 codeforces/NonAlternatingDeckHard/main.cpp create mode 100644 codeforces/NonAlternatingDeckHard/main_input0.txt create mode 100644 codeforces/NonAlternatingDeckHard/main_output0.txt create mode 100755 codeforces/PolycarpRecoversThePermutation/main.cpp create mode 100755 codeforces/RecentActions/main create mode 100755 codeforces/RecentActions/main.cpp create mode 100644 codeforces/RecentActions/main_input0.txt create mode 100644 codeforces/RecentActions/main_output0.txt create mode 100755 codeforces/TeamCompositinoProgrammersAndMathmaticians/main create mode 100755 codeforces/TeamCompositinoProgrammersAndMathmaticians/main.cpp create mode 100644 codeforces/TeamCompositinoProgrammersAndMathmaticians/main_input0.txt create mode 100644 codeforces/TeamCompositinoProgrammersAndMathmaticians/main_output0.txt create mode 100755 codeforces/TwoTowers/main create mode 100755 codeforces/TwoTowers/main.cpp create mode 100644 codeforces/TwoTowers/main_input0.txt create mode 100644 codeforces/TwoTowers/main_output0.txt create mode 100644 codeforces/TwoTowers/mainl.cpp create mode 100644 codeforces/TwoTowers/mainl_input0.txt create mode 100644 codeforces/TwoTowers/mainl_output0.txt create mode 100755 codeforces/WalkingMaster/main create mode 100755 codeforces/WalkingMaster/main.cpp create mode 100644 codeforces/WalkingMaster/main_input0.txt create mode 100644 codeforces/WalkingMaster/main_output0.txt diff --git a/codeforces/CormenTheBestFriendOfAMan/main b/codeforces/CormenTheBestFriendOfAMan/main new file mode 100755 index 0000000..43222bb Binary files /dev/null and b/codeforces/CormenTheBestFriendOfAMan/main differ diff --git a/codeforces/CormenTheBestFriendOfAMan/main.cpp b/codeforces/CormenTheBestFriendOfAMan/main.cpp index 25db2b2..4e41dad 100755 --- a/codeforces/CormenTheBestFriendOfAMan/main.cpp +++ b/codeforces/CormenTheBestFriendOfAMan/main.cpp @@ -22,10 +22,27 @@ const db PI = acos((db)-1); const int dx[4]{1, 0, -1, 0}; const int dy[4]{0, 1, 0, -1}; +// v[i + 1] + v[i] = k + void solve() { int n, k; cin >> n >> k; vi v(n); + for (auto &x : v) cin >> x; + vi ans(n); + int cnt = 0; + for (int i = 0; i < n - 1; i++) { + if (v[i] + v[i + 1] < k) { + int aw = k - v[i]; + cnt += aw - v[i + 1]; + v[i + 1] = aw; + } + } + cout << cnt << '\n'; + for (auto x : v) { + cout << x << ' '; + } + cout << '\n'; } diff --git a/codeforces/CormenTheBestFriendOfAMan/main_input0.txt b/codeforces/CormenTheBestFriendOfAMan/main_input0.txt new file mode 100644 index 0000000..6642156 --- /dev/null +++ b/codeforces/CormenTheBestFriendOfAMan/main_input0.txt @@ -0,0 +1,2 @@ +3 5 +2 0 1 diff --git a/codeforces/CormenTheBestFriendOfAMan/main_input1.txt b/codeforces/CormenTheBestFriendOfAMan/main_input1.txt new file mode 100644 index 0000000..2e3b056 --- /dev/null +++ b/codeforces/CormenTheBestFriendOfAMan/main_input1.txt @@ -0,0 +1,2 @@ +3 1 +0 0 0 diff --git a/codeforces/CormenTheBestFriendOfAMan/main_input2.txt b/codeforces/CormenTheBestFriendOfAMan/main_input2.txt new file mode 100644 index 0000000..d0085cf --- /dev/null +++ b/codeforces/CormenTheBestFriendOfAMan/main_input2.txt @@ -0,0 +1,2 @@ +4 6 +2 4 3 5 diff --git a/codeforces/CormenTheBestFriendOfAMan/main_output0.txt b/codeforces/CormenTheBestFriendOfAMan/main_output0.txt new file mode 100644 index 0000000..0639b2b --- /dev/null +++ b/codeforces/CormenTheBestFriendOfAMan/main_output0.txt @@ -0,0 +1,2 @@ +4 +2 3 2 diff --git a/codeforces/CormenTheBestFriendOfAMan/main_output1.txt b/codeforces/CormenTheBestFriendOfAMan/main_output1.txt new file mode 100644 index 0000000..4fd2a3f --- /dev/null +++ b/codeforces/CormenTheBestFriendOfAMan/main_output1.txt @@ -0,0 +1,2 @@ +1 +0 1 0 diff --git a/codeforces/CormenTheBestFriendOfAMan/main_output2.txt b/codeforces/CormenTheBestFriendOfAMan/main_output2.txt new file mode 100644 index 0000000..9b66e1b --- /dev/null +++ b/codeforces/CormenTheBestFriendOfAMan/main_output2.txt @@ -0,0 +1,2 @@ +0 +2 4 3 5 diff --git a/codeforces/EqualizeByDivide/main b/codeforces/EqualizeByDivide/main new file mode 100755 index 0000000..2adc6ce Binary files /dev/null and b/codeforces/EqualizeByDivide/main differ diff --git a/codeforces/EqualizeByDivide/main.cpp b/codeforces/EqualizeByDivide/main.cpp new file mode 100755 index 0000000..1c22f4e --- /dev/null +++ b/codeforces/EqualizeByDivide/main.cpp @@ -0,0 +1,117 @@ +#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 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}; + +//pretty printing +template +void printm(const map &mp) { + cerr << "{" << endl; + for (auto p : mp) { + cerr << " { " << p.first << " : " << p.second << " }\n"; + } + cerr << "}" << endl; +} +template +void printv(const vector &v) { + cerr << "["; + for (int i = 0; i < v.size(); i++) { + if (i == v.size() - 1) { + cerr << v[i]; + } else { + cerr << v[i] << ", "; + } + } + cerr << "]\n"; +} + +template +void printvv(const vector> &v) { + cerr << "[\n"; + for (auto &vec : v) { + cout << " "; + printv(vec); + } + cerr << "]\n"; +} +void print() { + cerr << "\n"; +} + +template +void print(T val, TS... vals) { + cerr << val << " "; + print(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; + vi v(n); + for (auto &x : v) cin >> x; + auto isEqual = [&](vi &a) { + return count(all(a), a[0]) == a.size(); + }; + + int ans = 0; + vector p; + while (!isEqual(v)) { + if (ans > n * 30) {cout << -1 << '\n'; return;}; + auto imx = max_element(all(v)) - v.begin(); + auto imn = min_element(all(v)) - v.begin(); + int mx = *max_element(all(v)); + int mn = *min_element(all(v)); + p.push_back({imx + 1, imn + 1}); + v[imx] = ceil((double)mx / mn); + ans++; + } + cout << ans << '\n'; + for (int i = 0; i < ans; i++) { + cout << p[i].first << ' ' << p[i].second << '\n'; + } + +} + +int main () { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while(tt--) { + solve(); + } +} + + diff --git a/codeforces/EqualizeByDivide/main_input0.txt b/codeforces/EqualizeByDivide/main_input0.txt new file mode 100644 index 0000000..5d32c10 --- /dev/null +++ b/codeforces/EqualizeByDivide/main_input0.txt @@ -0,0 +1,21 @@ +10 +1 +100 +3 +1 1 1 +2 +2 1 +2 +5 5 +3 +4 3 2 +4 +3 3 4 4 +2 +2 100 +5 +5 3 6 7 8 +6 +3 3 80 3 8 3 +4 +19 40 19 55 diff --git a/codeforces/EqualizeByDivide/main_output0.txt b/codeforces/EqualizeByDivide/main_output0.txt new file mode 100644 index 0000000..642f8e4 --- /dev/null +++ b/codeforces/EqualizeByDivide/main_output0.txt @@ -0,0 +1,43 @@ +0 +0 +-1 +0 +2 +1 3 +2 1 +4 +3 1 +4 2 +1 3 +2 4 +6 +2 1 +2 1 +2 1 +2 1 +2 1 +2 1 +8 +5 2 +4 2 +3 2 +1 3 +1 3 +2 1 +4 1 +5 1 +4 +5 1 +3 1 +3 1 +3 1 +9 +4 2 +2 1 +1 2 +1 2 +3 2 +3 2 +1 4 +2 4 +3 4 diff --git a/codeforces/IdealPoint/main b/codeforces/IdealPoint/main new file mode 100755 index 0000000..cdd18a8 Binary files /dev/null and b/codeforces/IdealPoint/main differ diff --git a/codeforces/IdealPoint/main.cpp b/codeforces/IdealPoint/main.cpp new file mode 100755 index 0000000..fdd9d35 --- /dev/null +++ b/codeforces/IdealPoint/main.cpp @@ -0,0 +1,116 @@ +#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 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}; + +//pretty printing +template +void printm(const map &mp) { + cerr << "{" << endl; + for (auto p : mp) { + cerr << " { " << p.first << " : " << p.second << " }\n"; + } + cerr << "}" << endl; +} +template +void printv(const vector &v) { + cerr << "["; + for (int i = 0; i < v.size(); i++) { + if (i == v.size() - 1) { + cerr << v[i]; + } else { + cerr << v[i] << ", "; + } + } + cerr << "]\n"; +} + +template +void printvv(const vector> &v) { + cerr << "[\n"; + for (auto &vec : v) { + cout << " "; + printv(vec); + } + cerr << "]\n"; +} +void print() { + cerr << "\n"; +} + +template +void print(T val, TS... vals) { + cerr << val << " "; + print(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 add(vi &v, int l, int r) { + for (int i = l; i <= r; i++) { + v[i]++; + } +} + + +void solve() { + int n, k; + cin >> n >> k; + int cnt = 0; + vi v(51); + for (int i = 0; i < n; i++) { + int l, r; + cin >> l >> r; + if (k >= l && k <= r) { + add(v, l, r); + } + } + for (int i = 1; i < v.size(); i++) { + if (v[k] <= v[i] && i != k) { + cout << "NO\n"; + return; + } + } + cout << "YES\n"; +} + +int main () { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while(tt--) { + solve(); + } +} + + diff --git a/codeforces/IdealPoint/main_input0.txt b/codeforces/IdealPoint/main_input0.txt new file mode 100644 index 0000000..284f7f3 --- /dev/null +++ b/codeforces/IdealPoint/main_input0.txt @@ -0,0 +1,15 @@ +4 +4 3 +1 3 +7 9 +2 5 +3 6 +2 9 +1 4 +3 7 +1 3 +2 4 +3 5 +1 4 +6 7 +5 5 diff --git a/codeforces/IdealPoint/main_output0.txt b/codeforces/IdealPoint/main_output0.txt new file mode 100644 index 0000000..c8cd351 --- /dev/null +++ b/codeforces/IdealPoint/main_output0.txt @@ -0,0 +1,4 @@ +YES +NO +NO +YES diff --git a/codeforces/MexMaster/main b/codeforces/MexMaster/main new file mode 100755 index 0000000..a0d3157 Binary files /dev/null and b/codeforces/MexMaster/main differ diff --git a/codeforces/MexMaster/main.cpp b/codeforces/MexMaster/main.cpp new file mode 100755 index 0000000..92727d0 --- /dev/null +++ b/codeforces/MexMaster/main.cpp @@ -0,0 +1,153 @@ +#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 print() { + cerr << "\n"; +} + +template +void print(T val, TS... vals) { + cerr << val << " "; + print(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 + */ + +// 1 1 0 0 0 0 +// 1 1 0 0 0 0 + +void solve() { + int n; + cin >> n; + vi v(n); + int zrs = 0; + int ons = 0; + for (auto &x : v) { + cin >> x; + zrs += (x == 0); + ons += (x == 1); + } + if (zrs <= ceil(n, 2)) { + cout << 0 << '\n'; + } else { + if (ons + zrs == n && ons != 0) { + cout << 2 << '\n'; + } else { + cout << 1 << '\n'; + } + } +} + +int main () { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while(tt--) { + solve(); + } +} + + diff --git a/codeforces/MexMaster/main_input0.txt b/codeforces/MexMaster/main_input0.txt new file mode 100644 index 0000000..62587c3 --- /dev/null +++ b/codeforces/MexMaster/main_input0.txt @@ -0,0 +1,7 @@ +3 +2 +0 0 +3 +0 0 1 +8 +1 0 0 0 2 0 3 0 diff --git a/codeforces/MexMaster/main_output0.txt b/codeforces/MexMaster/main_output0.txt new file mode 100644 index 0000000..16db301 --- /dev/null +++ b/codeforces/MexMaster/main_output0.txt @@ -0,0 +1,3 @@ +1 +0 +1 diff --git a/codeforces/MonstersEasy/main b/codeforces/MonstersEasy/main new file mode 100755 index 0000000..72fb34c Binary files /dev/null and b/codeforces/MonstersEasy/main differ diff --git a/codeforces/MonstersEasy/main.cpp b/codeforces/MonstersEasy/main.cpp new file mode 100755 index 0000000..3afe488 --- /dev/null +++ b/codeforces/MonstersEasy/main.cpp @@ -0,0 +1,153 @@ +#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 print() { + cerr << "\n"; +} + +template +void print(T val, TS... vals) { + cerr << val << " "; + print(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 + */ + +// 1 1 1 4 4 5 = 16 +// 1 1 1 2 3 4 = 12 +// 2 3 3 3 4 5 +// 1 2 3 3 4 5 +void solve() { + int n; + cin >> n; + vi v(n); + for (auto &x : v) { + cin >> x; + } + sort(all(v)); + int j = 1; + ll ans = 0; + for (int i = 0; i < n; i++) { + if (v[i] > j && i != 0) { + j++; + } + print(v[i], j); + ans += v[i] - j; + } + 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/MonstersEasy/main_input0.txt b/codeforces/MonstersEasy/main_input0.txt new file mode 100644 index 0000000..87d1499 --- /dev/null +++ b/codeforces/MonstersEasy/main_input0.txt @@ -0,0 +1,5 @@ +2 +3 +3 1 2 +6 +4 1 5 4 1 1 diff --git a/codeforces/MonstersEasy/main_input1.txt b/codeforces/MonstersEasy/main_input1.txt new file mode 100644 index 0000000..3649d3e --- /dev/null +++ b/codeforces/MonstersEasy/main_input1.txt @@ -0,0 +1,3 @@ +1 +10 +8 8 8 7 6 5 4 3 3 3 \ No newline at end of file diff --git a/codeforces/MonstersEasy/main_input2.txt b/codeforces/MonstersEasy/main_input2.txt new file mode 100644 index 0000000..e24bc32 --- /dev/null +++ b/codeforces/MonstersEasy/main_input2.txt @@ -0,0 +1,3 @@ +1 +11 +3 3 5 7 4 6 3 10 9 8 2 \ No newline at end of file diff --git a/codeforces/MonstersEasy/main_input3.txt b/codeforces/MonstersEasy/main_input3.txt new file mode 100644 index 0000000..946e596 --- /dev/null +++ b/codeforces/MonstersEasy/main_input3.txt @@ -0,0 +1,3 @@ +1 +9 +1 1 1 2 2 2 3 3 3 \ No newline at end of file diff --git a/codeforces/MonstersEasy/main_input4.txt b/codeforces/MonstersEasy/main_input4.txt new file mode 100644 index 0000000..d3cb46f --- /dev/null +++ b/codeforces/MonstersEasy/main_input4.txt @@ -0,0 +1,3 @@ +1 +1 +4 \ No newline at end of file diff --git a/codeforces/MonstersEasy/main_input5.txt b/codeforces/MonstersEasy/main_input5.txt new file mode 100644 index 0000000..ae7dd0b --- /dev/null +++ b/codeforces/MonstersEasy/main_input5.txt @@ -0,0 +1,3 @@ +1 +1 +1 \ No newline at end of file diff --git a/codeforces/MonstersEasy/main_input6.txt b/codeforces/MonstersEasy/main_input6.txt new file mode 100644 index 0000000..a3f7138 --- /dev/null +++ b/codeforces/MonstersEasy/main_input6.txt @@ -0,0 +1,3 @@ +1 +3 +10 10 10 \ No newline at end of file diff --git a/codeforces/MonstersEasy/main_input7.txt b/codeforces/MonstersEasy/main_input7.txt new file mode 100644 index 0000000..5b87f4c --- /dev/null +++ b/codeforces/MonstersEasy/main_input7.txt @@ -0,0 +1,3 @@ +1 +6 +5 5 5 4 4 4 \ No newline at end of file diff --git a/codeforces/MonstersEasy/main_input8.txt b/codeforces/MonstersEasy/main_input8.txt new file mode 100644 index 0000000..aa68cba --- /dev/null +++ b/codeforces/MonstersEasy/main_input8.txt @@ -0,0 +1,3 @@ +1 +1 +2 \ No newline at end of file diff --git a/codeforces/MonstersEasy/main_output0.txt b/codeforces/MonstersEasy/main_output0.txt new file mode 100644 index 0000000..4f1d7cd --- /dev/null +++ b/codeforces/MonstersEasy/main_output0.txt @@ -0,0 +1,2 @@ +0 +4 diff --git a/codeforces/MonstersEasy/main_output1.txt b/codeforces/MonstersEasy/main_output1.txt new file mode 100644 index 0000000..8e2afd3 --- /dev/null +++ b/codeforces/MonstersEasy/main_output1.txt @@ -0,0 +1 @@ +17 \ No newline at end of file diff --git a/codeforces/MonstersEasy/main_output2.txt b/codeforces/MonstersEasy/main_output2.txt new file mode 100644 index 0000000..d8263ee --- /dev/null +++ b/codeforces/MonstersEasy/main_output2.txt @@ -0,0 +1 @@ +2 \ No newline at end of file diff --git a/codeforces/MonstersEasy/main_output3.txt b/codeforces/MonstersEasy/main_output3.txt new file mode 100644 index 0000000..c227083 --- /dev/null +++ b/codeforces/MonstersEasy/main_output3.txt @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/codeforces/MonstersEasy/main_output4.txt b/codeforces/MonstersEasy/main_output4.txt new file mode 100644 index 0000000..e440e5c --- /dev/null +++ b/codeforces/MonstersEasy/main_output4.txt @@ -0,0 +1 @@ +3 \ No newline at end of file diff --git a/codeforces/MonstersEasy/main_output5.txt b/codeforces/MonstersEasy/main_output5.txt new file mode 100644 index 0000000..c227083 --- /dev/null +++ b/codeforces/MonstersEasy/main_output5.txt @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/codeforces/MonstersEasy/main_output6.txt b/codeforces/MonstersEasy/main_output6.txt new file mode 100644 index 0000000..cabf43b --- /dev/null +++ b/codeforces/MonstersEasy/main_output6.txt @@ -0,0 +1 @@ +24 \ No newline at end of file diff --git a/codeforces/MonstersEasy/main_output7.txt b/codeforces/MonstersEasy/main_output7.txt new file mode 100644 index 0000000..62f9457 --- /dev/null +++ b/codeforces/MonstersEasy/main_output7.txt @@ -0,0 +1 @@ +6 \ No newline at end of file diff --git a/codeforces/MonstersEasy/main_output8.txt b/codeforces/MonstersEasy/main_output8.txt new file mode 100644 index 0000000..56a6051 --- /dev/null +++ b/codeforces/MonstersEasy/main_output8.txt @@ -0,0 +1 @@ +1 \ No newline at end of file diff --git a/codeforces/NonAlternatingDeckEasy/main b/codeforces/NonAlternatingDeckEasy/main new file mode 100755 index 0000000..e42ecfd Binary files /dev/null and b/codeforces/NonAlternatingDeckEasy/main differ diff --git a/codeforces/NonAlternatingDeckEasy/main.cpp b/codeforces/NonAlternatingDeckEasy/main.cpp new file mode 100755 index 0000000..281ae8b --- /dev/null +++ b/codeforces/NonAlternatingDeckEasy/main.cpp @@ -0,0 +1,148 @@ +#include +#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 print() { + cerr << "\n"; +} + +template +void print(T val, TS... vals) { + cerr << val << " "; + print(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; + int alice = 0, bob = 0; + int i = 1; + while (n > 0) { + if (i % 2 == 1) { + alice += i <= n ? i : n; + n -= i; + } + else { + bob += i <= n ? i : n; + n -= i; + } + i++; + } + cout << alice << " " << bob << endl; +} + +int main () { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while(tt--) { + solve(); + } +} + + diff --git a/codeforces/NonAlternatingDeckEasy/main_input0.txt b/codeforces/NonAlternatingDeckEasy/main_input0.txt new file mode 100644 index 0000000..e0b8d85 --- /dev/null +++ b/codeforces/NonAlternatingDeckEasy/main_input0.txt @@ -0,0 +1,6 @@ +5 +10 +6 +17 +8 +1000000 diff --git a/codeforces/NonAlternatingDeckEasy/main_output0.txt b/codeforces/NonAlternatingDeckEasy/main_output0.txt new file mode 100644 index 0000000..48d2097 --- /dev/null +++ b/codeforces/NonAlternatingDeckEasy/main_output0.txt @@ -0,0 +1,5 @@ +5 5 +1 5 +10 7 +3 5 +500202 499798 diff --git a/codeforces/NonAlternatingDeckHard/main b/codeforces/NonAlternatingDeckHard/main new file mode 100755 index 0000000..0f9b8d2 Binary files /dev/null and b/codeforces/NonAlternatingDeckHard/main differ diff --git a/codeforces/NonAlternatingDeckHard/main.cpp b/codeforces/NonAlternatingDeckHard/main.cpp new file mode 100755 index 0000000..29a71f5 --- /dev/null +++ b/codeforces/NonAlternatingDeckHard/main.cpp @@ -0,0 +1,162 @@ +#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 print() { + cerr << "\n"; +} + +template +void print(T val, TS... vals) { + cerr << val << " "; + print(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; + vi pfx(n); //no of black tiles; + pfx[0] = 0; + int w1 = 1, w2 = 0, b1 = 0, b2 = 0; + for (int i = 1; i < n; i++) { + pfx[i] = pfx[i - 1] + (i % 2 != 0); + } + int i = 5; + int j = 1; + int cnt = 0; + ll sum = 0; + while (sum < n) { + sum = w1 + w2 + b1 + b2; + if (cnt % 2 == 0) { + int r = min(i + j - 1, n - 1); + int pf = pfx[r] - pfx[j - 1]; + b2 += pf; + w2 += (r + 1 - j) - pf; + } else { + int r = min(i + j - 1, n - 1); + int pf = pfx[min(i + j - 1, n - 1)] - pfx[j - 1]; + b1 += pf; + w1 += (r + 1 - j) - pf; + } + cnt++; + j = min(i + j - 1, n - 1) + 1; + i += 4; + } + cout << w1 << " " << b1 << " " << w2 << " " << b2 << '\n'; + +} + +int main () { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while(tt--) { + solve(); + } +} + + diff --git a/codeforces/NonAlternatingDeckHard/main_input0.txt b/codeforces/NonAlternatingDeckHard/main_input0.txt new file mode 100644 index 0000000..e0b8d85 --- /dev/null +++ b/codeforces/NonAlternatingDeckHard/main_input0.txt @@ -0,0 +1,6 @@ +5 +10 +6 +17 +8 +1000000 diff --git a/codeforces/NonAlternatingDeckHard/main_output0.txt b/codeforces/NonAlternatingDeckHard/main_output0.txt new file mode 100644 index 0000000..079473d --- /dev/null +++ b/codeforces/NonAlternatingDeckHard/main_output0.txt @@ -0,0 +1,5 @@ +3 2 2 3 +1 0 2 3 +6 4 3 4 +2 1 2 3 +250278 249924 249722 250076 diff --git a/codeforces/PolycarpRecoversThePermutation/main.cpp b/codeforces/PolycarpRecoversThePermutation/main.cpp new file mode 100755 index 0000000..c046a24 --- /dev/null +++ b/codeforces/PolycarpRecoversThePermutation/main.cpp @@ -0,0 +1,138 @@ +#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 print() { + cerr << "\n"; +} + +template +void print(T val, TS... vals) { + cerr << val << " "; + print(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; + vi v(n); + for (auto &x : v) { + cin >> x; + } + + +} + +int main () { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while(tt--) { + solve(); + } +} + + diff --git a/codeforces/RecentActions/main b/codeforces/RecentActions/main new file mode 100755 index 0000000..0db811c Binary files /dev/null and b/codeforces/RecentActions/main differ diff --git a/codeforces/RecentActions/main.cpp b/codeforces/RecentActions/main.cpp new file mode 100755 index 0000000..3ee1841 --- /dev/null +++ b/codeforces/RecentActions/main.cpp @@ -0,0 +1,119 @@ +#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 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}; + +//pretty printing +template +void printm(const map &mp) { + cerr << "{" << endl; + for (auto p : mp) { + cerr << " { " << p.first << " : " << p.second << " }\n"; + } + cerr << "}" << endl; +} +template +void printv(const vector &v) { + cerr << "["; + for (int i = 0; i < v.size(); i++) { + if (i == v.size() - 1) { + cerr << v[i]; + } else { + cerr << v[i] << ", "; + } + } + cerr << "]\n"; +} + +template +void printvv(const vector> &v) { + cerr << "[\n"; + for (auto &vec : v) { + cout << " "; + printv(vec); + } + cerr << "]\n"; +} +void print() { + cerr << "\n"; +} + +template +void print(T val, TS... vals) { + cerr << val << " "; + print(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, m; + cin >> n >> m; + vi v(m); + deque dq; + for (int i = 1; i <= n; i++) { + dq.pb(i); + } + unordered_map mp; + for (auto &x : v) cin >> x; + for (int i = 0; i < m; i++) { + int back = dq.back(); + auto it = find(all(dq), v[i]); + if (it != dq.end()) { // found + continue; + } else { + mp[back] = i + 1; + dq.pop_back(); + dq.push_front(v[i]); + } + } + for (int i = 1; i <= n; i++) { + if (mp[i] != 0) { + cout << mp[i] << ' '; + } else { + cout << -1 << ' '; + } + } + cout << '\n'; +} + +int main () { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while(tt--) { + solve(); + } +} + + diff --git a/codeforces/RecentActions/main_input0.txt b/codeforces/RecentActions/main_input0.txt new file mode 100644 index 0000000..a6aa411 --- /dev/null +++ b/codeforces/RecentActions/main_input0.txt @@ -0,0 +1,21 @@ +10 +1 1 +2 +3 2 +5 4 +4 5 +5 9 9 5 7 +5 5 +6 7 8 9 10 +3 4 +4 4 4 4 +4 4 +5 5 6 6 +3 5 +4 5 5 5 4 +4 20 +5 5 24 24 24 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 +5 7 +7 8 7 11 7 12 10 +6 7 +8 11 7 8 8 8 12 diff --git a/codeforces/RecentActions/main_output0.txt b/codeforces/RecentActions/main_output0.txt new file mode 100644 index 0000000..0594b15 --- /dev/null +++ b/codeforces/RecentActions/main_output0.txt @@ -0,0 +1,10 @@ +1 +-1 2 1 +-1 5 2 1 +5 4 3 2 1 +-1 -1 1 +-1 -1 3 1 +-1 2 1 +8 7 3 1 +7 6 4 2 1 +-1 -1 7 3 2 1 diff --git a/codeforces/TeamCompositinoProgrammersAndMathmaticians/main b/codeforces/TeamCompositinoProgrammersAndMathmaticians/main new file mode 100755 index 0000000..ab03ea4 Binary files /dev/null and b/codeforces/TeamCompositinoProgrammersAndMathmaticians/main differ diff --git a/codeforces/TeamCompositinoProgrammersAndMathmaticians/main.cpp b/codeforces/TeamCompositinoProgrammersAndMathmaticians/main.cpp new file mode 100755 index 0000000..0868030 --- /dev/null +++ b/codeforces/TeamCompositinoProgrammersAndMathmaticians/main.cpp @@ -0,0 +1,148 @@ +#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 print() { + cerr << "\n"; +} + +template +void print(T val, TS... vals) { + cerr << val << " "; + print(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 + */ + +// 6 2 +// 1 3 +// 1 3 +// ---- +// 5 3 +// 3 1 + +void solve() { + ll a, b; + cin >> a >> b; + if (!a or !b) { + cout << 0 << '\n'; + return; + } + ll sum = (a + b) / 4; + cout << min(sum, min(a, b)) << '\n'; + + +} + +int main () { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while(tt--) { + solve(); + } +} + + diff --git a/codeforces/TeamCompositinoProgrammersAndMathmaticians/main_input0.txt b/codeforces/TeamCompositinoProgrammersAndMathmaticians/main_input0.txt new file mode 100644 index 0000000..ee1cb7c --- /dev/null +++ b/codeforces/TeamCompositinoProgrammersAndMathmaticians/main_input0.txt @@ -0,0 +1,7 @@ +6 +5 5 +10 1 +2 3 +0 0 +17 2 +1000000000 1000000000 diff --git a/codeforces/TeamCompositinoProgrammersAndMathmaticians/main_output0.txt b/codeforces/TeamCompositinoProgrammersAndMathmaticians/main_output0.txt new file mode 100644 index 0000000..edfc500 --- /dev/null +++ b/codeforces/TeamCompositinoProgrammersAndMathmaticians/main_output0.txt @@ -0,0 +1,6 @@ +2 +1 +1 +0 +2 +500000000 diff --git a/codeforces/TwoTowers/main b/codeforces/TwoTowers/main new file mode 100755 index 0000000..6e44fa1 Binary files /dev/null and b/codeforces/TwoTowers/main differ diff --git a/codeforces/TwoTowers/main.cpp b/codeforces/TwoTowers/main.cpp new file mode 100755 index 0000000..faef146 --- /dev/null +++ b/codeforces/TwoTowers/main.cpp @@ -0,0 +1,113 @@ +#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 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}; + +//pretty printing +template +void printm(const map &mp) { + cerr << "{" << endl; + for (auto p : mp) { + cerr << " { " << p.first << " : " << p.second << " }\n"; + } + cerr << "}" << endl; +} +template +void printv(const vector &v) { + cerr << "["; + for (int i = 0; i < v.size(); i++) { + if (i == v.size() - 1) { + cerr << v[i]; + } else { + cerr << v[i] << ", "; + } + } + cerr << "]\n"; +} + +template +void printvv(const vector> &v) { + cerr << "[\n"; + for (auto &vec : v) { + cout << " "; + printv(vec); + } + cerr << "]\n"; +} +void print() { + cerr << "\n"; +} + +template +void print(T val, TS... vals) { + cerr << val << " "; + print(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 + */ + +bool isBeautiful(string s) { + for (int i = 0; i < s.length() - 1; i++) { + if (s[i] == s[i + 1]) { + return false; + } + } + return true; +} + +void solve() { + int n, m; + cin >> n >> m; + string t1, t2; + cin >> t1 >> t2; + string s1 = t1 + string(rall(t2)); + print(s1); + int cnt = 0; + for (int i = 0; i < n + m - 1; i++) { + if (s1[i] == s1[i + 1]) { + cnt++; + } + } + cout << (cnt <= 1 ? "YES\n" : "NO\n"); +} + +int main () { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while(tt--) { + solve(); + } +} + + diff --git a/codeforces/TwoTowers/main_input0.txt b/codeforces/TwoTowers/main_input0.txt new file mode 100644 index 0000000..cc23c7b --- /dev/null +++ b/codeforces/TwoTowers/main_input0.txt @@ -0,0 +1,13 @@ +4 +4 3 +BRBB +RBR +4 7 +BRBR +RRBRBRB +3 4 +RBR +BRBR +5 4 +BRBRR +BRBR diff --git a/codeforces/TwoTowers/main_output0.txt b/codeforces/TwoTowers/main_output0.txt new file mode 100644 index 0000000..4d34574 --- /dev/null +++ b/codeforces/TwoTowers/main_output0.txt @@ -0,0 +1,4 @@ +YES +YES +YES +NO diff --git a/codeforces/TwoTowers/mainl.cpp b/codeforces/TwoTowers/mainl.cpp new file mode 100644 index 0000000..e69de29 diff --git a/codeforces/TwoTowers/mainl_input0.txt b/codeforces/TwoTowers/mainl_input0.txt new file mode 100644 index 0000000..cc23c7b --- /dev/null +++ b/codeforces/TwoTowers/mainl_input0.txt @@ -0,0 +1,13 @@ +4 +4 3 +BRBB +RBR +4 7 +BRBR +RRBRBRB +3 4 +RBR +BRBR +5 4 +BRBRR +BRBR diff --git a/codeforces/TwoTowers/mainl_output0.txt b/codeforces/TwoTowers/mainl_output0.txt new file mode 100644 index 0000000..4d34574 --- /dev/null +++ b/codeforces/TwoTowers/mainl_output0.txt @@ -0,0 +1,4 @@ +YES +YES +YES +NO diff --git a/codeforces/WalkingMaster/main b/codeforces/WalkingMaster/main new file mode 100755 index 0000000..2813aca Binary files /dev/null and b/codeforces/WalkingMaster/main differ diff --git a/codeforces/WalkingMaster/main.cpp b/codeforces/WalkingMaster/main.cpp new file mode 100755 index 0000000..3efb42c --- /dev/null +++ b/codeforces/WalkingMaster/main.cpp @@ -0,0 +1,142 @@ +#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 print() { + cerr << "\n"; +} + +template +void print(T val, TS... vals) { + cerr << val << " "; + print(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 a, b, c, d; + cin >> a >> b >> c >> d; + int xAfterUp = (d - b) + a; + print(xAfterUp); + if (d > b && c <= a) + if ((d <= b && c > a) || c > xAfterUp) { + cout << -1 << '\n'; + return; + } + cout << (d - b) + abs(xAfterUp - c) << '\n'; + +} + +int main () { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while(tt--) { + solve(); + } +} + + diff --git a/codeforces/WalkingMaster/main_input0.txt b/codeforces/WalkingMaster/main_input0.txt new file mode 100644 index 0000000..fd8aabe --- /dev/null +++ b/codeforces/WalkingMaster/main_input0.txt @@ -0,0 +1,7 @@ +6 +-1 0 -1 2 +0 0 4 5 +-2 -1 1 1 +-3 2 -3 2 +2 -1 -1 -1 +1 1 0 2 diff --git a/codeforces/WalkingMaster/main_output0.txt b/codeforces/WalkingMaster/main_output0.txt new file mode 100644 index 0000000..1382439 --- /dev/null +++ b/codeforces/WalkingMaster/main_output0.txt @@ -0,0 +1,6 @@ +4 +6 +-1 +0 +3 +3 -- cgit v1.2.3