aboutsummaryrefslogtreecommitdiff
path: root/contests/Round889
diff options
context:
space:
mode:
authoromagdy7 <omar.professional8777@gmail.com>2023-07-29 23:46:41 +0300
committeromagdy7 <omar.professional8777@gmail.com>2023-07-29 23:46:41 +0300
commit14b6ca598cdb041b56822fae224134610b7bb345 (patch)
tree71ceda0b702059f1cf9e847672cab724ac3aa3b5 /contests/Round889
parent350518c931e4a9fa8445f47f4dadc019132a7b8a (diff)
downloadcompetitive-programming-14b6ca598cdb041b56822fae224134610b7bb345.tar.xz
competitive-programming-14b6ca598cdb041b56822fae224134610b7bb345.zip
Solved A from the last Div2
Diffstat (limited to 'contests/Round889')
-rwxr-xr-xcontests/Round889/A/mainbin0 -> 19784 bytes
-rwxr-xr-xcontests/Round889/A/main.cpp143
-rw-r--r--contests/Round889/A/main_input0.txt11
-rw-r--r--contests/Round889/A/main_output0.txt5
-rwxr-xr-xcontests/Round889/B/mainbin0 -> 17096 bytes
-rwxr-xr-xcontests/Round889/B/main.cpp160
-rw-r--r--contests/Round889/B/main.py23
-rw-r--r--contests/Round889/B/main_input0.txt11
-rw-r--r--contests/Round889/B/main_output0.txt10
-rwxr-xr-xcontests/Round889/C/mainbin0 -> 27456 bytes
-rwxr-xr-xcontests/Round889/C/main.cpp178
-rw-r--r--contests/Round889/C/main_input0.txt21
-rw-r--r--contests/Round889/C/main_input1.txt3
-rw-r--r--contests/Round889/C/main_input2.txt3
-rw-r--r--contests/Round889/C/main_output0.txt113
-rw-r--r--contests/Round889/C/main_output1.txt1
-rw-r--r--contests/Round889/C/main_output2.txt1
17 files changed, 683 insertions, 0 deletions
diff --git a/contests/Round889/A/main b/contests/Round889/A/main
new file mode 100755
index 0000000..589aa45
--- /dev/null
+++ b/contests/Round889/A/main
Binary files differ
diff --git a/contests/Round889/A/main.cpp b/contests/Round889/A/main.cpp
new file mode 100755
index 0000000..7db0097
--- /dev/null
+++ b/contests/Round889/A/main.cpp
@@ -0,0 +1,143 @@
+#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;
+ vi v(n);
+ int outOfPlace = 0;
+ for (int i = 0; i < n; i++) {
+ cin >> v[i];
+ outOfPlace += (v[i] == i + 1);
+ }
+ if (outOfPlace % 2 == 0) {
+ cout << outOfPlace / 2 << '\n';
+ } else {
+ cout << (outOfPlace / 2) + 1 << '\n';
+ }
+}
+
+int main() {
+ ios_base::sync_with_stdio(false);
+ cin.tie(NULL);
+ int tt;
+ cin >> tt;
+ while (tt--) {
+ solve();
+ }
+}
diff --git a/contests/Round889/A/main_input0.txt b/contests/Round889/A/main_input0.txt
new file mode 100644
index 0000000..e19d497
--- /dev/null
+++ b/contests/Round889/A/main_input0.txt
@@ -0,0 +1,11 @@
+5
+2
+2 1
+3
+1 2 3
+5
+1 2 5 4 3
+4
+1 2 4 3
+10
+10 2 1 3 6 5 4 7 9 8
diff --git a/contests/Round889/A/main_output0.txt b/contests/Round889/A/main_output0.txt
new file mode 100644
index 0000000..116980c
--- /dev/null
+++ b/contests/Round889/A/main_output0.txt
@@ -0,0 +1,5 @@
+0
+2
+2
+1
+1
diff --git a/contests/Round889/B/main b/contests/Round889/B/main
new file mode 100755
index 0000000..008296e
--- /dev/null
+++ b/contests/Round889/B/main
Binary files differ
diff --git a/contests/Round889/B/main.cpp b/contests/Round889/B/main.cpp
new file mode 100755
index 0000000..86c739a
--- /dev/null
+++ b/contests/Round889/B/main.cpp
@@ -0,0 +1,160 @@
+#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 factorial(ll n) {
+ ll ans = 1;
+ for (ll i = 2; i <= n; i++) {
+ ans *= i;
+ }
+ return ans;
+}
+
+void solve() {
+ ll n;
+ cin >> n;
+ vll v;
+ int i = 0;
+ int ans = 0;
+ for (int i = 0; i < 25; i++) {
+ v.pb(factorial(i));
+ }
+ dbg(ans);
+ ll mx = 1;
+ dbg(v.size());
+ for (ll i = 1; i < v.size(); i++) {
+ for (ll j = i + 1; j < v.size(); j++) {
+ if (n % (v[j] / v[i - 1]) == 0) {
+ mx = max(mx, j - i + 1);
+ dbg("j: ", j, "i: ", i);
+ dbg(v[j] / v[i]);
+ }
+ }
+ }
+ dbg("=================");
+ cout << mx << '\n';
+}
+
+int main() {
+ ios_base::sync_with_stdio(false);
+ cin.tie(NULL);
+ int tt;
+ cin >> tt;
+ while (tt--) {
+ solve();
+ }
+}
diff --git a/contests/Round889/B/main.py b/contests/Round889/B/main.py
new file mode 100644
index 0000000..3a99f47
--- /dev/null
+++ b/contests/Round889/B/main.py
@@ -0,0 +1,23 @@
+def factorial(n):
+ ans = 1
+ for i in range(2, n + 1):
+ ans *= i
+ return ans
+
+def solve():
+ n = int(input())
+ v = []
+ for i in range(100):
+ v.append(factorial(i))
+ mx = 1
+ for i in range(1, len(v)):
+ for j in range(i + 1, len(v)):
+ if n % (v[j] // v[i - 1]) == 0:
+ print("-> ", j - i + 1)
+ mx = max(mx, j - i + 1)
+ print(mx)
+
+if __name__ == "__main__":
+ tt = int(input())
+ for _ in range(tt):
+ solve()
diff --git a/contests/Round889/B/main_input0.txt b/contests/Round889/B/main_input0.txt
new file mode 100644
index 0000000..a603728
--- /dev/null
+++ b/contests/Round889/B/main_input0.txt
@@ -0,0 +1,11 @@
+10
+1
+40
+990990
+4204474560
+169958913706572972
+365988220345828080
+387701719537826430
+620196883578129853
+864802341280805662
+1000000000000000000
diff --git a/contests/Round889/B/main_output0.txt b/contests/Round889/B/main_output0.txt
new file mode 100644
index 0000000..021f75a
--- /dev/null
+++ b/contests/Round889/B/main_output0.txt
@@ -0,0 +1,10 @@
+1
+2
+3
+6
+4
+22
+3
+1
+2
+2
diff --git a/contests/Round889/C/main b/contests/Round889/C/main
new file mode 100755
index 0000000..240f802
--- /dev/null
+++ b/contests/Round889/C/main
Binary files differ
diff --git a/contests/Round889/C/main.cpp b/contests/Round889/C/main.cpp
new file mode 100755
index 0000000..b07e93d
--- /dev/null
+++ b/contests/Round889/C/main.cpp
@@ -0,0 +1,178 @@
+#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;
+ vll v(n);
+ ll mx = -30;
+ for (int i = 0; i < n; i++) {
+ cin >> v[i];
+ mx = max(mx, v[i]);
+ }
+ auto it = max_element(all(v)) - v.begin();
+ int k = 50;
+ cout << k << '\n';
+ for (int i = 0; i < 5; i++) {
+ cout << it + 1 << ' ' << it + 1 << '\n';
+ v[it] += v[it];
+ k--;
+ }
+ for (int i = 0; i < n; i++) {
+ if (v[i] < 0) {
+ cout << i + 1 << ' ' << it + 1 << '\n';
+ v[i] += v[it];
+ k--;
+ }
+ }
+ cout << 1 << ' ' << it + 1 << '\n';
+ v[0] += v[it];
+ k--;
+ if (mx < 0) {
+ for (int i = n - 1; i > 0; i--) {
+ cout << i << ' ' << i + 1 << '\n';
+ v[i - 1] += v[i];
+ k--;
+ }
+ for (int i = 0; i < k; i++) {
+ cout << 1 << ' ' << 1 << '\n';
+ v[0] += v[0];
+ }
+ } else {
+ for (int i = 0; i < n - 1; i++) {
+ cout << i + 2 << ' ' << i + 1 << '\n';
+ v[i + 1] += v[i];
+ k--;
+ }
+ for (int i = 0; i < k; i++) {
+ cout << n << ' ' << n << '\n';
+ v[n - 1] += v[n - 1];
+ }
+ }
+ dbg(v);
+}
+
+int main() {
+ ios_base::sync_with_stdio(false);
+ cin.tie(NULL);
+ int tt;
+ cin >> tt;
+ while (tt--) {
+ solve();
+ }
+}
diff --git a/contests/Round889/C/main_input0.txt b/contests/Round889/C/main_input0.txt
new file mode 100644
index 0000000..70ae50d
--- /dev/null
+++ b/contests/Round889/C/main_input0.txt
@@ -0,0 +1,21 @@
+10
+2
+2 1
+4
+1 2 -10 3
+5
+2 1 1 1 1
+8
+0 0 0 0 0 0 0 0
+5
+1 2 -4 3 -10
+10
+11 12 13 14 15 -15 -16 -17 -18 -19
+7
+1 9 3 -4 -3 -2 -1
+3
+10 9 8
+20
+1 -14 2 -10 6 -5 10 -13 10 7 -14 19 -5 19 1 18 -16 -7 12 8
+20
+-15 -17 -13 8 14 -13 10 -4 11 -4 -16 -6 15 -4 -2 7 -9 5 -5 17
diff --git a/contests/Round889/C/main_input1.txt b/contests/Round889/C/main_input1.txt
new file mode 100644
index 0000000..18b74fd
--- /dev/null
+++ b/contests/Round889/C/main_input1.txt
@@ -0,0 +1,3 @@
+1
+5
+-1 -2 -3 -4 -5 \ No newline at end of file
diff --git a/contests/Round889/C/main_input2.txt b/contests/Round889/C/main_input2.txt
new file mode 100644
index 0000000..caa986f
--- /dev/null
+++ b/contests/Round889/C/main_input2.txt
@@ -0,0 +1,3 @@
+1
+20
+-1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 \ No newline at end of file
diff --git a/contests/Round889/C/main_output0.txt b/contests/Round889/C/main_output0.txt
new file mode 100644
index 0000000..3af4239
--- /dev/null
+++ b/contests/Round889/C/main_output0.txt
@@ -0,0 +1,113 @@
+1
+2 1
+3
+4 4
+4 4
+3 4
+4
+2 1
+3 1
+4 1
+5 1
+0
+7
+3 4
+3 4
+5 4
+5 4
+5 4
+5 4
+5 4
+15
+6 1
+6 1
+6 1
+7 2
+7 2
+7 2
+8 3
+8 3
+8 3
+9 4
+9 4
+9 4
+10 5
+10 5
+10 5
+8
+3 4
+3 4
+2 4
+2 4
+2 4
+2 4
+1 4
+1 4
+3
+2 1
+3 1
+3 1
+31
+14 1
+18 7
+13 11
+15 11
+6 4
+5 17
+19 6
+19 12
+10 5
+11 12
+1 17
+15 19
+16 10
+14 2
+16 11
+20 7
+7 6
+9 5
+3 6
+6 14
+17 18
+18 14
+12 3
+17 16
+8 18
+13 16
+9 8
+14 8
+16 2
+11 8
+12 7
+31
+5 12
+19 13
+9 1
+5 17
+18 19
+6 16
+15 8
+6 9
+15 14
+7 10
+19 7
+17 20
+14 4
+15 20
+4 3
+1 8
+16 12
+16 15
+5 6
+12 10
+11 15
+20 3
+20 19
+13 14
+11 14
+18 10
+7 3
+12 17
+4 7
+13 2
+11 13
diff --git a/contests/Round889/C/main_output1.txt b/contests/Round889/C/main_output1.txt
new file mode 100644
index 0000000..7813681
--- /dev/null
+++ b/contests/Round889/C/main_output1.txt
@@ -0,0 +1 @@
+5 \ No newline at end of file
diff --git a/contests/Round889/C/main_output2.txt b/contests/Round889/C/main_output2.txt
new file mode 100644
index 0000000..7813681
--- /dev/null
+++ b/contests/Round889/C/main_output2.txt
@@ -0,0 +1 @@
+5 \ No newline at end of file