aboutsummaryrefslogtreecommitdiff
path: root/contests/Round888/C
diff options
context:
space:
mode:
authoromagdy7 <omar.professional8777@gmail.com>2023-07-25 21:47:54 +0300
committeromagdy7 <omar.professional8777@gmail.com>2023-07-25 21:47:54 +0300
commit41ce2d5446f6f075eb8711fe1ec50b7d0e53e5f4 (patch)
tree308693614a9a51d8fd6283ee364060ca07ce647d /contests/Round888/C
parent6b548332bfc6469756526002971c422f43f86d0a (diff)
downloadcompetitive-programming-41ce2d5446f6f075eb8711fe1ec50b7d0e53e5f4.tar.xz
competitive-programming-41ce2d5446f6f075eb8711fe1ec50b7d0e53e5f4.zip
Solved 3 problems in today's Div3 round
Diffstat (limited to 'contests/Round888/C')
-rwxr-xr-xcontests/Round888/C/mainbin0 -> 24680 bytes
-rwxr-xr-xcontests/Round888/C/main.cpp163
-rw-r--r--contests/Round888/C/main_input0.txt21
-rw-r--r--contests/Round888/C/main_input1.txt3
-rw-r--r--contests/Round888/C/main_input2.txt3
-rw-r--r--contests/Round888/C/main_output0.txt10
-rw-r--r--contests/Round888/C/main_output1.txt1
-rw-r--r--contests/Round888/C/main_output2.txt1
8 files changed, 202 insertions, 0 deletions
diff --git a/contests/Round888/C/main b/contests/Round888/C/main
new file mode 100755
index 0000000..acd2636
--- /dev/null
+++ b/contests/Round888/C/main
Binary files differ
diff --git a/contests/Round888/C/main.cpp b/contests/Round888/C/main.cpp
new file mode 100755
index 0000000..73f6cf8
--- /dev/null
+++ b/contests/Round888/C/main.cpp
@@ -0,0 +1,163 @@
+#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, k;
+ cin >> n >> k;
+ vi v(n);
+ vi fq(n + 1);
+ for (auto &x : v) {
+ cin >> x;
+ fq[x]++;
+ }
+ if (v[0] == v[n - 1] && fq[v[0]] >= k) {
+ cout << "YES\n";
+ return;
+ }
+ int last_occ_f = -1;
+ int last_occ_l = -1;
+ int cnt_f = k;
+ int cnt_l = k;
+ for (int i = 0; i < n; i++) {
+ if (v[i] == v[0] && cnt_f != 0) {
+ last_occ_f = i;
+ cnt_f--;
+ }
+ }
+ for (int i = n - 1; i > 0; i--) {
+ if (v[i] == v[n - 1] && cnt_l != 0) {
+ last_occ_l = i;
+ cnt_l--;
+ }
+ }
+ if (fq[v.front()] >= k && fq[v.back()] >= k && last_occ_f < last_occ_l) {
+ cout << "YES\n";
+ } else {
+ 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/Round888/C/main_input0.txt b/contests/Round888/C/main_input0.txt
new file mode 100644
index 0000000..5ab5138
--- /dev/null
+++ b/contests/Round888/C/main_input0.txt
@@ -0,0 +1,21 @@
+10
+4 2
+1 1 1 1
+14 3
+1 2 1 1 7 5 3 3 1 3 4 4 2 4
+3 3
+3 1 3
+10 4
+1 2 1 2 1 2 1 2 1 2
+6 2
+1 3 4 1 6 6
+2 2
+1 1
+4 2
+2 1 1 1
+2 1
+1 2
+3 2
+2 2 2
+4 1
+1 1 2 2
diff --git a/contests/Round888/C/main_input1.txt b/contests/Round888/C/main_input1.txt
new file mode 100644
index 0000000..79cc46c
--- /dev/null
+++ b/contests/Round888/C/main_input1.txt
@@ -0,0 +1,3 @@
+1
+14 3
+1 2 1 1 7 5 3 3 1 3 4 4 2 4 \ No newline at end of file
diff --git a/contests/Round888/C/main_input2.txt b/contests/Round888/C/main_input2.txt
new file mode 100644
index 0000000..5042551
--- /dev/null
+++ b/contests/Round888/C/main_input2.txt
@@ -0,0 +1,3 @@
+1
+8 2
+1 1 6 1 5 5 6 6 \ No newline at end of file
diff --git a/contests/Round888/C/main_output0.txt b/contests/Round888/C/main_output0.txt
new file mode 100644
index 0000000..030f178
--- /dev/null
+++ b/contests/Round888/C/main_output0.txt
@@ -0,0 +1,10 @@
+YES
+YES
+NO
+NO
+YES
+YES
+NO
+YES
+YES
+YES
diff --git a/contests/Round888/C/main_output1.txt b/contests/Round888/C/main_output1.txt
new file mode 100644
index 0000000..d2bb323
--- /dev/null
+++ b/contests/Round888/C/main_output1.txt
@@ -0,0 +1 @@
+YES \ No newline at end of file
diff --git a/contests/Round888/C/main_output2.txt b/contests/Round888/C/main_output2.txt
new file mode 100644
index 0000000..d2bb323
--- /dev/null
+++ b/contests/Round888/C/main_output2.txt
@@ -0,0 +1 @@
+YES \ No newline at end of file