diff options
| author | omagdy7 <omar.professional8777@gmail.com> | 2023-07-25 21:47:54 +0300 |
|---|---|---|
| committer | omagdy7 <omar.professional8777@gmail.com> | 2023-07-25 21:47:54 +0300 |
| commit | 41ce2d5446f6f075eb8711fe1ec50b7d0e53e5f4 (patch) | |
| tree | 308693614a9a51d8fd6283ee364060ca07ce647d /codeforces | |
| parent | 6b548332bfc6469756526002971c422f43f86d0a (diff) | |
| download | competitive-programming-41ce2d5446f6f075eb8711fe1ec50b7d0e53e5f4.tar.xz competitive-programming-41ce2d5446f6f075eb8711fe1ec50b7d0e53e5f4.zip | |
Solved 3 problems in today's Div3 round
Diffstat (limited to 'codeforces')
16 files changed, 638 insertions, 0 deletions
diff --git a/codeforces/RudolphAndCutTheRope/main b/codeforces/RudolphAndCutTheRope/main Binary files differnew file mode 100755 index 0000000..c5c066e --- /dev/null +++ b/codeforces/RudolphAndCutTheRope/main diff --git a/codeforces/RudolphAndCutTheRope/main.cpp b/codeforces/RudolphAndCutTheRope/main.cpp new file mode 100755 index 0000000..b48c704 --- /dev/null +++ b/codeforces/RudolphAndCutTheRope/main.cpp @@ -0,0 +1,139 @@ +#include <bits/stdc++.h> +using namespace std; + +using ll = long long; +using pii = pair<int, int>; +using vpi = vector<pii>; +using vi = vector<int>; +using vll = vector<long long>; +using mpii = map<int, int>; +using mpll = map<ll, ll>; +using db = long double; + +#define pb push_back +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() +#define lb lower_bound +#define ub upper_bound +#define make_unique(x) \ + sort(all((x))); \ + (x).resize(unique(all((x))) - (x).begin()) +#define ceil(a, b) ((a) + (b) - 1) / (b)) + +const int MOD = (int)1e9 + 7; +const db PI = acos((db)-1); +const int dx[4]{1, 0, -1, 0}; +const int dy[4]{0, 1, 0, -1}; + +template <typename K, typename V> +ostream &operator<<(ostream &os, const pair<K, V> &p); +template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec); +template <typename K, typename V> +ostream &operator<<(ostream &os, const map<K, V> &m); +template <typename K, typename V> +ostream &operator<<(ostream &os, const unordered_map<K, V> &m); +template <typename T> ostream &operator<<(ostream &os, const set<T> &s); +template <typename T> +ostream &operator<<(ostream &os, const unordered_set<T> &s); + +template <typename K, typename V> +ostream &operator<<(ostream &os, const pair<K, V> &p) { + os << "(" << p.first << ", " << p.second << ")"; + return os; +} + +template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { + os << "{"; + for (size_t i = 0; i < vec.size(); ++i) { + if (i > 0) + os << ", "; + os << vec[i]; + } + os << "}"; + return os; +} + +template <typename K, typename V> +ostream &operator<<(ostream &os, const map<K, V> &m) { + os << "{"; + for (const auto &p : m) { + os << p.first << ": " << p.second << ", "; + } + os << "}"; + return os; +} + +template <typename K, typename V> +ostream &operator<<(ostream &os, const unordered_map<K, V> &m) { + os << "{"; + for (const auto &p : m) { + os << p.first << ": " << p.second << ", "; + } + os << "}"; + return os; +} + +template <typename T> ostream &operator<<(ostream &os, const set<T> &s) { + int i = 0; + os << "{"; + for (const auto &e : s) { + if (i > 0) + os << ", "; + os << e; + i++; + } + os << "}"; + return os; +} + +template <typename T> +ostream &operator<<(ostream &os, const unordered_set<T> &s) { + int i = 0; + os << "{"; + for (const auto &e : s) { + if (i > 0) + os << ", "; + os << e; + i++; + } + os << "}"; + return os; +} + +void dbg() { cerr << "\n"; } + +template <typename T, typename... TS> void dbg(T val, TS... vals) { + cerr << val << " "; + dbg(vals...); +} + +/* stuff you should look for: + --------------------------- + * special cases (n=1?) + * int overflow, array bounds + * do smth instead of nothing and stay organized + * WRITE STUFF DOWN + * DON'T GET STUCK ON ONE APPROACH + */ + +void solve() { + int n; + cin >> n; + int cnt = 0; + for (int i = 0; i < n; i++) { + int a, b; + cin >> a >> b; + cnt += (a > b); + } + cout << cnt << '\n'; +} + +int main() { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while (tt--) { + solve(); + } +} diff --git a/codeforces/RudolphAndCutTheRope/main_input0.txt b/codeforces/RudolphAndCutTheRope/main_input0.txt new file mode 100644 index 0000000..521f3ef --- /dev/null +++ b/codeforces/RudolphAndCutTheRope/main_input0.txt @@ -0,0 +1,20 @@ +4 +3 +4 3 +3 1 +1 2 +4 +9 2 +5 2 +7 7 +3 4 +5 +11 7 +5 10 +12 9 +3 2 +1 5 +3 +5 6 +4 5 +7 7 diff --git a/codeforces/RudolphAndCutTheRope/main_output0.txt b/codeforces/RudolphAndCutTheRope/main_output0.txt new file mode 100644 index 0000000..8e7c5e0 --- /dev/null +++ b/codeforces/RudolphAndCutTheRope/main_output0.txt @@ -0,0 +1,4 @@ +2 +2 +3 +0 diff --git a/codeforces/RudolphAndTheAnotherCompetition/main b/codeforces/RudolphAndTheAnotherCompetition/main Binary files differnew file mode 100755 index 0000000..92b0413 --- /dev/null +++ b/codeforces/RudolphAndTheAnotherCompetition/main diff --git a/codeforces/RudolphAndTheAnotherCompetition/main.cpp b/codeforces/RudolphAndTheAnotherCompetition/main.cpp new file mode 100755 index 0000000..58246cf --- /dev/null +++ b/codeforces/RudolphAndTheAnotherCompetition/main.cpp @@ -0,0 +1,196 @@ +#include <bits/stdc++.h> +using namespace std; + +using ll = long long; +using pii = pair<int, int>; +using vpi = vector<pii>; +using vi = vector<int>; +using vll = vector<long long>; +using mpii = map<int, int>; +using mpll = map<ll, ll>; +using db = long double; + +#define pb push_back +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() +#define lb lower_bound +#define ub upper_bound +#define make_unique(x) \ + sort(all((x))); \ + (x).resize(unique(all((x))) - (x).begin()) +#define ceil(a, b) ((a) + (b) - 1) / (b)) + +const int MOD = (int)1e9 + 7; +const db PI = acos((db)-1); +const int dx[4]{1, 0, -1, 0}; +const int dy[4]{0, 1, 0, -1}; + +template <typename K, typename V> +ostream &operator<<(ostream &os, const pair<K, V> &p); +template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec); +template <typename K, typename V> +ostream &operator<<(ostream &os, const map<K, V> &m); +template <typename K, typename V> +ostream &operator<<(ostream &os, const unordered_map<K, V> &m); +template <typename T> ostream &operator<<(ostream &os, const set<T> &s); +template <typename T> +ostream &operator<<(ostream &os, const unordered_set<T> &s); + +template <typename K, typename V> +ostream &operator<<(ostream &os, const pair<K, V> &p) { + os << "(" << p.first << ", " << p.second << ")"; + return os; +} + +template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { + os << "{"; + for (size_t i = 0; i < vec.size(); ++i) { + if (i > 0) + os << ", "; + os << vec[i]; + } + os << "}"; + return os; +} + +template <typename K, typename V> +ostream &operator<<(ostream &os, const map<K, V> &m) { + os << "{"; + for (const auto &p : m) { + os << p.first << ": " << p.second << ", "; + } + os << "}"; + return os; +} + +template <typename K, typename V> +ostream &operator<<(ostream &os, const unordered_map<K, V> &m) { + os << "{"; + for (const auto &p : m) { + os << p.first << ": " << p.second << ", "; + } + os << "}"; + return os; +} + +template <typename T> ostream &operator<<(ostream &os, const set<T> &s) { + int i = 0; + os << "{"; + for (const auto &e : s) { + if (i > 0) + os << ", "; + os << e; + i++; + } + os << "}"; + return os; +} + +template <typename T> +ostream &operator<<(ostream &os, const unordered_set<T> &s) { + int i = 0; + os << "{"; + for (const auto &e : s) { + if (i > 0) + os << ", "; + os << e; + i++; + } + os << "}"; + return os; +} + +void dbg() { cerr << "\n"; } + +template <typename T, typename... TS> void dbg(T val, TS... vals) { + cerr << val << " "; + dbg(vals...); +} + +/* stuff you should look for: + --------------------------- + * special cases (n=1?) + * int overflow, array bounds + * do smth instead of nothing and stay organized + * WRITE STUFF DOWN + * DON'T GET STUCK ON ONE APPROACH + */ + +ll calc_penalty(vll &v, int b) { + ll penalty = 0; + ll pref = 0; + for (int i = 0; i < b; i++) { + pref += v[i]; + penalty += pref; + } + return penalty; +} + +int calc_problems(vll &v, int h) { + ll sum = 0; + for (int i = 0; i < v.size(); i++) { + if (sum + v[i] > h) { + return i; + } + sum += v[i]; + } + return v.size(); +} + +struct triple { + int pos; + int first; + ll second; +}; + +// operator overloading for == for the triple struct +bool operator==(const triple &p1, const triple &p2) { + return p1.first == p2.first && p1.second == p2.second; +} + +ostream &operator<<(ostream &os, const triple &tr) { + os << "\n {" << tr.first << ' ' << tr.second << ' ' << tr.pos << "}"; + return os; +} + +bool customComparator(triple &p1, triple &p2) { + if (p1.first > p2.first) + return true; + else if (p1.first == p2.first && p1.second == p2.second) { + return p1.pos == 0; + } else if (p1.first == p2.first) + return p1.second < p2.second; + return false; +} + +void solve() { + int n, m, h; + cin >> n >> m >> h; + vector<triple> mp(n); + for (int i = 0; i < n; i++) { + vll v(m); + for (auto &x : v) { + cin >> x; + } + sort(all(v)); + int b = calc_problems(v, h); + ll pen = calc_penalty(v, b); + mp[i] = {i, b, pen}; + } + sort(all(mp), customComparator); + for (int i = 0; i < n; i++) { + if (mp[i].pos == 0) { + cout << i + 1 << '\n'; + } + } +} + +int main() { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while (tt--) { + solve(); + } +} diff --git a/codeforces/RudolphAndTheAnotherCompetition/main_input0.txt b/codeforces/RudolphAndTheAnotherCompetition/main_input0.txt new file mode 100644 index 0000000..6b18f43 --- /dev/null +++ b/codeforces/RudolphAndTheAnotherCompetition/main_input0.txt @@ -0,0 +1,18 @@ +5 +3 3 120 +20 15 110 +90 90 100 +40 40 40 +2 1 120 +30 +30 +1 3 120 +10 20 30 +3 2 27 +8 9 +10 7 +10 8 +3 3 15 +7 2 6 +7 5 4 +1 9 8 diff --git a/codeforces/RudolphAndTheAnotherCompetition/main_input1.txt b/codeforces/RudolphAndTheAnotherCompetition/main_input1.txt new file mode 100644 index 0000000..01faba6 --- /dev/null +++ b/codeforces/RudolphAndTheAnotherCompetition/main_input1.txt @@ -0,0 +1,7 @@ +1 +5 1 50 +1 +1 +1 +1 +1
\ No newline at end of file diff --git a/codeforces/RudolphAndTheAnotherCompetition/main_input2.txt b/codeforces/RudolphAndTheAnotherCompetition/main_input2.txt new file mode 100644 index 0000000..d3819c2 --- /dev/null +++ b/codeforces/RudolphAndTheAnotherCompetition/main_input2.txt @@ -0,0 +1,49 @@ +1 +47 3 129 +2 2 3 +4 1 2 +4 2 1 +3 2 4 +1 4 4 +1 2 1 +5 4 5 +6 4 5 +2 1 6 +5 5 3 +6 4 5 +4 5 6 +4 5 4 +3 6 3 +1 3 6 +2 4 4 +6 6 1 +5 6 3 +6 4 1 +1 5 2 +2 6 5 +2 6 5 +6 3 5 +1 3 4 +5 3 4 +1 1 3 +6 2 6 +2 5 4 +3 3 6 +5 4 2 +6 6 1 +6 3 2 +3 4 6 +1 1 4 +1 3 6 +2 1 4 +6 2 5 +1 6 6 +2 1 3 +4 2 6 +2 2 4 +6 5 2 +6 4 2 +6 3 6 +4 4 6 +6 5 6 +1 4 1
\ No newline at end of file diff --git a/codeforces/RudolphAndTheAnotherCompetition/main_output0.txt b/codeforces/RudolphAndTheAnotherCompetition/main_output0.txt new file mode 100644 index 0000000..df106a2 --- /dev/null +++ b/codeforces/RudolphAndTheAnotherCompetition/main_output0.txt @@ -0,0 +1,5 @@ +2 +1 +1 +2 +1 diff --git a/codeforces/RudolphAndTheAnotherCompetition/main_output1.txt b/codeforces/RudolphAndTheAnotherCompetition/main_output1.txt new file mode 100644 index 0000000..56a6051 --- /dev/null +++ b/codeforces/RudolphAndTheAnotherCompetition/main_output1.txt @@ -0,0 +1 @@ +1
\ No newline at end of file diff --git a/codeforces/RudolphAndTheAnotherCompetition/main_output2.txt b/codeforces/RudolphAndTheAnotherCompetition/main_output2.txt new file mode 100644 index 0000000..9a03714 --- /dev/null +++ b/codeforces/RudolphAndTheAnotherCompetition/main_output2.txt @@ -0,0 +1 @@ +10
\ No newline at end of file diff --git a/codeforces/RudolphAndTicTacToe/main b/codeforces/RudolphAndTicTacToe/main Binary files differnew file mode 100755 index 0000000..a4f1dae --- /dev/null +++ b/codeforces/RudolphAndTicTacToe/main diff --git a/codeforces/RudolphAndTicTacToe/main.cpp b/codeforces/RudolphAndTicTacToe/main.cpp new file mode 100755 index 0000000..650f957 --- /dev/null +++ b/codeforces/RudolphAndTicTacToe/main.cpp @@ -0,0 +1,177 @@ +#include <bits/stdc++.h> +using namespace std; + +using ll = long long; +using pii = pair<int, int>; +using vpi = vector<pii>; +using vi = vector<int>; +using vll = vector<long long>; +using mpii = map<int, int>; +using mpll = map<ll, ll>; +using db = long double; + +#define pb push_back +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() +#define lb lower_bound +#define ub upper_bound +#define make_unique(x) \ + sort(all((x))); \ + (x).resize(unique(all((x))) - (x).begin()) +#define ceil(a, b) ((a) + (b) - 1) / (b)) + +const int MOD = (int)1e9 + 7; +const db PI = acos((db)-1); +const int dx[4]{1, 0, -1, 0}; +const int dy[4]{0, 1, 0, -1}; + +template <typename K, typename V> +ostream &operator<<(ostream &os, const pair<K, V> &p); +template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec); +template <typename K, typename V> +ostream &operator<<(ostream &os, const map<K, V> &m); +template <typename K, typename V> +ostream &operator<<(ostream &os, const unordered_map<K, V> &m); +template <typename T> ostream &operator<<(ostream &os, const set<T> &s); +template <typename T> +ostream &operator<<(ostream &os, const unordered_set<T> &s); + +template <typename K, typename V> +ostream &operator<<(ostream &os, const pair<K, V> &p) { + os << "(" << p.first << ", " << p.second << ")"; + return os; +} + +template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { + os << "{"; + for (size_t i = 0; i < vec.size(); ++i) { + if (i > 0) + os << ", "; + os << vec[i]; + } + os << "}"; + return os; +} + +template <typename K, typename V> +ostream &operator<<(ostream &os, const map<K, V> &m) { + os << "{"; + for (const auto &p : m) { + os << p.first << ": " << p.second << ", "; + } + os << "}"; + return os; +} + +template <typename K, typename V> +ostream &operator<<(ostream &os, const unordered_map<K, V> &m) { + os << "{"; + for (const auto &p : m) { + os << p.first << ": " << p.second << ", "; + } + os << "}"; + return os; +} + +template <typename T> ostream &operator<<(ostream &os, const set<T> &s) { + int i = 0; + os << "{"; + for (const auto &e : s) { + if (i > 0) + os << ", "; + os << e; + i++; + } + os << "}"; + return os; +} + +template <typename T> +ostream &operator<<(ostream &os, const unordered_set<T> &s) { + int i = 0; + os << "{"; + for (const auto &e : s) { + if (i > 0) + os << ", "; + os << e; + i++; + } + os << "}"; + return os; +} + +void dbg() { cerr << "\n"; } + +template <typename T, typename... TS> void dbg(T val, TS... vals) { + cerr << val << " "; + dbg(vals...); +} + +/* stuff you should look for: + --------------------------- + * special cases (n=1?) + * int overflow, array bounds + * do smth instead of nothing and stay organized + * WRITE STUFF DOWN + * DON'T GET STUCK ON ONE APPROACH + */ + +bool isWinner(const vector<string> &board, char player) { + // Check rows + for (int i = 0; i < 3; ++i) { + if (board[i][0] == player && board[i][1] == player && + board[i][2] == player) { + return true; + } + } + + // Check columns + for (int i = 0; i < 3; ++i) { + if (board[0][i] == player && board[1][i] == player && + board[2][i] == player) { + return true; + } + } + + // Check diagonals + if ((board[0][0] == player && board[1][1] == player && + board[2][2] == player) || + (board[0][2] == player && board[1][1] == player && + board[2][0] == player)) { + return true; + } + + return false; +} + +char checkWinner(const vector<string> &board) { + for (char player : {'X', 'O', '+'}) { + if (isWinner(board, player)) { + return player; + } + } + return '.'; // '\0' represents no winner +} + +void solve() { + vector<string> v(3); + for (int i = 0; i < 3; i++) { + cin >> v[i]; + } + char winner = checkWinner(v); + if (winner == '.') { + cout << "DRAW\n"; + } else { + cout << winner << "\n"; + } +} + +int main() { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while (tt--) { + solve(); + } +} diff --git a/codeforces/RudolphAndTicTacToe/main_input0.txt b/codeforces/RudolphAndTicTacToe/main_input0.txt new file mode 100644 index 0000000..f807a3a --- /dev/null +++ b/codeforces/RudolphAndTicTacToe/main_input0.txt @@ -0,0 +1,16 @@ +5 ++X+ +OXO +OX. +O+. ++OX +X+O +.XO +OX. ++++ +O.+ +X.O ++.. +.++ +X.O ++.. diff --git a/codeforces/RudolphAndTicTacToe/main_output0.txt b/codeforces/RudolphAndTicTacToe/main_output0.txt new file mode 100644 index 0000000..e1566f0 --- /dev/null +++ b/codeforces/RudolphAndTicTacToe/main_output0.txt @@ -0,0 +1,5 @@ +X +O ++ +DRAW +DRAW |
