From 422543715dcfb97d7c09ef4f72ecb9e4cd2066b0 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Sun, 26 Jun 2022 10:42:12 +0800 Subject: [PATCH] C - Fishingprince Plays With Array https://codeforces.com/contest/1696/submission/161823627 --- Codeforces/1696/C/C.cpp | 58 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 Codeforces/1696/C/C.cpp diff --git a/Codeforces/1696/C/C.cpp b/Codeforces/1696/C/C.cpp new file mode 100644 index 00000000..94a265e9 --- /dev/null +++ b/Codeforces/1696/C/C.cpp @@ -0,0 +1,58 @@ +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 5e4 + 5; + +int t, n, m, k, a[N], b[N]; + +void expand(int *arr, int n, int m, std::vector> &vec) { + for (int i = 1; i <= n; i++) { + long long x = arr[i], + cnt = 1; + + while (x % m == 0) { + x /= m; + cnt *= m; + } + + if (!vec.empty() && vec.rbegin()->first == x) { + vec.rbegin()->second += cnt; + } else { + vec.push_back(std::make_pair(x, cnt)); + } + } +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> t; + + while (t--) { + std::vector> va, vb; + + cin >> n >> m; + + for (int i = 1, x; i <= n; i++) { + cin >> a[i]; + } + + cin >> k; + + for (int i = 1; i <= k; i++) { + cin >> b[i]; + } + + expand(a, n, m, va); + expand(b, k, m, vb); + + cout << (va == vb ? "Yes" : "No") << endl; + } + + return 0; +}