From ef9dfb5d8bfa705a0c056a2652d298e5ebb763fb Mon Sep 17 00:00:00 2001 From: omagdy7 Date: Wed, 22 Feb 2023 20:18:04 +0200 Subject: Solved a bunch of problems --- codeforces/FlipFlopSum/main | Bin 0 -> 22640 bytes codeforces/FlipFlopSum/main.cpp | 107 ++++++++++++++++ codeforces/FlipFlopSum/main_input0.txt | 9 ++ codeforces/FlipFlopSum/main_output0.txt | 4 + codeforces/GardenerAndTheCapyBaras1/main.cpp | 89 ++++++++++++++ codeforces/PolycarpAndTheDayOfPi/main | Bin 0 -> 25712 bytes codeforces/PolycarpAndTheDayOfPi/main.cpp | 98 +++++++++++++++ codeforces/PolycarpAndTheDayOfPi/main_input0.txt | 10 ++ codeforces/PolycarpAndTheDayOfPi/main_output0.txt | 9 ++ codeforces/Stripes/main.cpp | 18 ++- codeforces/Sum/main.cpp | 12 +- codeforces/Word/main.cpp | 16 +-- codeforces/recursionTest/recursionTest.cpp | 25 ++-- contests/Round#849(Div4)/A/main | Bin 0 -> 26728 bytes contests/Round#849(Div4)/A/main.cpp | 92 ++++++++++++++ contests/Round#849(Div4)/A/main_input0.txt | 11 ++ contests/Round#849(Div4)/A/main_output0.txt | 10 ++ contests/Round#849(Div4)/B/main | Bin 0 -> 19080 bytes contests/Round#849(Div4)/B/main.cpp | 122 +++++++++++++++++++ contests/Round#849(Div4)/B/main_input0.txt | 15 +++ contests/Round#849(Div4)/B/main_output0.txt | 7 ++ contests/Round#849(Div4)/C/main | Bin 0 -> 18656 bytes contests/Round#849(Div4)/C/main.cpp | 105 ++++++++++++++++ contests/Round#849(Div4)/C/main_input0.txt | 19 +++ contests/Round#849(Div4)/C/main_output0.txt | 9 ++ contests/Round#849(Div4)/D/main | Bin 0 -> 67128 bytes contests/Round#849(Div4)/D/main.cpp | 104 ++++++++++++++++ contests/Round#849(Div4)/D/main_input0.txt | 11 ++ contests/Round#849(Div4)/D/main_output0.txt | 5 + contests/Round#849(Div4)/E/main | Bin 0 -> 27104 bytes contests/Round#849(Div4)/E/main.cpp | 124 +++++++++++++++++++ contests/Round#849(Div4)/E/main_input0.txt | 11 ++ contests/Round#849(Div4)/E/main_input1.txt | 3 + contests/Round#849(Div4)/E/main_input2.txt | 3 + contests/Round#849(Div4)/E/main_output0.txt | 5 + contests/Round#849(Div4)/E/main_output1.txt | 1 + contests/Round#849(Div4)/E/main_output2.txt | 1 + contests/Round#849(Div4)/F/main | Bin 0 -> 22520 bytes contests/Round#849(Div4)/F/main.cpp | 114 +++++++++++++++++ contests/Round#849(Div4)/F/main_input0.txt | 19 +++ contests/Round#849(Div4)/F/main_output0.txt | 9 ++ contests/Round#849(Div4)/G1/main | Bin 0 -> 39896 bytes contests/Round#849(Div4)/G1/main.cpp | 108 ++++++++++++++++ contests/Round#849(Div4)/G1/main_input0.txt | 21 ++++ contests/Round#849(Div4)/G1/main_output0.txt | 10 ++ contests/Round#849(Div4)/G2/main | Bin 0 -> 41712 bytes contests/Round#849(Div4)/G2/main.cpp | 142 ++++++++++++++++++++++ contests/Round#849(Div4)/G2/main_input0.txt | 21 ++++ contests/Round#849(Div4)/G2/main_output0.txt | 10 ++ contests/Round#849(Div4)/G2Joe/main | Bin 0 -> 66008 bytes contests/Round#849(Div4)/G2Joe/main.cpp | 129 ++++++++++++++++++++ contests/Round#849(Div4)/G2Joe/main_input0.txt | 21 ++++ contests/Round#849(Div4)/G2Joe/main_input1.txt | 3 + contests/Round#849(Div4)/G2Joe/main_input2.txt | 3 + contests/Round#849(Div4)/G2Joe/main_output0.txt | 10 ++ contests/Round#849(Div4)/G2Joe/main_output1.txt | 1 + contests/Round#849(Div4)/G2Joe/main_output2.txt | 1 + contests/Starters78/A/main | Bin 0 -> 47328 bytes contests/Starters78/A/main.cpp | 94 ++++++++++++++ contests/Starters78/A/main_input0.txt | 7 ++ contests/Starters78/A/main_output0.txt | 3 + contests/Starters78/B/main | Bin 0 -> 17688 bytes contests/Starters78/B/main.cpp | 109 +++++++++++++++++ contests/Starters78/B/main_input0.txt | 4 + contests/Starters78/B/main_input1.txt | 2 + contests/Starters78/B/main_input2.txt | 2 + contests/Starters78/B/main_input3.txt | 2 + contests/Starters78/B/main_input4.txt | 2 + contests/Starters78/B/main_input5.txt | 2 + contests/Starters78/B/main_input6.txt | 2 + contests/Starters78/B/main_input7.txt | 2 + contests/Starters78/B/main_output0.txt | 3 + contests/Starters78/B/main_output1.txt | 1 + contests/Starters78/B/main_output2.txt | 1 + contests/Starters78/B/main_output3.txt | 1 + contests/Starters78/B/main_output4.txt | 1 + contests/Starters78/B/main_output5.txt | 1 + contests/Starters78/B/main_output6.txt | 1 + contests/Starters78/B/main_output7.txt | 1 + contests/Starters78/C/main | Bin 0 -> 17848 bytes contests/Starters78/C/main.cpp | 113 +++++++++++++++++ contests/Starters78/C/main_input0.txt | 4 + contests/Starters78/C/main_input1.txt | 2 + contests/Starters78/C/main_output0.txt | 3 + contests/Starters78/C/main_output1.txt | 1 + contests/Starters78/D/main | Bin 0 -> 57544 bytes contests/Starters78/D/main.cpp | 117 ++++++++++++++++++ contests/Starters78/D/main_input0.txt | 13 ++ contests/Starters78/D/main_input1.txt | 4 + contests/Starters78/D/main_input2.txt | 4 + contests/Starters78/D/main_input3.txt | 4 + contests/Starters78/D/main_output0.txt | 4 + contests/Starters78/D/main_output1.txt | 1 + contests/Starters78/D/main_output2.txt | 1 + contests/Starters78/D/main_output3.txt | 1 + contests/Starters78/E/main.cpp | 89 ++++++++++++++ contests/Starters78/F/main.cpp | 89 ++++++++++++++ cses/IntroductoryProblems/BitStrings/main | Bin 22544 -> 22545 bytes 98 files changed, 2330 insertions(+), 38 deletions(-) create mode 100755 codeforces/FlipFlopSum/main create mode 100755 codeforces/FlipFlopSum/main.cpp create mode 100644 codeforces/FlipFlopSum/main_input0.txt create mode 100644 codeforces/FlipFlopSum/main_output0.txt create mode 100755 codeforces/GardenerAndTheCapyBaras1/main.cpp create mode 100755 codeforces/PolycarpAndTheDayOfPi/main create mode 100755 codeforces/PolycarpAndTheDayOfPi/main.cpp create mode 100644 codeforces/PolycarpAndTheDayOfPi/main_input0.txt create mode 100644 codeforces/PolycarpAndTheDayOfPi/main_output0.txt create mode 100755 contests/Round#849(Div4)/A/main create mode 100755 contests/Round#849(Div4)/A/main.cpp create mode 100644 contests/Round#849(Div4)/A/main_input0.txt create mode 100644 contests/Round#849(Div4)/A/main_output0.txt create mode 100755 contests/Round#849(Div4)/B/main create mode 100755 contests/Round#849(Div4)/B/main.cpp create mode 100644 contests/Round#849(Div4)/B/main_input0.txt create mode 100644 contests/Round#849(Div4)/B/main_output0.txt create mode 100755 contests/Round#849(Div4)/C/main create mode 100755 contests/Round#849(Div4)/C/main.cpp create mode 100644 contests/Round#849(Div4)/C/main_input0.txt create mode 100644 contests/Round#849(Div4)/C/main_output0.txt create mode 100755 contests/Round#849(Div4)/D/main create mode 100755 contests/Round#849(Div4)/D/main.cpp create mode 100644 contests/Round#849(Div4)/D/main_input0.txt create mode 100644 contests/Round#849(Div4)/D/main_output0.txt create mode 100755 contests/Round#849(Div4)/E/main create mode 100755 contests/Round#849(Div4)/E/main.cpp create mode 100644 contests/Round#849(Div4)/E/main_input0.txt create mode 100644 contests/Round#849(Div4)/E/main_input1.txt create mode 100644 contests/Round#849(Div4)/E/main_input2.txt create mode 100644 contests/Round#849(Div4)/E/main_output0.txt create mode 100644 contests/Round#849(Div4)/E/main_output1.txt create mode 100644 contests/Round#849(Div4)/E/main_output2.txt create mode 100755 contests/Round#849(Div4)/F/main create mode 100755 contests/Round#849(Div4)/F/main.cpp create mode 100644 contests/Round#849(Div4)/F/main_input0.txt create mode 100644 contests/Round#849(Div4)/F/main_output0.txt create mode 100755 contests/Round#849(Div4)/G1/main create mode 100755 contests/Round#849(Div4)/G1/main.cpp create mode 100644 contests/Round#849(Div4)/G1/main_input0.txt create mode 100644 contests/Round#849(Div4)/G1/main_output0.txt create mode 100755 contests/Round#849(Div4)/G2/main create mode 100755 contests/Round#849(Div4)/G2/main.cpp create mode 100644 contests/Round#849(Div4)/G2/main_input0.txt create mode 100644 contests/Round#849(Div4)/G2/main_output0.txt create mode 100755 contests/Round#849(Div4)/G2Joe/main create mode 100755 contests/Round#849(Div4)/G2Joe/main.cpp create mode 100644 contests/Round#849(Div4)/G2Joe/main_input0.txt create mode 100644 contests/Round#849(Div4)/G2Joe/main_input1.txt create mode 100644 contests/Round#849(Div4)/G2Joe/main_input2.txt create mode 100644 contests/Round#849(Div4)/G2Joe/main_output0.txt create mode 100644 contests/Round#849(Div4)/G2Joe/main_output1.txt create mode 100644 contests/Round#849(Div4)/G2Joe/main_output2.txt create mode 100755 contests/Starters78/A/main create mode 100755 contests/Starters78/A/main.cpp create mode 100644 contests/Starters78/A/main_input0.txt create mode 100644 contests/Starters78/A/main_output0.txt create mode 100755 contests/Starters78/B/main create mode 100755 contests/Starters78/B/main.cpp create mode 100644 contests/Starters78/B/main_input0.txt create mode 100644 contests/Starters78/B/main_input1.txt create mode 100644 contests/Starters78/B/main_input2.txt create mode 100644 contests/Starters78/B/main_input3.txt create mode 100644 contests/Starters78/B/main_input4.txt create mode 100644 contests/Starters78/B/main_input5.txt create mode 100644 contests/Starters78/B/main_input6.txt create mode 100644 contests/Starters78/B/main_input7.txt create mode 100644 contests/Starters78/B/main_output0.txt create mode 100644 contests/Starters78/B/main_output1.txt create mode 100644 contests/Starters78/B/main_output2.txt create mode 100644 contests/Starters78/B/main_output3.txt create mode 100644 contests/Starters78/B/main_output4.txt create mode 100644 contests/Starters78/B/main_output5.txt create mode 100644 contests/Starters78/B/main_output6.txt create mode 100644 contests/Starters78/B/main_output7.txt create mode 100755 contests/Starters78/C/main create mode 100755 contests/Starters78/C/main.cpp create mode 100644 contests/Starters78/C/main_input0.txt create mode 100644 contests/Starters78/C/main_input1.txt create mode 100644 contests/Starters78/C/main_output0.txt create mode 100644 contests/Starters78/C/main_output1.txt create mode 100755 contests/Starters78/D/main create mode 100755 contests/Starters78/D/main.cpp create mode 100644 contests/Starters78/D/main_input0.txt create mode 100644 contests/Starters78/D/main_input1.txt create mode 100644 contests/Starters78/D/main_input2.txt create mode 100644 contests/Starters78/D/main_input3.txt create mode 100644 contests/Starters78/D/main_output0.txt create mode 100644 contests/Starters78/D/main_output1.txt create mode 100644 contests/Starters78/D/main_output2.txt create mode 100644 contests/Starters78/D/main_output3.txt create mode 100755 contests/Starters78/E/main.cpp create mode 100755 contests/Starters78/F/main.cpp diff --git a/codeforces/FlipFlopSum/main b/codeforces/FlipFlopSum/main new file mode 100755 index 0000000..cddb16d Binary files /dev/null and b/codeforces/FlipFlopSum/main differ diff --git a/codeforces/FlipFlopSum/main.cpp b/codeforces/FlipFlopSum/main.cpp new file mode 100755 index 0000000..7de31f6 --- /dev/null +++ b/codeforces/FlipFlopSum/main.cpp @@ -0,0 +1,107 @@ +#include +using namespace std; + +using ll = long long; +using pi = 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 + +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; + int flag = 0; + for (int i = 0; i < n - 1; i++) { + if (v[i] == v[i + 1] && v[i] == -1) { + flag = 1; + break; + } + } + if (std::accumulate(all(v), 0) == v.size()) { + cout << std::accumulate(all(v), -4) << '\n'; + } else if (flag == 1) { + cout << std::accumulate(all(v), 4) << '\n'; + } else { + cout << std::accumulate(all(v), 0) << '\n'; + } + +} + +int main () { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while(tt--) { + solve(); + } +} + + diff --git a/codeforces/FlipFlopSum/main_input0.txt b/codeforces/FlipFlopSum/main_input0.txt new file mode 100644 index 0000000..ae848c8 --- /dev/null +++ b/codeforces/FlipFlopSum/main_input0.txt @@ -0,0 +1,9 @@ +4 +5 +-1 1 1 -1 -1 +5 +1 1 -1 -1 -1 +2 +1 1 +4 +1 -1 -1 1 diff --git a/codeforces/FlipFlopSum/main_output0.txt b/codeforces/FlipFlopSum/main_output0.txt new file mode 100644 index 0000000..8dd367d --- /dev/null +++ b/codeforces/FlipFlopSum/main_output0.txt @@ -0,0 +1,4 @@ +3 +3 +-2 +4 diff --git a/codeforces/GardenerAndTheCapyBaras1/main.cpp b/codeforces/GardenerAndTheCapyBaras1/main.cpp new file mode 100755 index 0000000..7590c13 --- /dev/null +++ b/codeforces/GardenerAndTheCapyBaras1/main.cpp @@ -0,0 +1,89 @@ +#include +using namespace std; + +using ll = long long; +using pi = 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 + +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 main () { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while(tt--) { + solve(); + } +} + + diff --git a/codeforces/PolycarpAndTheDayOfPi/main b/codeforces/PolycarpAndTheDayOfPi/main new file mode 100755 index 0000000..b306185 Binary files /dev/null and b/codeforces/PolycarpAndTheDayOfPi/main differ diff --git a/codeforces/PolycarpAndTheDayOfPi/main.cpp b/codeforces/PolycarpAndTheDayOfPi/main.cpp new file mode 100755 index 0000000..877aa61 --- /dev/null +++ b/codeforces/PolycarpAndTheDayOfPi/main.cpp @@ -0,0 +1,98 @@ +#include +using namespace std; + +using ll = long long; +using pi = 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 + +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() { + string pi = "314159265358979323846264338327"; + string n; + cin >> n; + int ans = 0; + int i = 0; + while(i < pi.length() && n[i] == pi[i]) { + ans++; + i++; + } + cout << ans << endl; +} + +int main () { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while(tt--) { + solve(); + } +} + + diff --git a/codeforces/PolycarpAndTheDayOfPi/main_input0.txt b/codeforces/PolycarpAndTheDayOfPi/main_input0.txt new file mode 100644 index 0000000..4e76296 --- /dev/null +++ b/codeforces/PolycarpAndTheDayOfPi/main_input0.txt @@ -0,0 +1,10 @@ +9 +000 +3 +4141592653 +141592653589793238462643383279 +31420 +31415 +314159265358 +27182 +314159265358979323846264338327 diff --git a/codeforces/PolycarpAndTheDayOfPi/main_output0.txt b/codeforces/PolycarpAndTheDayOfPi/main_output0.txt new file mode 100644 index 0000000..038a593 --- /dev/null +++ b/codeforces/PolycarpAndTheDayOfPi/main_output0.txt @@ -0,0 +1,9 @@ +0 +1 +0 +0 +3 +5 +12 +0 +30 diff --git a/codeforces/Stripes/main.cpp b/codeforces/Stripes/main.cpp index 91048d4..d9454c7 100755 --- a/codeforces/Stripes/main.cpp +++ b/codeforces/Stripes/main.cpp @@ -1,4 +1,4 @@ -#include +#include using namespace std; @@ -23,18 +23,16 @@ const int dx[4]{1, 0, -1, 0}; const int dy[4]{0, 1, 0, -1}; void solve() { - - } -int main () { - ios_base::sync_with_stdio(false); - cin.tie(NULL); - int tt; - cin >> tt; - while(tt--) { +int main() { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while (tt--) { solve(); - } + } } /* stuff you should look for: diff --git a/codeforces/Sum/main.cpp b/codeforces/Sum/main.cpp index 7a56c46..f9def9b 100755 --- a/codeforces/Sum/main.cpp +++ b/codeforces/Sum/main.cpp @@ -35,13 +35,13 @@ void solve() { } int main () { - ios_base::sync_with_stdio(false); - cin.tie(NULL); - int tt; - cin >> tt; - while(tt--) { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while(tt--) { solve(); - } + } } /* stuff you should look for: diff --git a/codeforces/Word/main.cpp b/codeforces/Word/main.cpp index 31937b2..d32a6ca 100755 --- a/codeforces/Word/main.cpp +++ b/codeforces/Word/main.cpp @@ -1,30 +1,30 @@ -#include +#include #include using namespace std; string convertLower(string s) { - for(auto &ch : s) { + for (auto &ch : s) { ch = tolower(ch); } return s; } string convertUpper(string s) { - for(auto &ch : s) { + for (auto &ch : s) { ch = toupper(ch); } return s; } -int main () { - ios_base::sync_with_stdio(false); - cin.tie(NULL); +int main() { + ios_base::sync_with_stdio(false); + cin.tie(NULL); string s; cin >> s; int l = 0; int u = 0; - for(auto ch : s) { - if(islower(ch)) { + for (auto ch : s) { + if (islower(ch)) { l++; } else { u++; diff --git a/codeforces/recursionTest/recursionTest.cpp b/codeforces/recursionTest/recursionTest.cpp index 91e9db8..c61d519 100755 --- a/codeforces/recursionTest/recursionTest.cpp +++ b/codeforces/recursionTest/recursionTest.cpp @@ -1,27 +1,25 @@ #include -#include +#include using namespace std; string ans; -bool solve(vector v,int idx, int target, int sum, string opts) { - if(idx == v.size() - 1) { - if(sum == target){ +bool solve(vector v, int idx, int target, int sum, string opts) { + if (idx == v.size() - 1) { + if (sum == target) { ans = opts; return true; } return false; - } - else { + } else { int nxt = idx + 1; - bool plus = solve(v, nxt, target, sum + v[nxt],opts + "+"); + bool plus = solve(v, nxt, target, sum + v[nxt], opts + "+"); bool minus = solve(v, nxt, target, sum - v[nxt], opts + "-"); bool mult = solve(v, nxt, target, sum * v[nxt], opts + "*"); bool div = solve(v, nxt, target, sum / v[nxt], opts + "/"); return plus || minus || mult || div; } - } int main() { @@ -29,23 +27,22 @@ int main() { cin >> n >> target; vector v(n); string opts = ""; - for(int &x : v) { + for (int &x : v) { cin >> x; } sort(v.begin(), v.end()); do { - if(solve(v, 0, target, v[0], opts)) { - for(int i = 0; i < v.size(); i++) { + if (solve(v, 0, target, v[0], opts)) { + for (int i = 0; i < v.size(); i++) { if (i == v.size() - 1) { cout << v[i]; - } - else { + } else { cout << v[i] << " " << ans[i] << " "; } } cout << '\n'; } - } while(next_permutation(v.begin(), v.end())); + } while (next_permutation(v.begin(), v.end())); return 0; } diff --git a/contests/Round#849(Div4)/A/main b/contests/Round#849(Div4)/A/main new file mode 100755 index 0000000..3e81677 Binary files /dev/null and b/contests/Round#849(Div4)/A/main differ diff --git a/contests/Round#849(Div4)/A/main.cpp b/contests/Round#849(Div4)/A/main.cpp new file mode 100755 index 0000000..aa30531 --- /dev/null +++ b/contests/Round#849(Div4)/A/main.cpp @@ -0,0 +1,92 @@ +#include +using namespace std; + +using ll = long long; +using pi = 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 + +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() { + string haystack = "codeforces"; + char ch; + cin >> ch; + cout << (count(all(haystack), ch) ? "YES" : "NO") << '\n'; +} + +int main () { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while(tt--) { + solve(); + } +} + + diff --git a/contests/Round#849(Div4)/A/main_input0.txt b/contests/Round#849(Div4)/A/main_input0.txt new file mode 100644 index 0000000..9d71f59 --- /dev/null +++ b/contests/Round#849(Div4)/A/main_input0.txt @@ -0,0 +1,11 @@ +10 +a +b +c +d +e +f +g +h +i +j diff --git a/contests/Round#849(Div4)/A/main_output0.txt b/contests/Round#849(Div4)/A/main_output0.txt new file mode 100644 index 0000000..6df8a46 --- /dev/null +++ b/contests/Round#849(Div4)/A/main_output0.txt @@ -0,0 +1,10 @@ +NO +NO +YES +YES +YES +YES +NO +NO +NO +NO diff --git a/contests/Round#849(Div4)/B/main b/contests/Round#849(Div4)/B/main new file mode 100755 index 0000000..24928cb Binary files /dev/null and b/contests/Round#849(Div4)/B/main differ diff --git a/contests/Round#849(Div4)/B/main.cpp b/contests/Round#849(Div4)/B/main.cpp new file mode 100755 index 0000000..da40ca0 --- /dev/null +++ b/contests/Round#849(Div4)/B/main.cpp @@ -0,0 +1,122 @@ +#include +using namespace std; + +using ll = long long; +using pi = 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 + +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 + */ + +struct Point { + int x; + int y; + Point(int x, int y) { + this->x = x; + this->y = y; + } +}; + +void solve() { + Point p(0, 0); + int n; + cin >> n; + string str; + cin >> str; + for (auto ch: str) { + if(ch == 'U') { + p.y++; + } + else if(ch == 'D') { + p.y--; + } + else if(ch == 'R') { + p.x++; + } + else if(ch == 'L') { + p.x--; + } + + if (p.x == 1 && p.y == 1) { + cout << "YES" << '\n'; + return; + } + } + cout << "NO" << '\n'; +} + +int main () { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while(tt--) { + solve(); + } +} + + diff --git a/contests/Round#849(Div4)/B/main_input0.txt b/contests/Round#849(Div4)/B/main_input0.txt new file mode 100644 index 0000000..bca5a3e --- /dev/null +++ b/contests/Round#849(Div4)/B/main_input0.txt @@ -0,0 +1,15 @@ +7 +7 +UUURDDL +2 +UR +8 +RRRUUDDD +3 +LLL +4 +DUUR +5 +RUDLL +11 +LLLLDDRUDRD diff --git a/contests/Round#849(Div4)/B/main_output0.txt b/contests/Round#849(Div4)/B/main_output0.txt new file mode 100644 index 0000000..4699a2d --- /dev/null +++ b/contests/Round#849(Div4)/B/main_output0.txt @@ -0,0 +1,7 @@ +YES +YES +NO +NO +YES +YES +NO diff --git a/contests/Round#849(Div4)/C/main b/contests/Round#849(Div4)/C/main new file mode 100755 index 0000000..7f05022 Binary files /dev/null and b/contests/Round#849(Div4)/C/main differ diff --git a/contests/Round#849(Div4)/C/main.cpp b/contests/Round#849(Div4)/C/main.cpp new file mode 100755 index 0000000..91c1a12 --- /dev/null +++ b/contests/Round#849(Div4)/C/main.cpp @@ -0,0 +1,105 @@ +#include +using namespace std; + +using ll = long long; +using pi = 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 + +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 + */ + +int countPairs(string &str) { + int cnt = 0; + for (int i = 0; i < str.length() / 2; i++) { + if (str[i] != str[str.length() - 1 - i]) { + cnt++; + } else { + break; + } + } + return cnt; +} + +void solve() { + int n; + cin >> n; + string str; + cin >> str; + cout << str.length() - 2 * countPairs(str) << '\n'; +} + +int main () { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while(tt--) { + solve(); + } +} + + diff --git a/contests/Round#849(Div4)/C/main_input0.txt b/contests/Round#849(Div4)/C/main_input0.txt new file mode 100644 index 0000000..b07910f --- /dev/null +++ b/contests/Round#849(Div4)/C/main_input0.txt @@ -0,0 +1,19 @@ +9 +3 +100 +4 +0111 +5 +10101 +6 +101010 +7 +1010110 +1 +1 +2 +10 +2 +11 +10 +1011011010 diff --git a/contests/Round#849(Div4)/C/main_output0.txt b/contests/Round#849(Div4)/C/main_output0.txt new file mode 100644 index 0000000..89375dd --- /dev/null +++ b/contests/Round#849(Div4)/C/main_output0.txt @@ -0,0 +1,9 @@ +1 +2 +5 +0 +3 +1 +0 +2 +4 diff --git a/contests/Round#849(Div4)/D/main b/contests/Round#849(Div4)/D/main new file mode 100755 index 0000000..b59f7cc Binary files /dev/null and b/contests/Round#849(Div4)/D/main differ diff --git a/contests/Round#849(Div4)/D/main.cpp b/contests/Round#849(Div4)/D/main.cpp new file mode 100755 index 0000000..9e9da38 --- /dev/null +++ b/contests/Round#849(Div4)/D/main.cpp @@ -0,0 +1,104 @@ +#include +using namespace std; + +using ll = long long; +using pi = 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 + +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 + */ + +// abcabcabc +void solve() { + int n; + cin >> n; + string str; + cin >> str; + vi fq(27); + int split = 0; + for (int i = 0; i < n; i++) { + char ch = str[i]; + fq[ch - 'a']++; + if (fq[ch - 'a'] > 1) { + split = i; + break; + } + } + cout << unordered_set(str.begin(), str.begin() + split).size() + unordered_set(str.begin() + split, str.end()).size() << '\n'; +} + +int main () { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while(tt--) { + solve(); + } +} + + diff --git a/contests/Round#849(Div4)/D/main_input0.txt b/contests/Round#849(Div4)/D/main_input0.txt new file mode 100644 index 0000000..8d60cf9 --- /dev/null +++ b/contests/Round#849(Div4)/D/main_input0.txt @@ -0,0 +1,11 @@ +5 +2 +aa +7 +abcabcd +5 +aaaaa +10 +paiumoment +4 +aazz diff --git a/contests/Round#849(Div4)/D/main_output0.txt b/contests/Round#849(Div4)/D/main_output0.txt new file mode 100644 index 0000000..8162782 --- /dev/null +++ b/contests/Round#849(Div4)/D/main_output0.txt @@ -0,0 +1,5 @@ +2 +7 +2 +10 +3 diff --git a/contests/Round#849(Div4)/E/main b/contests/Round#849(Div4)/E/main new file mode 100755 index 0000000..6a259d3 Binary files /dev/null and b/contests/Round#849(Div4)/E/main differ diff --git a/contests/Round#849(Div4)/E/main.cpp b/contests/Round#849(Div4)/E/main.cpp new file mode 100755 index 0000000..d1605ce --- /dev/null +++ b/contests/Round#849(Div4)/E/main.cpp @@ -0,0 +1,124 @@ +#include +using namespace std; + +using ll = long long; +using pi = 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 + +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 + */ + +/* + * Ideally we want them all to be positive + * If we can't get them all to be positive we want to flip the largest numbers in absloute + * The 0 can be a joker because flipping its sign is meaningless anyways +*/ + +void solve() { + int n; + cin >> n; + vll v(n); + for (auto &x : v) cin >> x; + int neg = 0; + for (auto x : v) { + neg += (x < 0); + } + ll sum = 0; + if (neg % 2 == 0) { + for (auto x : v) { + if (x < 0) { + sum += -x; + } else { + sum += x; + } + } + } else { + for (auto &x : v) { + if (x < 0) { + x = -x; + } + } + for (auto x : v) { + sum += x; + } + sum -= *min_element(all(v)) * 2; + } + cout << sum << '\n'; + +} + +int main () { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while(tt--) { + solve(); + } +} + + diff --git a/contests/Round#849(Div4)/E/main_input0.txt b/contests/Round#849(Div4)/E/main_input0.txt new file mode 100644 index 0000000..7111644 --- /dev/null +++ b/contests/Round#849(Div4)/E/main_input0.txt @@ -0,0 +1,11 @@ +5 +3 +-1 -1 -1 +5 +1 5 -5 0 2 +3 +1 2 3 +6 +-1 10 9 8 7 6 +2 +-1 -1 diff --git a/contests/Round#849(Div4)/E/main_input1.txt b/contests/Round#849(Div4)/E/main_input1.txt new file mode 100644 index 0000000..5285b38 --- /dev/null +++ b/contests/Round#849(Div4)/E/main_input1.txt @@ -0,0 +1,3 @@ +1 +4 +1 -10 9 8 \ No newline at end of file diff --git a/contests/Round#849(Div4)/E/main_input2.txt b/contests/Round#849(Div4)/E/main_input2.txt new file mode 100644 index 0000000..028be5f --- /dev/null +++ b/contests/Round#849(Div4)/E/main_input2.txt @@ -0,0 +1,3 @@ +1 +7 +-1 1 -1 1 -1 1 -1 \ No newline at end of file diff --git a/contests/Round#849(Div4)/E/main_output0.txt b/contests/Round#849(Div4)/E/main_output0.txt new file mode 100644 index 0000000..9ce57b7 --- /dev/null +++ b/contests/Round#849(Div4)/E/main_output0.txt @@ -0,0 +1,5 @@ +1 +13 +6 +39 +2 diff --git a/contests/Round#849(Div4)/E/main_output1.txt b/contests/Round#849(Div4)/E/main_output1.txt new file mode 100644 index 0000000..a5c750f --- /dev/null +++ b/contests/Round#849(Div4)/E/main_output1.txt @@ -0,0 +1 @@ +27 \ No newline at end of file diff --git a/contests/Round#849(Div4)/E/main_output2.txt b/contests/Round#849(Div4)/E/main_output2.txt new file mode 100644 index 0000000..c793025 --- /dev/null +++ b/contests/Round#849(Div4)/E/main_output2.txt @@ -0,0 +1 @@ +7 \ No newline at end of file diff --git a/contests/Round#849(Div4)/F/main b/contests/Round#849(Div4)/F/main new file mode 100755 index 0000000..ebe8061 Binary files /dev/null and b/contests/Round#849(Div4)/F/main differ diff --git a/contests/Round#849(Div4)/F/main.cpp b/contests/Round#849(Div4)/F/main.cpp new file mode 100755 index 0000000..79a7299 --- /dev/null +++ b/contests/Round#849(Div4)/F/main.cpp @@ -0,0 +1,114 @@ +#include +using namespace std; + +using ll = long long; +using pi = 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 + +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 + */ + +int sumDigits(int x) { + int sum = 0; + while(x) { + sum += x % 10; + x /= 10; + } + return sum; +} + +void solve() { + int n, q; + cin >> n >> q; + vi v(n); + for (auto &x: v) cin >> x; // O(n) + for (int i = 0; i < q; i++) { // O(q) + int x, y, z; + cin >> x; + if (x == 1) { + cin >> y >> z; + for (int i = y - 1; i < z; i++) { + v[i] = sumDigits(v[i]); + } + } else { + cin >> y; + cout << v[y - 1] << '\n'; + } + } +} + +int main () { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while(tt--) { + solve(); + } +} + + diff --git a/contests/Round#849(Div4)/F/main_input0.txt b/contests/Round#849(Div4)/F/main_input0.txt new file mode 100644 index 0000000..e5b8ab3 --- /dev/null +++ b/contests/Round#849(Div4)/F/main_input0.txt @@ -0,0 +1,19 @@ +3 +5 8 +1 420 69 1434 2023 +1 2 3 +2 2 +2 3 +2 4 +1 2 5 +2 1 +2 3 +2 5 +2 3 +9999 1000 +1 1 2 +2 1 +2 2 +1 1 +1 +2 1 diff --git a/contests/Round#849(Div4)/F/main_output0.txt b/contests/Round#849(Div4)/F/main_output0.txt new file mode 100644 index 0000000..974b142 --- /dev/null +++ b/contests/Round#849(Div4)/F/main_output0.txt @@ -0,0 +1,9 @@ +6 +15 +1434 +1 +6 +7 +36 +1 +1 diff --git a/contests/Round#849(Div4)/G1/main b/contests/Round#849(Div4)/G1/main new file mode 100755 index 0000000..d3376c0 Binary files /dev/null and b/contests/Round#849(Div4)/G1/main differ diff --git a/contests/Round#849(Div4)/G1/main.cpp b/contests/Round#849(Div4)/G1/main.cpp new file mode 100755 index 0000000..fa55787 --- /dev/null +++ b/contests/Round#849(Div4)/G1/main.cpp @@ -0,0 +1,108 @@ +#include +using namespace std; + +using ll = long long; +using pi = 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 + +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, c; + cin >> n >> c; + vi v(n); + for (int i = 0; i < n; i++) { + int x; + cin >> x; + v[i] = x + i + 1; + } + sort(all(v)); + int ans = 0; + for (auto x : v) { + if (c - x >= 0) { + ans++; + } else { + break; + } + c -= x; + } + cout << ans << '\n'; +} + +int main () { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while(tt--) { + solve(); + } +} + + diff --git a/contests/Round#849(Div4)/G1/main_input0.txt b/contests/Round#849(Div4)/G1/main_input0.txt new file mode 100644 index 0000000..a76b8f7 --- /dev/null +++ b/contests/Round#849(Div4)/G1/main_input0.txt @@ -0,0 +1,21 @@ +10 +5 6 +1 1 1 1 1 +8 32 +100 52 13 6 9 4 100 35 +1 1 +5 +4 5 +4 3 2 1 +5 9 +2 3 1 4 1 +5 8 +2 3 1 4 1 +4 3 +2 3 4 1 +4 9 +5 4 3 3 +2 14 +7 5 +5 600000000 +500000000 400000000 300000000 200000000 100000000 diff --git a/contests/Round#849(Div4)/G1/main_output0.txt b/contests/Round#849(Div4)/G1/main_output0.txt new file mode 100644 index 0000000..c95e0d2 --- /dev/null +++ b/contests/Round#849(Div4)/G1/main_output0.txt @@ -0,0 +1,10 @@ +2 +2 +0 +1 +2 +2 +1 +1 +1 +2 diff --git a/contests/Round#849(Div4)/G2/main b/contests/Round#849(Div4)/G2/main new file mode 100755 index 0000000..a562bbb Binary files /dev/null and b/contests/Round#849(Div4)/G2/main differ diff --git a/contests/Round#849(Div4)/G2/main.cpp b/contests/Round#849(Div4)/G2/main.cpp new file mode 100755 index 0000000..c5114b2 --- /dev/null +++ b/contests/Round#849(Div4)/G2/main.cpp @@ -0,0 +1,142 @@ +#include +using namespace std; + +using ll = long long; +using pi = 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 + +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, c; + cin >> n >> c; + vi v(n); + vi start(n), end(n); + for (auto &x : v) cin >> x; + for (int i = 0; i < n; i++) { + start[i] = v[i] + i + 1; + end[i] = v[i] + n - i; + } + int min_start = *min_element(all(start)); + vi indexes; + for (int i = 0; i < n; i++) { + if (start[i] == min_start) { + indexes.push_back(i); + } + } + int max_end_indx = 0; + int mx = 0; + for (int i = 0; i < indexes.size(); i++) { + if (end[indexes[i]] > mx) { + max_end_indx = indexes[i]; + } + mx = max(mx, end[indexes[i]]); + } + vi final(n); + int ans = 0; + for (int i = 0; i < n; i++) { + if (i == max_end_indx && c - start[i] > 0) { + c -= start[i]; + ans++; + final[i] = INT_MAX; + } else { + final[i] = min(start[i], end[i]); + } + } + sort(all(final)); + print("c: ", c); + print("Final: "); + printv(final); + print("Start: "); + printv(start); + print("End: "); + printv(end); + + for (int i = 0; i < n; i++) { + if (c - final[i] >= 0) { + ans++; + } else { + break; + } + c -= final[i]; + } + cout << ans << '\n'; + +} + +int main () { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while(tt--) { + solve(); + } +} + + diff --git a/contests/Round#849(Div4)/G2/main_input0.txt b/contests/Round#849(Div4)/G2/main_input0.txt new file mode 100644 index 0000000..a76b8f7 --- /dev/null +++ b/contests/Round#849(Div4)/G2/main_input0.txt @@ -0,0 +1,21 @@ +10 +5 6 +1 1 1 1 1 +8 32 +100 52 13 6 9 4 100 35 +1 1 +5 +4 5 +4 3 2 1 +5 9 +2 3 1 4 1 +5 8 +2 3 1 4 1 +4 3 +2 3 4 1 +4 9 +5 4 3 3 +2 14 +7 5 +5 600000000 +500000000 400000000 300000000 200000000 100000000 diff --git a/contests/Round#849(Div4)/G2/main_output0.txt b/contests/Round#849(Div4)/G2/main_output0.txt new file mode 100644 index 0000000..83eaaf6 --- /dev/null +++ b/contests/Round#849(Div4)/G2/main_output0.txt @@ -0,0 +1,10 @@ +2 +3 +0 +1 +3 +2 +1 +1 +2 +2 diff --git a/contests/Round#849(Div4)/G2Joe/main b/contests/Round#849(Div4)/G2Joe/main new file mode 100755 index 0000000..ee70665 Binary files /dev/null and b/contests/Round#849(Div4)/G2Joe/main differ diff --git a/contests/Round#849(Div4)/G2Joe/main.cpp b/contests/Round#849(Div4)/G2Joe/main.cpp new file mode 100755 index 0000000..bdfd50e --- /dev/null +++ b/contests/Round#849(Div4)/G2Joe/main.cpp @@ -0,0 +1,129 @@ +#include +using namespace std; + +using ll = long long; +using pi = 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 + +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, c; + cin >> n >> c; + vector a(n); + for (int i = 0; i < n; i++) { + cin >> a[i]; + } + vector s(n), e(n); + multiset ms; + for (int i = 0; i < n; i++) { + s[i] = a[i] + i + 1; + e[i] = a[i] + n - i; + ms.insert(s[i]); + } + vector> x(n); + for (int i = 0; i < n; i++) { + if (s[i] <= e[i]) { + x[i] = {s[i], -s[i]}; + } else { + x[i] = {e[i], s[i]}; + } + } + sort(x.begin(), x.end()); + int ans = 0; + bool found = false; + while (ans < n && c - x[ans].first >= 0) { + c -= x[ans].first; + ms.erase(ms.find(abs(x[ans].second))); + if (x[ans].second < 0) { + found = true; + } + ans += 1; + } + if (found) { + cout << ans << '\n'; + } else { + while (*ms.begin() > c && ans >= 0) { + c += x[ans - 1].first; + ms.insert(abs(x[ans - 1].second)); + ans -= 1; + } + cout << ans + 1 << '\n'; + } +} + +int main () { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while(tt--) { + solve(); + } +} + diff --git a/contests/Round#849(Div4)/G2Joe/main_input0.txt b/contests/Round#849(Div4)/G2Joe/main_input0.txt new file mode 100644 index 0000000..a76b8f7 --- /dev/null +++ b/contests/Round#849(Div4)/G2Joe/main_input0.txt @@ -0,0 +1,21 @@ +10 +5 6 +1 1 1 1 1 +8 32 +100 52 13 6 9 4 100 35 +1 1 +5 +4 5 +4 3 2 1 +5 9 +2 3 1 4 1 +5 8 +2 3 1 4 1 +4 3 +2 3 4 1 +4 9 +5 4 3 3 +2 14 +7 5 +5 600000000 +500000000 400000000 300000000 200000000 100000000 diff --git a/contests/Round#849(Div4)/G2Joe/main_input1.txt b/contests/Round#849(Div4)/G2Joe/main_input1.txt new file mode 100644 index 0000000..66160b6 --- /dev/null +++ b/contests/Round#849(Div4)/G2Joe/main_input1.txt @@ -0,0 +1,3 @@ +1 +2 5 +4 2 \ No newline at end of file diff --git a/contests/Round#849(Div4)/G2Joe/main_input2.txt b/contests/Round#849(Div4)/G2Joe/main_input2.txt new file mode 100644 index 0000000..b579a0a --- /dev/null +++ b/contests/Round#849(Div4)/G2Joe/main_input2.txt @@ -0,0 +1,3 @@ +1 +3 4 +5 5 1 \ No newline at end of file diff --git a/contests/Round#849(Div4)/G2Joe/main_output0.txt b/contests/Round#849(Div4)/G2Joe/main_output0.txt new file mode 100644 index 0000000..83eaaf6 --- /dev/null +++ b/contests/Round#849(Div4)/G2Joe/main_output0.txt @@ -0,0 +1,10 @@ +2 +3 +0 +1 +3 +2 +1 +1 +2 +2 diff --git a/contests/Round#849(Div4)/G2Joe/main_output1.txt b/contests/Round#849(Div4)/G2Joe/main_output1.txt new file mode 100644 index 0000000..56a6051 --- /dev/null +++ b/contests/Round#849(Div4)/G2Joe/main_output1.txt @@ -0,0 +1 @@ +1 \ No newline at end of file diff --git a/contests/Round#849(Div4)/G2Joe/main_output2.txt b/contests/Round#849(Div4)/G2Joe/main_output2.txt new file mode 100644 index 0000000..56a6051 --- /dev/null +++ b/contests/Round#849(Div4)/G2Joe/main_output2.txt @@ -0,0 +1 @@ +1 \ No newline at end of file diff --git a/contests/Starters78/A/main b/contests/Starters78/A/main new file mode 100755 index 0000000..670aa7e Binary files /dev/null and b/contests/Starters78/A/main differ diff --git a/contests/Starters78/A/main.cpp b/contests/Starters78/A/main.cpp new file mode 100755 index 0000000..411b7ee --- /dev/null +++ b/contests/Starters78/A/main.cpp @@ -0,0 +1,94 @@ +#include +using namespace std; + +using ll = long long; +using pi = 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 + +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, x; + cin >> n >> x; + vi v(n); + for (auto &x : v) cin >> x; + sort(rall(v)); + cout << v[x - 1] - 1 << '\n'; +} + +int main () { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while(tt--) { + solve(); + } +} + + diff --git a/contests/Starters78/A/main_input0.txt b/contests/Starters78/A/main_input0.txt new file mode 100644 index 0000000..0a0258a --- /dev/null +++ b/contests/Starters78/A/main_input0.txt @@ -0,0 +1,7 @@ +3 +2 2 +5 1 +4 1 +5 1 7 4 +4 3 +15 70 100 31 diff --git a/contests/Starters78/A/main_output0.txt b/contests/Starters78/A/main_output0.txt new file mode 100644 index 0000000..288d060 --- /dev/null +++ b/contests/Starters78/A/main_output0.txt @@ -0,0 +1,3 @@ +0 +6 +30 diff --git a/contests/Starters78/B/main b/contests/Starters78/B/main new file mode 100755 index 0000000..0e36586 Binary files /dev/null and b/contests/Starters78/B/main differ diff --git a/contests/Starters78/B/main.cpp b/contests/Starters78/B/main.cpp new file mode 100755 index 0000000..d5c6cce --- /dev/null +++ b/contests/Starters78/B/main.cpp @@ -0,0 +1,109 @@ +#include +using namespace std; + +using ll = long long; +using pi = 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 + +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, x; + cin >> n >> x; + if ((x < 0 && n - abs(x) < 1) || (x > 0 && n + 1 < x)) { + cout << "-1\n"; + return; + } + if (x == 0) { + for (int i = 0; i < n - 1; i++) { + cout << "*"; + } + cout << "-\n"; + return; + } + if (x > 0) { + for (int i = 0; i < n - abs(x) + 1; i++) { + cout << "*"; + } + for (int i = 0; i < abs(x) - 1; i++) { + cout << "+"; + } + } else { + for (int i = 0; i < n - abs(x) - 1; i++) { + cout << "*"; + } + for (int i = 0; i < abs(x) + 1; i++) { + cout << "-"; + } + + } + cout << '\n'; +} + +int main() { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while (tt--) { + solve(); + } +} diff --git a/contests/Starters78/B/main_input0.txt b/contests/Starters78/B/main_input0.txt new file mode 100644 index 0000000..1867e89 --- /dev/null +++ b/contests/Starters78/B/main_input0.txt @@ -0,0 +1,4 @@ +3 +3 4 +2 -5 +3 1 diff --git a/contests/Starters78/B/main_input1.txt b/contests/Starters78/B/main_input1.txt new file mode 100644 index 0000000..2269299 --- /dev/null +++ b/contests/Starters78/B/main_input1.txt @@ -0,0 +1,2 @@ +1 +7 0 \ No newline at end of file diff --git a/contests/Starters78/B/main_input2.txt b/contests/Starters78/B/main_input2.txt new file mode 100644 index 0000000..378d966 --- /dev/null +++ b/contests/Starters78/B/main_input2.txt @@ -0,0 +1,2 @@ +1 +7 -5 \ No newline at end of file diff --git a/contests/Starters78/B/main_input3.txt b/contests/Starters78/B/main_input3.txt new file mode 100644 index 0000000..2269299 --- /dev/null +++ b/contests/Starters78/B/main_input3.txt @@ -0,0 +1,2 @@ +1 +7 0 \ No newline at end of file diff --git a/contests/Starters78/B/main_input4.txt b/contests/Starters78/B/main_input4.txt new file mode 100644 index 0000000..250b313 --- /dev/null +++ b/contests/Starters78/B/main_input4.txt @@ -0,0 +1,2 @@ +1 +2 2 \ No newline at end of file diff --git a/contests/Starters78/B/main_input5.txt b/contests/Starters78/B/main_input5.txt new file mode 100644 index 0000000..563e0d2 --- /dev/null +++ b/contests/Starters78/B/main_input5.txt @@ -0,0 +1,2 @@ +1 +4 -5 \ No newline at end of file diff --git a/contests/Starters78/B/main_input6.txt b/contests/Starters78/B/main_input6.txt new file mode 100644 index 0000000..76f9fe1 --- /dev/null +++ b/contests/Starters78/B/main_input6.txt @@ -0,0 +1,2 @@ +1 +6 -5 \ No newline at end of file diff --git a/contests/Starters78/B/main_input7.txt b/contests/Starters78/B/main_input7.txt new file mode 100644 index 0000000..378d966 --- /dev/null +++ b/contests/Starters78/B/main_input7.txt @@ -0,0 +1,2 @@ +1 +7 -5 \ No newline at end of file diff --git a/contests/Starters78/B/main_output0.txt b/contests/Starters78/B/main_output0.txt new file mode 100644 index 0000000..45554cc --- /dev/null +++ b/contests/Starters78/B/main_output0.txt @@ -0,0 +1,3 @@ ++++ +-1 +*+- diff --git a/contests/Starters78/B/main_output1.txt b/contests/Starters78/B/main_output1.txt new file mode 100644 index 0000000..5e1d35c --- /dev/null +++ b/contests/Starters78/B/main_output1.txt @@ -0,0 +1 @@ +******- \ No newline at end of file diff --git a/contests/Starters78/B/main_output2.txt b/contests/Starters78/B/main_output2.txt new file mode 100644 index 0000000..1092cca --- /dev/null +++ b/contests/Starters78/B/main_output2.txt @@ -0,0 +1 @@ +*------ \ No newline at end of file diff --git a/contests/Starters78/B/main_output3.txt b/contests/Starters78/B/main_output3.txt new file mode 100644 index 0000000..5e1d35c --- /dev/null +++ b/contests/Starters78/B/main_output3.txt @@ -0,0 +1 @@ +******- \ No newline at end of file diff --git a/contests/Starters78/B/main_output4.txt b/contests/Starters78/B/main_output4.txt new file mode 100644 index 0000000..67a4ed1 --- /dev/null +++ b/contests/Starters78/B/main_output4.txt @@ -0,0 +1 @@ +*+ \ No newline at end of file diff --git a/contests/Starters78/B/main_output5.txt b/contests/Starters78/B/main_output5.txt new file mode 100644 index 0000000..d7d17fc --- /dev/null +++ b/contests/Starters78/B/main_output5.txt @@ -0,0 +1 @@ +-1 \ No newline at end of file diff --git a/contests/Starters78/B/main_output6.txt b/contests/Starters78/B/main_output6.txt new file mode 100644 index 0000000..8a8f91e --- /dev/null +++ b/contests/Starters78/B/main_output6.txt @@ -0,0 +1 @@ +------ \ No newline at end of file diff --git a/contests/Starters78/B/main_output7.txt b/contests/Starters78/B/main_output7.txt new file mode 100644 index 0000000..1092cca --- /dev/null +++ b/contests/Starters78/B/main_output7.txt @@ -0,0 +1 @@ +*------ \ No newline at end of file diff --git a/contests/Starters78/C/main b/contests/Starters78/C/main new file mode 100755 index 0000000..5162083 Binary files /dev/null and b/contests/Starters78/C/main differ diff --git a/contests/Starters78/C/main.cpp b/cont