From 41ce2d5446f6f075eb8711fe1ec50b7d0e53e5f4 Mon Sep 17 00:00:00 2001 From: omagdy7 Date: Tue, 25 Jul 2023 21:47:54 +0300 Subject: Solved 3 problems in today's Div3 round --- contests/Round888/C/main | Bin 0 -> 24680 bytes contests/Round888/C/main.cpp | 163 +++++++++++++++++++++++++++++++++++ contests/Round888/C/main_input0.txt | 21 +++++ contests/Round888/C/main_input1.txt | 3 + contests/Round888/C/main_input2.txt | 3 + contests/Round888/C/main_output0.txt | 10 +++ contests/Round888/C/main_output1.txt | 1 + contests/Round888/C/main_output2.txt | 1 + 8 files changed, 202 insertions(+) create mode 100755 contests/Round888/C/main create mode 100755 contests/Round888/C/main.cpp create mode 100644 contests/Round888/C/main_input0.txt create mode 100644 contests/Round888/C/main_input1.txt create mode 100644 contests/Round888/C/main_input2.txt create mode 100644 contests/Round888/C/main_output0.txt create mode 100644 contests/Round888/C/main_output1.txt create mode 100644 contests/Round888/C/main_output2.txt (limited to 'contests/Round888/C') diff --git a/contests/Round888/C/main b/contests/Round888/C/main new file mode 100755 index 0000000..acd2636 Binary files /dev/null and b/contests/Round888/C/main 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 +using namespace std; + +using ll = long long; +using pii = pair; +using vpi = vector; +using vi = vector; +using vll = vector; +using mpii = map; +using mpll = map; +using db = long double; + +#define pb push_back +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() +#define lb lower_bound +#define ub upper_bound +#define make_unique(x) \ + sort(all((x))); \ + (x).resize(unique(all((x))) - (x).begin()) +#define ceil(a, b) ((a) + (b) - 1) / (b)) + +const int MOD = (int)1e9 + 7; +const db PI = acos((db)-1); +const int dx[4]{1, 0, -1, 0}; +const int dy[4]{0, 1, 0, -1}; + +template +ostream &operator<<(ostream &os, const pair &p); +template ostream &operator<<(ostream &os, const vector &vec); +template +ostream &operator<<(ostream &os, const map &m); +template +ostream &operator<<(ostream &os, const unordered_map &m); +template ostream &operator<<(ostream &os, const set &s); +template +ostream &operator<<(ostream &os, const unordered_set &s); + +template +ostream &operator<<(ostream &os, const pair &p) { + os << "(" << p.first << ", " << p.second << ")"; + return os; +} + +template ostream &operator<<(ostream &os, const vector &vec) { + os << "{"; + for (size_t i = 0; i < vec.size(); ++i) { + if (i > 0) + os << ", "; + os << vec[i]; + } + os << "}"; + return os; +} + +template +ostream &operator<<(ostream &os, const map &m) { + os << "{"; + for (const auto &p : m) { + os << p.first << ": " << p.second << ", "; + } + os << "}"; + return os; +} + +template +ostream &operator<<(ostream &os, const unordered_map &m) { + os << "{"; + for (const auto &p : m) { + os << p.first << ": " << p.second << ", "; + } + os << "}"; + return os; +} + +template ostream &operator<<(ostream &os, const set &s) { + int i = 0; + os << "{"; + for (const auto &e : s) { + if (i > 0) + os << ", "; + os << e; + i++; + } + os << "}"; + return os; +} + +template +ostream &operator<<(ostream &os, const unordered_set &s) { + int i = 0; + os << "{"; + for (const auto &e : s) { + if (i > 0) + os << ", "; + os << e; + i++; + } + os << "}"; + return os; +} + +void dbg() { cerr << "\n"; } + +template 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 -- cgit v1.2.3