text
stringlengths
49
983k
#include <bits/stdc++.h> using namespace std; int n, m, i, j, s = 0; string a[10000], b[10000]; int main() { map<string, int> p; cin >> n >> m; for (i = 0; i < n; i++) cin >> a[i], p[a[i]]++; for (i = 0; i < m; i++) { cin >> b[i]; if (p[b[i]]) s++; } if (s & 1) m--; if (n > m) cout << "YES"; else cout << "NO"; return 0; }
#include <bits/stdc++.h> using namespace std; map<string, int> mymap; string s; int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) { cin >> s; mymap[s] = 1; } int common = 0; for (int i = 0; i < m; i++) { cin >> s; if (mymap.count(s)) common++; } if ((common % 2 == 1 && n >= m) || (common % 2 == 0 && n > m)) printf("YES\n"); else printf("NO\n"); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; string cc; set<string> st; for (int i = 0; i < n + m; i++) { cin >> cc; st.insert(cc); } cout << (n > m - ((m + n - st.size()) % 2 != 0) ? "YES" : "NO"); return 0; }
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long n_ = 1e5 + 1000; const long double PI = acos(-1.0); long long gcd(long long a, long long b) { return (a ? gcd(b % a, a) : b); } long long power(long long a, long long n) { long long p = 1; while (n > 0) { if (n % 2) { p = p * a; } n >>= 1; a *= a; } return p; } long long power(long long a, long long n, long long mod) { long long p = 1; while (n > 0) { if (n % 2) { p = p * a; p %= mod; } n >>= 1; a *= a; a %= mod; } return p % mod; } bool vowel(char ch) { if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') return true; else return false; } class UnionFind { private: vector<long long> p, rank, setSize; long long numSets; public: UnionFind(long long N) { setSize.assign(N, 1); numSets = N; rank.assign(N, 0); p.assign(N, 0); for (long long i = 0; i < N; i++) p[i] = i; } long long findSet(long long i) { return (p[i] == i) ? i : (p[i] = findSet(p[i])); } bool isSameSet(long long i, long long j) { return findSet(i) == findSet(j); } void unionSet(long long i, long long j) { if (!isSameSet(i, j)) { numSets--; long long x = findSet(i), y = findSet(j); if (rank[x] > rank[y]) { p[y] = x; setSize[x] += setSize[y]; } else { p[x] = y; setSize[y] += setSize[x]; if (rank[x] == rank[y]) rank[y]++; } } } long long numDisjointSets() { return numSets; } long long sizeOfSet(long long i) { return setSize[findSet(i)]; } }; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, m; cin >> n >> m; set<string> s; string str; for (long long i = 0; i < n; i++) { cin >> str; s.insert(str); } long long x = s.size(), a = 0, b = 0, c = 0; for (long long i = 0; i < m; i++) { cin >> str; s.insert(str); if (s.size() == x) c++; x = s.size(); } a = n - x; b = m - x; if (x % 2 == 0) { if (a > b) cout << "YES"; else cout << "NO"; } else { if (a >= b) cout << "YES"; else cout << "NO"; } return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC target("avx2") using namespace std; void solve() { int n, m; cin >> n >> m; vector<string> b(m); unordered_set<string> set; for (int i = 0; i < n; i++) { string s; cin >> s; set.insert(s); } for (int i = 0; i < m; i++) cin >> b[i]; if (n > m) { cout << &("NO\0YES"[3 * 1]) << "\n"; return; } if (n < m) { cout << &("NO\0YES"[3 * 0]) << "\n"; return; } int count_similar = 0; for (int i = 0; i < m; i++) { if (set.count(b[i])) ++count_similar; } if (count_similar & 1) cout << &("NO\0YES"[3 * 1]) << "\n"; else cout << &("NO\0YES"[3 * 0]) << "\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; t = 1; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; vector<string> vec1, vec2, vec3; map<string, int> map1; int main() { int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { string str; cin >> str; vec1.push_back(str); map1[str] = 1; } for (int i = 0; i < m; i++) { string str; cin >> str; if (map1.find(str) != map1.end()) { vec3.push_back(str); continue; } vec2.push_back(str); } int unmatch1 = n - vec3.size(); int unmatch2 = vec2.size(); int f = 0; if (vec3.size() % 2 == 1) { f = 1; } else if (vec3.size() % 2 == 0 && vec3.size() != 0) { f = 2; } int chance = 0; int i = 0, j = 0; if (f == 1) { chance = 2; } else if (f == 2) { chance = 1; } else { chance = 1; } while (i < unmatch1 && j < unmatch2) { if (chance == 1) { i++; chance = 2; j++; chance = 1; } else if (chance == 2) { j++; chance = 1; i++; chance = 2; } } if (chance == 1) { if (i == unmatch1) { cout << "NO\n"; } else if (j == unmatch2) { cout << "YES\n"; } } else { if (j == unmatch2) { cout << "YES\n"; } else if (i == unmatch1) { cout << "NO\n"; } } }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); string xx; map<string, int> mm; int n, m, ct = 0; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> xx; mm[xx]++; } for (int i = 0; i < m; i++) { cin >> xx; mm[xx]++; if (mm[xx] > 1) ct++; } if (ct & 1) { n = n - ct / 2; m = m - ct / 2 - 1; if (n > m) cout << "YES\n"; else cout << "NO\n"; } else { n = n - ct / 2; m = m - ct / 2; if (n > m) cout << "YES\n"; else cout << "NO\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; const long long INF = 1e8, MAX = 1e4, MOD = 1e9 + 7; map<string, bool> mp; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int a = 0, b = 0, x = 0, y = 0, z = 0; cin >> a >> b; for (int i = 0; i < a; i++) { string s; cin >> s; mp[s] = 1; } for (int i = 0; i < b; i++) { string s; cin >> s; if (mp[s]) z++; } x = a - z; y = b - z; if (z % 2 == 1) x++; if (x > y) cout << "YES"; else cout << "NO"; return 0; }
#include <bits/stdc++.h> using namespace std; bool sortbysec(const pair<long int, long int> &a, const pair<long int, long int> &b) { return (a.second < b.second); } int main() { long int n, m, i; cin >> n >> m; set<string> s; string s1; for (i = 0; i < n + m; i++) { cin >> s1; s.insert(s1); } i = n + m - s.size(); if (i % 2 == 0) { n = n - i; m = m - i; if (n > m) { cout << "YES"; } else { cout << "NO"; } } else { n = n - i; m = m - i; m--; if (n > m) { cout << "YES"; } else { cout << "NO"; } } return 0; }
#include <bits/stdc++.h> using namespace std; int n, m; int main() { cin >> n >> m; unordered_set<string> words; string s; for (int i = 0; i < n; i++) { cin >> s; words.insert(s); } int mreal = m; int sameCount = 0; for (int i = 0; i < m; i++) { cin >> s; if (words.find(s) != words.end()) { sameCount++; } } if (n > mreal - sameCount % 2) { cout << "YES" << endl; } else { cout << "NO" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 1010; string name[MAXN], name2[MAXN]; map<string, bool> check; int main() { int n, m; cin >> n >> m; int cnt = 0; for (int i = 0; i < n; i++) { string now; cin >> now; name[i] = now; check[name[i]] = true; } for (int i = 0; i < m; i++) { string now; cin >> now; name2[i] = now; if (check.count(name2[i]) != 0) { cnt++; } } int t = 0; while (cnt != 0) { if (t % 2 == 0) { n--; m--; } else { n--; m--; } cnt--; t++; } if (t % 2 == 0) { if (n > m) { cout << "YES\n"; } else { cout << "NO\n"; } } else { if (m > n) { cout << "NO\n"; } else { cout << "YES\n"; } } }
#include <bits/stdc++.h> using namespace std; inline int in() { int x; cin >> x; return x; } template <typename T> istream &operator>>(istream &in, vector<T> &vec) { for (int i = 0; i < vec.size(); ++i) in >> vec[i]; return in; } template <typename T> ostream &operator<<(ostream &out, const vector<T> &vec) { for (int i = 0; i < vec.size(); ++i) out << vec[i] << " "; return out; } int a[1000001]; int fenwik[1000001]; int n, m; vector<pair<int, int> > call[1000001]; unordered_map<int, int> lf; int result[1000001]; inline void xorS(int i, int x) { --i; for (; i < n; i |= (i + 1)) fenwik[i] ^= x; } inline int getXor(int i) { --i; int x = 0; for (; i >= 0; i = (i & (i + 1)) - 1) x ^= fenwik[i]; return x; } int main() { int a = in(), b = in(); vector<string> s(a + b); for (int i = 0; i < a + b; ++i) cin >> s[i]; sort((s).begin(), (s).end()); int g = 0; for (int i = 0; i < a + b - 1; ++i) s[i] == s[i + 1] ? ++g : 0; int i; int check = 0; int h = a - g, j = b - g; for (i = 0; i < a + b && !check; ++i) { if (!(i % 2)) { if (g > 0) --g; else if (h > 0) { h--; } else check = 1; } else { if (g > 0) --g; else if (j > 0) { j--; } else check = 1; } if (!check) { check = 0; } else break; } if (i % 2) cout << "YES"; else cout << "NO"; return 0; }
#include <bits/stdc++.h> using namespace std; const int mod = int(1e9 + 7); long long int power(long long int a, long long int b) { if (a == 0) return 0; long long int ans = 1; a = a % mod; while (b > 0) { if ((b & 1) == 1) ans = (ans * a) % mod; b = b >> 1; a = (a * a) % mod; } return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; set<string> set1; for (int i = 0; i < n; i++) { string s; cin >> s; set1.insert(s); } for (int i = 0; i < m; i++) { string s; cin >> s; set1.insert(s); } if (n > m) cout << "YES" << endl; else if (n < m) cout << "NO" << endl; else { int dupli = n + m - (set1.size()); if (dupli % 2 == 1) { cout << "YES" << endl; } else { cout << "NO" << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; map<string, int> mp; int main() { string str; int p, e; scanf("%d %d", &p, &e); map<string, int> words; for (int i = 0; i < p; i++) { cin >> str; mp[str] = 1; } int cnt = 0; for (int i = 0; i < e; i++) { cin >> str; if (mp[str] == 1) { ++cnt; } } p -= cnt; e -= cnt; if (cnt % 2) { if (p >= e) { cout << "YES" << endl; } else cout << "NO" << endl; } else { if (p > e) { cout << "YES" << endl; } else cout << "NO" << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int n, m; cin >> n >> m; set<string> sa, sb, sab; for (int i = (int)(0); i < (int)(n); ++i) { string s; cin >> s; sa.insert(s); } for (int i = (int)(0); i < (int)(m); ++i) { string s; cin >> s; sb.insert(s); if (sa.count(s)) sab.insert(s); } int a = (int)sa.size(); int b = (int)sb.size(); int ab = (int)sab.size(); a -= ab; b -= ab; string A = "YES"; string B = "NO"; while (true) { if (ab) --ab; else if (a) --a; else { cout << B << endl; return 0; } swap(a, b), swap(A, B); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int m, n; cin >> n >> m; map<string, int> pol, ene, common; string temp; for (int i = 0; i < n; i++) { cin >> temp; pol[temp]++; common[temp]++; } for (int i = 0; i < m; i++) { cin >> temp; ene[temp]++; common[temp]++; } map<string, int>::iterator it; int cnt = 0; for (it = common.begin(); it != common.end(); it++) { if (it->second == 2) { temp = it->first; pol.erase(temp); ene.erase(temp); cnt++; } } if (cnt % 2 == 0) { if (pol.size() > ene.size()) cout << "YES\n"; else cout << "NO\n"; } else { if (pol.size() < ene.size()) cout << "NO\n"; else cout << "YES\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; int n, m; set<string> dic; void read() { cin.sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m; string s; for (int i = 0; i < n; ++i) { cin >> s; dic.insert(s); } int common = 0; for (int i = 0; i < m; ++i) { cin >> s; auto it = dic.find(s); if (it != dic.end()) ++common; } if (n > m) { printf("YES"); } else { if (n == m && (common & 1)) { printf("YES\n"); } else { printf("NO\n"); } } } void solve() { read(); int ans = 1; } int main() { int t = 1; for (int i = 0; i < t; ++i) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int n, m; map<string, bool> vis; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { string str; cin >> str; vis[str] = true; } int cnt = 0; for (int i = 1; i <= m; i++) { string str; cin >> str; if (vis[str]) cnt++; } n -= cnt / 2; m -= cnt - cnt / 2; return !printf("%s\n", n > m ? "YES" : "NO"); }
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; set<string> A, B; vector<string> C(max(n, m)); string tt; for (int i = 0; i < n; i++) cin >> tt, A.emplace(tt); for (int i = 0; i < m; i++) cin >> tt, B.emplace(tt); auto it = set_intersection(A.begin(), A.end(), B.begin(), B.end(), C.begin()); if ((int)(it - C.begin()) % 2) n++; cout << (n > m ? "YES" : "NO"); }
#include <bits/stdc++.h> using namespace std; int main() { { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); }; set<string> wordSet; string str; int n, m, i; cin >> n >> m; for (i = 1; i <= n; i++) { cin >> str; wordSet.insert(str); } int commonCnt = 0; for (i = 1; i <= m; i++) { cin >> str; if (wordSet.count(str) > 0) { commonCnt++; } } int word1 = n - commonCnt + (commonCnt + 1) / 2; int word2 = m - commonCnt + (commonCnt) / 2; if (word1 > word2) { cout << "YES" << endl; } else { cout << "NO" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } const long long MAXN = 2005, Mo = 1000000007; char s[MAXN], ch; long long n, m, a[MAXN], b[MAXN]; int main() { long long i, j, k; n = read(); m = read(); for (i = 1; i <= n; ++i) { scanf("%s", s + 1); k = strlen(s + 1); for (j = 1, a[i] = 0; j <= k; ++j) a[i] = (a[i] * 997 + s[j] - 'A' + 1) % Mo; } for (i = 1; i <= m; ++i) { scanf("%s", s + 1); k = strlen(s + 1); for (j = 1, b[i] = 0; j <= k; ++j) b[i] = (b[i] * 997 + s[j] - 'A' + 1) % Mo; } for (i = 1, k = 0; i <= n; ++i) for (j = 1; j <= m; ++j) if (a[i] == b[j]) { k++; break; } n = n - k; m = m - k; n = n + (k + 1) / 2; m = m + k / 2; if (n > m) printf("YES\n"); else printf("NO\n"); return 0; }
#include <bits/stdc++.h> using namespace std; const int _MOD_ = (int)1e9 + 7; template <class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; } template <class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; } template <class T> inline bool Eq(T a, T b, int mod = _MOD_) { return (a - b) % mod == 0; } template <class T> inline T Add(T a, T b, int mod = _MOD_) { a += b; return a >= mod ? a - mod : a; } template <class T> inline T Sub(T a, T b, int mod = _MOD_) { a -= b; return a < 0 ? a + mod : a; } template <class T> inline T Mul(T x, T y, int mod = _MOD_) { return ((long long)x * y) % mod; } template <class T> inline T Sqr(T a, int mod = _MOD_) { return Mul(a, a, mod); } long long Pow(long long x, long long n, int mod = _MOD_) { long long r = mod > 1 ? 1 : 0; for (; n; n /= 2) { if (n & 1) r = Mul(r, x, mod); x = Mul(x, x, mod); } return r; } template <class T> inline T Div(T x, T y, int mod = _MOD_) { return Mul(x, Pow(y, mod - 2)); } inline int readChar(); template <class T = int> inline T readInt(); template <class T> inline void writeInt(T x, char end = 0); inline void writeChar(int x); inline void writeWord(const char *s); static const int buf_size = 4096; inline int getChar() { static char buf[buf_size]; static int len = 0, pos = 0; if (pos == len) pos = 0, len = fread(buf, 1, buf_size, stdin); if (pos == len) return -1; return buf[pos++]; } inline int readChar() { int c = getChar(); while (c <= 32) c = getChar(); return c; } template <class T> inline T readInt() { int s = 1, c = readChar(); T x = 0; if (c == '-') s = -1, c = getChar(); while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getChar(); return s == 1 ? x : -x; } static int write_pos = 0; static char write_buf[buf_size]; inline void writeChar(int x) { if (write_pos == buf_size) fwrite(write_buf, 1, buf_size, stdout), write_pos = 0; write_buf[write_pos++] = x; } template <class T> inline void writeInt(T x, char end) { if (x < 0) writeChar('-'), x = -x; char s[24]; int n = 0; while (x || !n) s[n++] = '0' + x % 10, x /= 10; while (n--) writeChar(s[n]); if (end) writeChar(end); } inline void writeWord(const char *s) { while (*s) writeChar(*s++); } struct Flusher { ~Flusher() { if (write_pos) fwrite(write_buf, 1, write_pos, stdout), write_pos = 0; } } flusher; int main() { ios_base::sync_with_stdio(0); cin.tie(0); string s; int n, m; cin >> n >> m; map<string, bool> was; set<string> s1, s2; for (int i = 0; i < (int)(n); i++) { cin >> s; was[s] = 1; s1.insert(s); } int cnt = 0; for (int i = 0; i < (int)(m); i++) { cin >> s; if (was[s]) { s1.erase(s1.find(s)); cnt++; } else s2.insert(s); } if (cnt % 2) { if (s1.size() < s2.size()) cout << "NO"; else cout << "YES"; } else { if (s1.size() > s2.size()) cout << "YES"; else cout << "NO"; } return 0; }
#include <bits/stdc++.h> using namespace std; int n, m, com; char s1[1010][510], s2[1010][510]; int main() { int i, j; cin >> n >> m; for (i = 1; i <= n; ++i) { cin >> s1[i]; } for (i = 1; i <= m; ++i) { cin >> s2[i]; for (j = 1; j <= n; ++j) if (strcmp(s2[i], s1[j]) == 0) ++com; } if (com % 2 == 1) --m; if (n > m) cout << "YES"; else cout << "NO"; return 0; }
#include <bits/stdc++.h> using namespace std; map<string, int> ma; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m, a = 0, b = 0, mosht = 0; cin >> n >> m; for (int i = 0; i < n; i++) { string s; cin >> s; ma[s] = 1; } a = n; b = m; for (int i = 0; i < m; i++) { string s; cin >> s; if (ma.find(s) != ma.end()) mosht++, a--, b--; } if (a > b) return cout << "YES" << endl, 0; if (b > a) return cout << "NO" << endl, 0; if (mosht % 2) cout << "YES" << endl; else cout << "NO" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; bool solve(const set<string>& poland, const set<string>& enemy) { auto common = set<string>(); set_intersection(begin(poland), end(poland), begin(enemy), end(enemy), inserter(common, begin(common))); const auto a = poland.size() - common.size(), b = enemy.size() - common.size(); if (common.size() % 2 == 0) return a > b; else return a + 1 > b; } int main() { int n, m; cin >> n >> m; auto poland = set<string>(); for (auto i = 0; i < n; i++) { string s; cin >> s; poland.insert(s); } auto enemy = set<string>(); for (auto i = 0; i < m; i++) { string s; cin >> s; enemy.insert(s); } cout << (solve(poland, enemy) ? "YES" : "NO") << endl; }
#include <bits/stdc++.h> using namespace std; char s[2][1001][505]; int vis1[1001]; int vis2[1001]; int main() { int n, m; while (cin >> n >> m) { memset(s, 0, sizeof(s)); memset(vis1, 0, sizeof(vis1)); memset(vis2, 0, sizeof(vis2)); for (int i = 0; i < n; i++) { scanf("%s", s[0][i]); } for (int i = 0; i < m; i++) { scanf("%s", s[1][i]); } if (n > m) { cout << "YES" << endl; continue; } else if (n < m) { cout << "NO" << endl; } else { int cnt = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (strcmp(s[0][i], s[1][j]) == 0) { cnt++; break; } } } if (cnt % 2 == 0) { cout << "NO" << endl; } else cout << "YES" << endl; } } }
#include <bits/stdc++.h> using namespace std; int i, j, n, m, p, o, com; vector<string> str1, str2; char name[600]; int main() { while (cin >> n >> m) { com = 0; for (i = 1; i <= n; i++) { scanf("%s", name); str1.push_back(name); } for (i = 1; i <= m; i++) { scanf("%s", name); str2.push_back(name); } if (n > m) cout << "YES\n"; else if (n < m) cout << "NO\n"; else { for (i = 0; i < str1.size(); i++) for (j = 0; j < str2.size(); j++) if (str1[i] == str2[j]) { com++; break; } if ((n - com) > (m - com)) cout << "YES\n"; else if ((n - com) < (m - com)) cout << "NO\n"; else { printf((com % 2 == 1) ? "YES" : "NO\n"); } } str1.clear(); str2.clear(); } return 0; }
#include <bits/stdc++.h> const int inf = 1e9 + 5; const long long linf = 5e18 + 5; const long double eps = 1e-9; const long long dd = 2e5 + 7; const long long maxn = 2e3 + 10; const long long mod = 1e9 + 7; using namespace std; const int qq = 1e5; map<char, long long> qwe; void imp() { cout << "Impossible\n"; exit(0); } void iin() { cout << "Infinity\n"; exit(0); } int x1[dd], c1[dd]; bool eq(int x) { for (int i = 2; i * i <= x; i++) { if (x % i == 0) return 0; } return 1; } int main() { ios_base::sync_with_stdio(0); if (0) { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); } else { if (!01) { freopen( "sufpref" ".in", "r", stdin); freopen( "sufpref" ".out", "w", stdout); } } set<string> pol, wra, qwe; int n, m; cin >> n >> m; for (long long i = 0; i < n; ++i) { string s; cin >> s; pol.insert(s); } for (long long i = 0; i < m; ++i) { string s; cin >> s; wra.insert(s); if (pol.count(s)) qwe.insert(s); } int pp = pol.size(); int ww = wra.size(); int aa = qwe.size(); int now = 0; while (pp && ww) { if (now == 0) { if (aa) { pp--; aa--; ww--; } else { pp--; } now = 1; } else { if (aa) { pp--; aa--; ww--; } else { ww--; } now = 0; } } if (now == 1 && ww != 0) { cout << "NO\n"; } if (now == 1 && ww == 0) cout << "YES\n"; if (now == 0 && pp == 0) cout << "NO\n"; if (now == 0 && pp != 0) cout << "YES\n"; }
#include <bits/stdc++.h> using namespace std; int main() { set<string> s1, s2, s3; s3.clear(); s1.clear(); s2.clear(); int n, m; cin >> n >> m; string str = ""; for (int i = 0; i < n; i++) { cin >> str; s1.insert(str); } for (int i = 0; i < m; i++) { cin >> str; s2.insert(str); } set<string>::iterator it; for (it = s1.begin(); it != s1.end(); it++) { if (s2.find(*it) != s2.end()) { s3.insert(*it); } } int z = s3.size(); int x = s1.size() - z; int y = s2.size() - z; if (z % 2 != 0) { if (x >= y) { cout << "YES\n"; } else { cout << "NO\n"; } } else { if (x - y >= 1) cout << "YES\n"; else { cout << "NO\n"; } } return 0; }
#include <bits/stdc++.h> using namespace std; vector<string> v1, v2; int main() { int a, b; scanf("%d %d", &a, &b); string s; for (int i = 0; i < a; i++) { cin >> s; v1.push_back(s); } for (int i = 0; i < b; i++) { cin >> s; v2.push_back(s); } if (a > b) printf("YES\n"); else if (a < b) printf("NO\n"); else { int x = 0; for (int i = 0; i < a; i++) { if (binary_search(v2.begin(), v2.end(), v1[i])) x++; } if (!x) printf("NO\n"); else if (x & 1) printf("YES\n"); else printf("NO\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; string pb[1001], eb[1001]; int main() { int n, m, same = 0; scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) cin >> pb[i]; for (int i = 0; i < m; i++) cin >> eb[i]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) if (pb[i] == eb[j]) same++; n -= same; m -= same; if (same % 2 == 0) { if (n > m) printf("YES\n"); else printf("NO\n"); } else { if (n >= m) printf("YES\n"); else printf("NO\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; map<string, long long> m; int main() { long long n, k; cin >> n >> k; string s; for (long long i = 0; i < n; i++) { cin >> s; m[s]++; } for (long long i = 0; i < k; i++) { cin >> s; m[s]++; } long long cnt = 0; for (map<string, long long>::iterator it = m.begin(); it != m.end(); it++) { if ((*it).second == 2) cnt++; } long long i = 0; n -= cnt; k -= cnt; while (1) { if (i % 2 == 0) { if (cnt) cnt--; else n--; if (n < 0) { cout << "NO"; return 0; } } else { if (cnt) cnt--; else k--; if (k < 0) { cout << "YES"; return 0; } } i++; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, m, common = 0, x; cin >> n >> m; string s[n], ss[m]; for (int i = 0; i < n; i++) cin >> s[i]; for (int i = 0; i < m; i++) cin >> ss[i]; if (n > m) { cout << "YES"; } else if (n < m) { cout << "NO"; } else { for (int i = 0; i < m; i++) { for (int j = 0; j < m; j++) { if (s[i] == ss[j]) { common++; } } } if (common % 2 == 0) cout << "NO"; else cout << "YES"; } return 0; }
#include <bits/stdc++.h> const int inf = (1ll << 30) - 1; const int maxn = (int)1e5 + 10; const int mod = (int)1e9 + 7; using namespace std; int n, m; string second[100100]; void solve() { cin >> n >> m; for (int i = 0; i < n + m; i++) cin >> second[i]; sort(second, second + n + m); int cnt = 0; for (int i = 1; i < n + m; i++) { if (second[i] == second[i - 1]) cnt++; } n -= cnt; m -= cnt; n += (cnt + 1) / 2; m += cnt / 2; if (n > m) cout << "YES\n"; else cout << "NO\n"; } int main() { int t = 1; for (int i = 1; i <= t; i++) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; map<string, int> mp; for (int i = 0; i < n; i++) { string s; cin >> s; mp[s]++; } int ans = 0; for (int i = 0; i < m; i++) { string s; cin >> s; if (mp[s] == 1) ans++; mp[s]++; } n -= ans; m -= ans; if (n + (ans % 2) > m) { cout << "YES" << endl; } else { cout << "NO" << endl; } }
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e7 + 5; const long long MOD = 1e9 + 7; int n, m, same; string s; map<string, bool> mark; int main() { ios::sync_with_stdio(false); cin >> n >> m; for (int i = 0; i < n; i++) { cin >> s; mark[s] = true; } for (int i = 0; i < m; i++) { cin >> s; if (mark[s]) same++; } for (int i = 0; n >= 0 && m >= 0; i++) { if (i % 2) { if (same > 0) { same--; n--; } m--; } else { if (same > 0) { same--; m--; } n--; } } if (m < 0) { return cout << "YES", 0; } cout << "NO"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, m, i; vector<string> v; cin >> n >> m; for (i = 0; i < n + m; i++) { string s; cin >> s; v.push_back(s); } int c = 0; sort(v.begin(), v.end()); for (i = 0; i < v.size(); i++) { if (v[i] == v[i + 1]) { c++; i++; } } int a, b; a = n - c; b = m - c; if (c % 2 == 0) { a = a + c / 2; b = b + c / 2; } else { a = a + (c / 2) + 1; b = b + c / 2; } if (a > b) { cout << "YES" << endl; } else { cout << "NO" << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, i, j; cin >> n >> m; string z; vector<string> a, b, c; vector<string>::iterator it, s; for (i = 0; i < n; i++) { cin >> z; a.push_back(z); } for (i = 0; i < m; i++) { cin >> z; b.push_back(z); } if (n < m) { s = a.begin(); while (s != a.end() && a.size() > 0 && b.size() > 0) { it = find(b.begin(), b.end(), *s); if (it != b.end()) { c.push_back(*s); b.erase(it); a.erase(s); } else { s++; } } } else { s = b.begin(); while (s != b.end() && b.size() > 0 && a.size() > 0) { it = find(a.begin(), a.end(), *s); if (it != a.end()) { c.push_back(*s); b.erase(s); a.erase(it); } else { s++; } } } if (a.size() > b.size()) { cout << "YES"; } else if (a.size() < b.size()) { cout << "NO"; } else { if (c.size() % 2 != 0) { cout << "YES"; } else { cout << "NO"; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N, M; cin >> N >> M; set<string> a, b, both; string s; for (int i = 0; i < N; i++) { cin >> s; a.insert(s); } int both_know = 0; for (int i = 0; i < M; i++) { cin >> s; if (a.find(s) != a.end()) { both.insert(s); } b.insert(s); } while (1) { if (!both.empty()) { string x = *both.begin(); both.erase(x); a.erase(x); b.erase(x); } else if (!a.empty()) { string x = *a.begin(); a.erase(x); } else { cout << "NO" << endl; return 0; } if (!both.empty()) { string x = *both.begin(); both.erase(x); a.erase(x); b.erase(x); } else if (!b.empty()) { string x = *b.begin(); b.erase(x); } else { cout << "YES" << endl; return 0; } } }
#include <bits/stdc++.h> using namespace std; int n, i, m, pr, a, b, p; map<string, int> mp; string s[10000], s1[10000]; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> s[i]; mp[s[i]] = 1; } for (int i = 1; i <= m; i++) { cin >> s1[i]; if (mp[s1[i]] == 1) p++; mp[s1[i]] = 1; } b = p / 2; a = p - b; a += (n - p); b += (m - p); if (b >= a) cout << "NO"; else cout << "YES"; return 0; }
#include <bits/stdc++.h> using namespace std; int n, m; inline void get_ready() { cin >> n >> m; } inline void solve() { set<string> ss; for (int i = (1); i <= (n + m); i++) { string s; cin >> s; ss.insert(s); } int nn = n + m - ss.size(); nn %= 2; if (n + nn > m) cout << "YES" << endl; else cout << "NO" << endl; } int main() { std::ios::sync_with_stdio(0); get_ready(); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; unordered_map<string, pair<int, bool> > u; bool cmp(string x, string y) { return u[x].first > u[y].first; } int n, m; string a[1000 + 5], b[1000 + 5]; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) cin >> a[i], u[a[i]].first = 1; for (int i = 1; i <= m; i++) { cin >> b[i]; if (u[b[i]].first) u[b[i]].first++; } sort(a + 1, a + n + 1, cmp); sort(b + 1, b + m + 1, cmp); int i, j, turn; char l; for (i = 1, j = 1, turn = 0; (i <= n && j <= m); turn++) { if (turn % 2 == 0) { while (i <= n) { if (!u[a[i]].second) { u[a[i]].second = true; break; } i++; } l = 'i'; } else { while (j <= m) { if (!u[b[j]].second) { u[b[j]].second = true; break; } j++; } l = 'j'; } } if (l == 'i') cout << "NO"; else cout << "YES"; return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx") using namespace std; int a, b, c, d, n, m, k; char str[505]; inline void die(string s) { cout << s << endl; exit(0); } int main() { int a = 0, ab = 0, b = 0; set<string> w1; scanf("%d%d", &n, &m); for (int _n((n)-1), i(0); i <= _n; i++) { scanf("%s", str); w1.insert(str); ++a; } for (int _n((m)-1), i(0); i <= _n; i++) { scanf("%s", str); auto it = w1.find(str); if (it != w1.end()) { w1.erase(it); --a; ++ab; } else { ++b; } } c = 0; while (1) { if (c % 2 == 0) { if (ab > 0) --ab; else if (a > 0) --a; else die("NO"); } else { if (ab > 0) --ab; else if (b > 0) --b; else die("YES"); } c ^= 1; } }
#include <bits/stdc++.h> int main() { int n, m; int i, j, sum; char word[1005][505], temp[505]; scanf("%d%d", &n, &m); sum = 0; for (i = 0; i < n; i++) scanf("%s", &word[i]); for (i = 0; i < m; i++) { scanf("%s", temp); for (j = 0; j < n; j++) if (strcmp(word[j], temp) == 0) sum++; } if (sum % 2 == 1) n++; if (n > m) printf("YES\n"); if (n <= m) printf("NO\n"); return 0; }
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9; const long long N = 1e5 + 1; const long long mod = 1e9 + 7; const long double eps = 1E-7; using namespace std; bool used[100001]; map<string, bool> mp; pair<int, int> p[10001]; void solve() { int n, m, ct = 0; string s; cin >> n >> m; if (n > m) { cout << "YES\n" << endl; return; } if (n < m) { cout << "NO\n" << endl; return; } for (int i = 0; i < n; ++i) { cin >> s; mp[s] = true; } for (int i = 0; i < m; ++i) { cin >> s; if (mp[s]) ct++; } if (ct % 2) { cout << "YES\n"; return; } else { cout << "NO\n"; return; } } bool mtest = false; int main() { ios_base::sync_with_stdio(0); int TE = 1; if (mtest) cin >> TE; while (TE--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; set<string> a; int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); long long n, m; cin >> n >> m; for (long long i = 1; i <= n + m; i++) { string s; cin >> s; a.insert(s); } n += ((n + m) - a.size()) % 2; if (n > m) cout << "YES"; else cout << "NO"; return 0; }
#include <bits/stdc++.h> using namespace std; string t; int a, b, c, k, i; set<string> s; int main() { cin >> a >> b; c = a + b; for (i = 1; i <= c; i++) { cin >> t; s.insert(t); } k = c - s.size(); if (k % 2 == 1) a++; if (a > b) cout << "YES"; else cout << "NO"; }
#include <bits/stdc++.h> using namespace std; map<string, int> mp; string str; int poland, enemy, both; int main() { int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> str; mp[str] = 1; poland++; } for (int i = 1; i <= m; i++) { cin >> str; if (mp[str] == 1) { both++; } enemy++; } poland -= both; enemy -= both; if (both % 2 == 0) { if (poland > enemy) cout << "YES" << endl; else cout << "NO" << endl; } else { if (poland >= enemy) cout << "YES" << endl; else cout << "NO" << endl; } }
#include <bits/stdc++.h> using namespace std; const int N = 1234567; string a[N]; char foo[N]; void get(string &s) { scanf("%s", foo); s = ""; for (int j = 0; foo[j]; j++) { s += foo[j]; } } int main() { int n, m; scanf("%d %d", &n, &m); for (int i = 0; i < n + m; i++) { get(a[i]); } sort(a, a + n + m); int common = 0; for (int i = 0; i < n + m - 1; i++) { if (a[i] == a[i + 1]) { common++; } } n -= common; m -= common; for (int it = 0;; it++) { if (it % 2 == 0) { if (common > 0) common--; else if (n > 0) n--; else { puts("NO"); break; } } else { if (common > 0) common--; else if (m > 0) m--; else { puts("YES"); break; } } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, m, t = 1, countt = 0, wa = 0, wb = 0; vector<string> a, b; map<string, int> c; string str; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> str; a.push_back(str); c[str] = 1; } for (int i = 0; i < m; i++) { cin >> str; b.push_back(str); if (c[str] == 1) countt++; } if (countt % 2 == 1) { wa++; t = 2; } else if (countt != 0 && countt % 2 == 0) { wb++; t = 1; } if ((a.size() - countt) > (b.size() - countt)) { if (t == 2) t = 1; wa++; } else if ((a.size() - countt) < (b.size() - countt)) { if (t == 1) t = 2; wb++; } else { int temp = (a.size() - countt); if (t == 1) t = 2; else if (t == 2) t = 1; } if (t == 1) cout << "YES" << endl; else cout << "NO" << endl; return 0; }
#include <bits/stdc++.h> using namespace ::std; void solve() { int n, m; cin >> n >> m; int sameW = 0; map<string, bool> a; string b; for (int i = 0; i < n + m; i++) { cin >> b; if (a.find(b) != a.end()) sameW++; else a[b] = true; } if (n > m) cout << "YES" << endl; else if (n < m) cout << "NO" << endl; else { if (sameW % 2) cout << "YES" << endl; else cout << "NO" << endl; } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; set<string> v[3]; int main() { ios::sync_with_stdio(false); int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { string s; cin >> s; v[0].insert(s); } for (int i = 0; i < m; i++) { string s; cin >> s; v[2].insert(s); } int turn = -1; while (v[0].size() && v[2].size()) { bool flag = false; for (set<string>::iterator it = v[turn + 1].begin(); it != v[turn + 1].end(); it++) { if (v[1 - turn].count(*it)) { flag = true; string rem = *it; v[0].erase(rem); v[2].erase(rem); break; } } if (!flag) { v[turn + 1].erase(v[turn + 1].begin()); } turn = -turn; } if (v[0].size() == 0 && v[2].size() == 0) { if (turn == -1) cout << "NO" << "\n"; else cout << "YES" << "\n"; } else if (v[0].size() == 0) { cout << "NO" << "\n"; } else cout << "YES" << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; const long long inf = 9e18; const long long M = 1e9 + 7; const long long N = 1e2 + 5; set<string> st; map<string, bool> b1, b2; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, m, nos(0), n1(0), n2(0), res1(0), res2(0); cin >> n >> m; for (long long i = 0; i < n; ++i) { string s; cin >> s; st.insert(s); b1[s] = 1; } for (long long i = 0; i < m; ++i) { string s; cin >> s; st.insert(s); b2[s] = 1; } for (set<string>::iterator it = st.begin(); it != st.end(); it++) { if (b1[*it] && b2[*it]) { ++nos; } } n1 = (nos + 1) / 2, n2 = nos - n1; for (map<string, bool>::iterator it = b1.begin(); it != b1.end(); ++it) { if (it->second) ++res1; } for (map<string, bool>::iterator it = b2.begin(); it != b2.end(); ++it) { if (it->second) ++res2; } if (n1 + res1 > n2 + res2) { cout << "YES"; } else { cout << "NO"; } }
#include <bits/stdc++.h> using namespace std; int main() { int n, m, same = 0; set<string> S; string s; scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) { cin >> s; S.insert(s); } for (int i = 0; i < m; i++) { cin >> s; if (S.find(s) != S.end()) same++; } n -= same; m -= same; if (same % 2 == 0) { if (n > m) printf("YES"); else printf("NO"); } else { if (m > n) printf("NO"); else printf("YES"); } return 0; }
#include <bits/stdc++.h> using namespace std; set<string> s; int main() { string str; int n, m; scanf("%d", &n); scanf("%d", &m); for (int i = 0; i < n; i++) { cin >> str; s.insert(str); } for (int j = 0; j < m; j++) { cin >> str; s.insert(str); } int l = s.size(); int t = n + m - l; int a = n - t, b = m - t; if (t % 2) { if (a >= b) { printf("YES"); return 0; } else { printf("NO"); return 0; } } else { if (a > b) { printf("YES"); return 0; } else { printf("NO"); return 0; } } return 0; }
#include <bits/stdc++.h> using namespace std; int N, M, c; string a[1010], b[1010]; map<string, bool> mp; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> N >> M; int i; for (i = 1; i <= N; i++) cin >> a[i], mp[a[i]] = 1; for (i = 1; i <= M; i++) { cin >> b[i]; if (mp[b[i]]) c++; } N = N - c + (c + 1) / 2; M = M - c + c / 2; if (N > M) cout << "YES\n"; else cout << "NO\n"; return 0; }
#include <bits/stdc++.h> using namespace std; bool play(set<string> &p1, set<string> &p2, set<string> &both, string a) { p1.erase(a); p2.erase(a); both.erase(a); } int main() { int n, m; cin >> n >> m; string word; set<string> ball, eball, both; for (int i = 0; i < n; ++i) { cin >> word; ball.insert(word); } for (int i = 0; i < m; ++i) { cin >> word; if (ball.find(word) != ball.end()) both.insert(word); eball.insert(word); } int turn = 1; while (!both.empty()) { play(ball, eball, both, *both.begin()); turn = 2; if (both.empty()) break; play(ball, eball, both, *both.begin()); turn = 1; } bool win = true; while (1) { if (turn == 1) { turn = 2; if (ball.empty()) { win = false; break; } ball.erase(ball.begin()); } else { turn = 1; if (eball.empty()) break; eball.erase(eball.begin()); } } cout << (win ? "YES" : "NO") << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int PB, EB; cin >> PB >> EB; string PBW[1001], EBW[1001]; map<string, bool> interc; int u_P = 0, u_E = 0, c_W = 0; for (int i = 1; i <= PB; i++) { cin >> PBW[i]; interc[PBW[i]] = true; u_P++; } for (int i = 1; i <= EB; i++) { cin >> EBW[i]; if (interc[EBW[i]] == true) { u_P--; u_E--; c_W++; } u_E++; } int t = 0; if (c_W % 2 == 1) t = 1; if (t == 1) u_E--; if (u_P > u_E) cout << "YES"; if (u_P < u_E) cout << "NO"; if (u_P == u_E) cout << "NO"; return 0; }
#include <bits/stdc++.h> using namespace std; const long long N = 1e5; set<string> p, v; int32_t main() { ios::sync_with_stdio(false); long long n, m, cnt = 0; cin >> n >> m; ++n; ++m; while (--n) { string second; cin >> second; p.insert(second); } while (--m) { string second; cin >> second; v.insert(second); } auto x = p.begin(); for (; x != p.end(); ++x) { auto t = *x; bool c = v.count(t); if (c) ++cnt; } long long pp = 0, pv = 0; pp += cnt / 2 + cnt % 2; pv += cnt / 2; pp += p.size() - cnt; pv += v.size() - cnt; bool c = (pp > pv); if (c) cout << "YES"; else cout << "NO"; }
#include <bits/stdc++.h> using namespace std; const int INF = (int)(1e9 + 1337); const long long LINF = (long long)(4e18); const double EPS = (double)(1e-11); int n, m; set<string> s, s1, s2; int cnt1, cnt2, cnt; vector<string> v1, v2; void to_vector(set<string> &s, vector<string> &v) { for (auto it = s.begin(); it != s.end(); it++) { v.push_back(*it); } } void init() { cin >> n >> m; for (int i = 1; i <= n; i++) { string cur; cin >> cur; s.insert(cur); s1.insert(cur); } for (int i = 1; i <= m; i++) { string cur; cin >> cur; s.insert(cur); s2.insert(cur); } } void solve() { init(); to_vector(s1, v1); to_vector(s2, v2); int ptr1 = 0, ptr2 = 0; for (auto it = s.begin(); it != s.end(); it++) { while (ptr1 < (int)v1.size() && v1[ptr1] < *it) { ptr1++; } while (ptr2 < (int)v2.size() && v2[ptr2] < *it) { ptr2++; } if (ptr1 < (int)v1.size() && v1[ptr1] == *it && ptr2 < (int)v2.size() && v2[ptr2] == *it) { cnt++; } else { if (ptr1 < (int)v1.size() && v1[ptr1] == *it) { cnt1++; } else { cnt2++; } } } cnt &= 1; cnt1 += cnt; if (cnt1 > cnt2) { cout << "YES\n"; } else { cout << "NO\n"; } } int main() { solve(); }
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; string s; map<string, bool> poland; map<string, bool> enemy; for (int i = 0; i < n; ++i) { cin >> s; poland[s] = true; } for (int i = 0; i < m; ++i) { cin >> s; enemy[s] = true; } if (n < m) { cout << "NO"; return 0; } if (n > m) { cout << "YES"; return 0; } int temp = 0; for (map<string, bool>::iterator it = poland.begin(); it != poland.end(); ++it) { if (enemy[it->first]) { temp++; } } string res; if ((temp % 2) == 1) res = "YES"; else res = "NO"; cout << res; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; set<string> st; string a; for (int i = 0; i < n; i++) { cin >> a; st.insert(a); } for (int i = 0; i < m; i++) { cin >> a; st.insert(a); } int k = n + m - st.size(); if (n > (m -= (k % 2))) { cout << "YES" << endl; } else { cout << "NO" << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; if (n > m) { cout << "YES" << endl; return 0; } if (n < m) { cout << "NO" << endl; return 0; } map<string, int> mapa; for (int i = 0; i < n; i++) { string a1; cin >> a1; mapa[a1] = 1; } int sum = 0; for (int i = 0; i < m; i++) { string a1; cin >> a1; if (mapa.find(a1) != mapa.end()) { sum++; } } if (n % 2 == 0) { if ((n - sum) % 2) { cout << "YES" << endl; } else { cout << "NO" << endl; } } else { if ((n - sum) % 2) { cout << "NO" << endl; } else { cout << "YES" << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, m, fp, sp; cin >> n >> m; int k = n + m, z = k; set<string> s; while (k--) { string t; cin >> t; s.insert(t); } if ((z - s.size()) % 2 == 1) { n++; } if (n > m) { cout << "YES"; } else { cout << "NO"; } return 0; }
#include <bits/stdc++.h> using namespace std; int n, m, x[1004], y[1004]; string a[1004], b[1004]; int main() { cin.sync_with_stdio(false); cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) cin >> b[i]; sort(a, a + n); sort(b, b + m); for (int i = 0, j = 0; i < n; i++) { while (j < m and a[i] > b[j]) j++; if (j < m and a[i] == b[j]) x[i] = y[j] = 1; } int ao = 0, ax = 0, bo = 0, bx = 0; for (int i = 0; i < n; i++) { if (x[i]) ao++; else ax++; } for (int i = 0; i < m; i++) { if (y[i]) bo++; else bx++; } bool yes; if (ao & 1) yes = (ax >= bx); else yes = (ax > bx); cout << (yes ? "YES" : "NO"); }
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const int inf = 1e9 + 1; const double eps = 1e-15; const double EPS = 1e-9; const double PI = acos(-1.0); int main() { ios_base ::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; set<string> p, e; string s; for (int i = 0; i < n; i++) { cin >> s; p.insert(s); } for (int i = 0; i < m; i++) { cin >> s; e.insert(s); } int cnt = 0; if (n == m) { for (auto it : p) { if (e.find(it) != e.end()) { cnt++; } } n -= cnt; m -= cnt; n += ((cnt + 1) / 2); m += ((cnt - (cnt + 1) / 2)); cout << ((n > m) ? "YES\n" : "NO\n"); } else if (n > m) { cout << "YES"; } else cout << "NO"; return 0; }
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int N = 1e5 + 5; const float pi = 3.14159265358979323; const long long inf = 1e18 + 5; const long double eps = pow(2, -52); int n, m; string test; map<string, int> p1, p2; int main() { cin >> n >> m; for (int i = 0; i < n; i++) cin >> test, p1[test]++; for (int i = 0; i < m; i++) cin >> test, p2[test]++; int common = 0; map<string, int>::iterator it; for (it = p1.begin(); it != p1.end(); it++) if (p2.find(it->first) != p2.end()) common++; int turn; if (common % 2) turn = 2; else turn = 1; n -= common; m -= common; if (turn == 1) { if (n > m) cout << "YES"; else cout << "NO"; } else { if (n >= m) cout << "YES"; else cout << "NO"; } }
#include <bits/stdc++.h> using namespace std; int n, m, cnt; map<string, int> mymap; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for (int i = 0; i < n; i++) { string st; cin >> st; ++mymap[st]; } for (int i = 0; i < m; i++) { string st; cin >> st; ++mymap[st]; } for (map<string, int>::iterator ii = mymap.begin(); ii != mymap.end(); ii++) { int sec = (*ii).second; if (sec == 2) ++cnt; } n -= cnt; m -= cnt; if (cnt & 1) { if (n < m) cout << "NO" << "\n"; else cout << "YES" << "\n"; } else { if (n > m) cout << "YES" << "\n"; else cout << "NO" << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; int main(int argc, char** argv) { int n, m; while (cin >> n >> m) { map<string, bool> myMap; string s; for (int i = 0; i < n; i++) { cin >> s; myMap[s] = true; } int inSec = 0; for (int i = 0; i < m; i++) { cin >> s; if (myMap[s]) inSec++; } if (inSec % 2 != 0) m--; if (n > m) cout << "YES" << endl; else cout << "NO" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; string s; map<string, int> mp; for (int i = 0; i < n; i++) { cin >> s; mp[s]++; } for (int i = 0; i < m; i++) { cin >> s; mp[s]++; } map<string, int>::iterator it = mp.begin(); int cnt = 0; for (; it != mp.end(); it++) cnt ^= it->second; if (n > m) cout << "YES" << endl; else if (m > n) cout << "NO" << endl; else { if (!cnt) cout << "NO" << endl; else cout << "YES" << endl; } }
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> std::pair<T, U> operator+(const std::pair<T, U>& l, const std::pair<T, U>& r) { return {l.first + r.first, l.second + r.second}; } typedef void (*callback_function)(void); const long long INF64 = 1e18; const long long INF32 = 1e9; int main() { ios_base::sync_with_stdio(false); cin.tie(); { long long n, m; cin >> n >> m; set<string> st; long long common = 0; string s; for (long long i = (0); i < (n); i++) { cin >> s; st.insert(s); } for (long long i = (0); i < (m); i++) { cin >> s; if (st.count(s)) common++; } n -= common, m -= common; long long b = common / 2, a = common - b; cout << (a + n > b + m ? "YES" : "NO") << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; set<string> bothSet(set<string>& first, set<string>& second) { set<string> result; set<string>::iterator it = second.begin(); while (it != second.end()) { if (first.count(*it) == 1) { result.insert(*it); } it++; } return result; } set<string> only(set<string>& first, set<string>& second) { set<string> result; set<string>::iterator it1 = first.begin(); while (it1 != first.end()) { result.insert(*it1); it1++; } set<string>::iterator it2 = second.begin(); while (it2 != second.end()) { result.erase(*it2); it2++; } return result; } void printSet(set<string>& s) { set<string>::iterator it = s.begin(); while (it != s.end()) { cout << *it << " "; it++; } } int main() { int n, m; cin >> n >> m; set<string> s1; set<string> s2; for (int i = 0; i < n; i++) { string s; cin >> s; s1.insert(s); } for (int i = 0; i < m; i++) { string s; cin >> s; s2.insert(s); } set<string> onlyFirst = only(s1, s2); set<string> onlySecond = only(s2, s1); set<string> both = bothSet(s1, s2); if (onlyFirst.size() > onlySecond.size()) { cout << "YES" << endl; } else if (onlyFirst.size() < onlySecond.size()) { cout << "NO" << endl; } else { if (onlyFirst.size() == onlySecond.size()) { if (both.size() % 2 == 1) { cout << "YES" << endl; } else { cout << "NO" << endl; } } } return 0; }
#include <bits/stdc++.h> using namespace std; const int MaxN = 1000; string a[MaxN + 5]; string b[MaxN + 5]; int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= m; i++) cin >> b[i]; if (n == m) { int cnt = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { if (a[i] == b[j]) cnt++; } } if (cnt != n) { if (cnt % 2 == 1) { printf("Yes\n"); } else { printf("No\n"); } } else { n % 2 ? printf("Yes\n") : printf("No\n"); } } else m > n ? printf("No\n") : printf("Yes\n"); }
#include <bits/stdc++.h> using namespace std; bool isPrime(long long n) { if (n == 1) return false; for (long long i = 2; i <= (long long)sqrt(n); i++) if (n % i == 0) return false; return true; } long long GCD(long long a, long long b) { while (b) { long long c = b; b = a % b; a = c; } return a; } long long LCM(long long a, long long b) { if (!a || !b) return 0; return (a * b) / GCD(a, b); } vector<long long> SOE(long long n) { vector<long long> vec(n + 1, 0); vec[0] = vec[1] = 0; vec[2] = 1; for (int i = 3; i <= n; i += 2) vec[i] = 1; for (int i = 3; i <= (long long)sqrt(n); i++) { if (vec[i] == 1) { for (int j = i * i; j <= n; j += i) vec[j] = 0; } } return vec; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long n = 0, m = 0; cin >> n >> m; vector<string> poll(n); vector<string> enem(m); set<string> s; for (long long i = 0; i < n; i++) cin >> poll[i], s.insert(poll[i]); for (long long i = 0; i < m; i++) cin >> enem[i]; if (n > m) cout << "YES" << "\n"; else if (n < m) cout << "NO" << "\n"; else { long long cnt = s.size(); for (long long i = 0; i < m; i++) { string val = enem[i]; if (s.find(val) != s.end()) continue; else cnt++; } cout << (cnt % 2 == 0 ? "NO" : "YES") << "\n"; } }
#include <bits/stdc++.h> using namespace std; vector<string> a, b; int n, m, k; string s; int main() { cin >> n >> m; for (int i = 0; i < n; ++i) { cin >> s; a.push_back(s); } for (int i = 0; i < m; ++i) { cin >> s; b.push_back(s); } for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { if (a[i] == b[j]) ++k; } } if (k % 2 == 0) { if (n > m) cout << "YES"; else cout << "NO"; } else { if (n >= m) cout << "YES"; else cout << "NO"; } }
#include <bits/stdc++.h> using namespace std; int main() { map<string, bool> w; string a; int n, m, d = 0; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> a; w[a] = true; } for (int i = 0; i < m; i++) { cin >> a; if (w[a]) d++; } if (d % 2 == 1) n++; if (n > m) cout << "YES"; else cout << "NO"; return 0; }
#include <bits/stdc++.h> using namespace std; map<string, long long int> ma, mb; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int i, m, n, x, j = 0, c = 0, r = 0, l, k, w = 0, s = 0, d = 0, f = 0, sum = 0, mul, s1 = 0, s2 = 0, mx1 = -1, mx2 = -1, mx3 = -1, mx = 1000000000000000000; cin >> n >> m; k = n; while (n--) { string a; cin >> a; ma[a]++; } l = m; while (m--) { string a; cin >> a; if (ma[a] != 0) { c++; } } if (k - c + (c % 2) > (l - c)) { cout << "YES" << endl; } else cout << "NO" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; string s; set<string> st; for (int i = 0; i < n + m; i++) { cin >> s; st.insert(s); } int i = n + m - st.size(); m -= i % 2; if (m < n) { cout << "YES" << endl; } else { cout << "NO" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; long long power(long long x, long long y, long long p) { long long res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } int main() { { ios_base::sync_with_stdio(false); cin.tie(NULL); }; long long n, m; cin >> n >> m; set<string> a, b; long long comm = 0; for (long long i = 0; i < n; i++) { string x; cin >> x; a.insert(x); } for (long long i = 0; i < m; i++) { string x; cin >> x; if (a.find(x) != a.end()) comm++; b.insert(x); } if (a.size() + (1 & comm) > b.size()) { cout << "YES\n"; } else cout << "NO\n"; return 0; }
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; } template <typename T1, typename T2> inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; } inline int readChar(); template <class T = int> inline T readInt(); template <class T> inline void writeInt(T x, char end = 0); inline void writeChar(int x); inline void writeWord(const char *s); static const int buf_size = 4096; inline int getChar() { static char buf[buf_size]; static int len = 0, pos = 0; if (pos == len) pos = 0, len = fread(buf, 1, buf_size, stdin); if (pos == len) return -1; return buf[pos++]; } inline int readChar() { int c = getChar(); while (c <= 32) c = getChar(); return c; } template <class T> inline T readInt() { int s = 1, c = readChar(); T x = 0; if (c == '-') s = -1, c = getChar(); while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getChar(); return s == 1 ? x : -x; } static int write_pos = 0; static char write_buf[buf_size]; inline void writeChar(int x) { if (write_pos == buf_size) fwrite(write_buf, 1, buf_size, stdout), write_pos = 0; write_buf[write_pos++] = x; } template <class T> inline void writeInt(T x, char end) { if (x < 0) writeChar('-'), x = -x; char s[24]; int n = 0; while (x || !n) s[n++] = '0' + x % 10, x /= 10; while (n--) writeChar(s[n]); if (end) writeChar(end); } inline void writeWord(const char *s) { while (*s) writeChar(*s++); } struct Flusher { ~Flusher() { if (write_pos) fwrite(write_buf, 1, write_pos, stdout), write_pos = 0; } } flusher; const int MAXN = 1001; int n, m; string s[MAXN], s1[MAXN]; unordered_map<string, int> k; int main() { cin >> n >> m; for (int i = 0; i < n; i++) { cin >> s[i]; } for (int i = 0; i < m; i++) { cin >> s1[i]; k[s1[i]]++; } int cnt = 0; for (int i = 0; i < n; i++) { if (k[s[i]]) { cnt++; } } int t = n - cnt + (cnt + 1) / 2; int t1 = m - cnt + cnt / 2; if (t > t1) { puts("YES"); } else { puts("NO"); } return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; double pi = 3.1415926535898; const long long M = 1e9 + 7; const int N = 50500; const int inf = INT_MAX; const double eps = 1e-6; string pol[1111], enm[1111]; set<string> setter; int main() { int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> pol[i]; setter.insert(pol[i]); } for (int i = 0; i < m; i++) { cin >> enm[i]; setter.insert(enm[i]); } if (n > m) cout << "YES"; else if (n < m) cout << "NO"; else if (n == m) { int num = setter.size(); if (num % 2) cout << "YES"; else cout << "NO"; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { map<string, bool> pw; map<string, bool> ew; int nc = 0; int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { string t; cin >> t; pw[t] = true; } for (int i = 0; i < m; i++) { string t; cin >> t; ew[t] = true; if (pw.find(t) != pw.end()) nc++; } if (n > m) { cout << "YES\n"; return 0; } if (m > n) { cout << "NO\n"; return 0; } if (nc == 0) { cout << "NO\n"; return 0; } if ((nc % 2)) { cout << "YES\n"; return 0; } if (!(nc % 2)) { cout << "NO\n"; return 0; } }
#include <bits/stdc++.h> using namespace std; int main() { int n, m; string s; set<string> a, b, ab; scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) { cin >> s; a.insert(s); } for (int i = 0; i < m; i++) { cin >> s; if (a.find(s) != a.end()) { a.erase(s); ab.insert(s); } else b.insert(s); } if (a.size() > b.size()) printf("YES"); else if (a.size() + 1 < b.size()) printf("NO"); else { if (ab.size() & 1 && a.size() == b.size()) printf("YES"); else printf("NO"); } }
#include <bits/stdc++.h> using namespace std; int main() { int n, m, p = 0; cin >> n >> m; string a[n], b[m]; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < m; i++) { cin >> b[i]; for (int j = 0; j < n; j++) { if (b[i] == a[j]) { p = p + 1; break; } } } if (n > m) { cout << "YES"; } if (n < m) { cout << "NO"; } if (n == m) { if (p % 2 == 1) { cout << "YES"; } else cout << "NO"; } }
#include <bits/stdc++.h> using namespace std; signed main() { set<string> st; int64_t n, m; cin >> n >> m; for (int64_t i = 0; i < n + m; ++i) { string second; cin >> second; st.insert(second); } if (n > m) { cout << "YES" << '\n'; } else if (n < m) { cout << "NO" << '\n'; } else { if (st.size() % 2 == 0) { cout << "NO" << '\n'; } else { cout << "YES" << '\n'; } } return 0; }
#include <bits/stdc++.h> const int LARGE = int(1e9); const int SMALL = int((-1) * 1e9); using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; set<string> a; set<string> b; for (int x = 0; x < n; x++) { string t; cin >> t; a.insert(t); } for (int x = 0; x < m; x++) { string t; cin >> t; b.insert(t); } int common = 0; for (set<string>::iterator itr = a.begin(); itr != a.end(); itr++) { if (b.count(*itr) > 0) common++; } int u = (common + 1) / 2 + a.size() - common; int v = common / 2 + b.size() - common; cout << ((u > v) ? "YES" : "NO") << "\n"; return 0; }
#include <bits/stdc++.h> char s1[1002][502]; char s2[1002][502]; int main() { int n, m; scanf("%d %d", &n, &m); int i; for (i = 1; i <= n; i++) scanf("%s", s1[i]); for (i = 1; i <= m; i++) scanf("%s", s2[i]); int j, cnt = 0; for (i = 1; i <= n; i++) { for (j = 1; j <= m; j++) { int k = 0; int f = 0; if (strlen(s1[i]) == strlen(s2[j])) { while (s1[i][k] != '\0' && s2[j][k] != '\0') { if (s1[i][k] != s2[j][k]) { f = 1; break; } k++; } if (k == strlen(s1[i])) cnt++; } } } if (n > m) { printf("YES\n"); return 0; } if (m > n) { printf("NO\n"); } if (n == m && cnt == 0) { printf("NO\n"); return 0; } if (n == m && cnt % 2 == 1) { printf("YES\n"); } if (n == m && cnt % 2 == 0) { printf("NO\n"); return 0; } }
#include <bits/stdc++.h> using namespace std; int main() { map<string, bool> pw; map<string, bool> ew; int nc = 0; int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { string t; cin >> t; pw[t] = true; } for (int i = 0; i < m; i++) { string t; cin >> t; ew[t] = true; if (pw.find(t) != pw.end()) nc++; } if (n > m) { cout << "YES\n"; return 0; } if (n < m) { cout << "NO\n"; return 0; } if (nc == 0) { cout << "NO\n"; return 0; } if (nc % 2 == 0) { cout << "NO\n"; return 0; } if (nc % 2 == 1) { cout << "YES\n"; return 0; } }
#include <bits/stdc++.h> using namespace std; int eve(long long int x) { if (x % 2 == 0) return 1; return 0; } void solve() { int x, i, n, m; cin >> n >> m; string t; map<string, int> mp; for (i = 0; i < n; ++i) { cin >> t; mp[t] = 1; } x = 0; for (i = 0; i < m; ++i) { cin >> t; if (mp[t]) x++; } if (n - x > m - x) x = 1; else if (n - x < m - x) x = 0; else if (x % 2 == 1) x = 1; else x = 0; if (x == 0) cout << "NO"; else cout << "YES"; cout << endl; ; } int main() { ios_base::sync_with_stdio(false); int t = 1; while (t--) { solve(); } }
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k = 0, l = 0; char a[1100][600], b[1100][600]; scanf("%d %d", &n, &m); for (int i = 0; i < n; i++) { scanf("%s", a[i]); } for (int i = 0; i < m; i++) { scanf("%s", b[i]); } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (strcmp(a[i], b[j]) == 0) { k++; } } } if (k % 2 == 1) { m = m - 1; } if (n > m) { printf("YES\n"); } else { printf("NO\n"); } }
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 5, OO = 0x3f3f3f3f; int n, m, cnt = 0; string s; map<string, int> mp; int main() { cin.tie(0); cin.sync_with_stdio(0); cin >> n >> m; for (int i = 0; i < n; i++) { cin >> s; mp[s]++; } for (int i = 0; i < m; i++) { cin >> s; if (mp[s]) cnt++; } n -= cnt, m -= cnt; if (cnt % 2 == 1) n++; if (m >= n) puts("NO"); else puts("YES"); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; set<string> words; for (int i = 0; i < n; i++) { string s; cin >> s; words.insert(s); } int common = 0; for (int i = 0; i < m; i++) { string s; cin >> s; common += words.count(s); } int player = 0; n -= common; m -= common; while (common > 0) { common--; player = (player + 1) % 2; } if (n > m) player = 0; else if (m > n) player = 1; else player = (player + 1) % 2; (player) ? cout << "NO" : cout << "YES"; }
#include <bits/stdc++.h> using namespace std; double esp = 1e-8; const long double PI = acos((long double)-1); const long long int INF = 0x3f3f3f3fll; const int MOD = 1e9 + 7ll; const int maxn = 110100; set<long long int> q; vector<long long int> tq; long long int A[maxn]; map<long long int, int> qu; int main() { long long int n, k; q.clear(); scanf("%I64d%I64d", &n, &k); qu.clear(); long long int sum = 0; for (int x = 1; x <= n; x++) { scanf("%I64d", &A[x]); sum += A[x]; qu[sum]++; } q.insert(1); if (abs(k) == 1) { q.insert(k); q.insert(k * k); } else { long long int tem = 1; while (abs(tem) <= 1e16) { q.insert(tem); tem *= k; } } tq.clear(); for (long long int v : q) tq.push_back(v); long long int ans = 0, tsum = 0; for (int x = 1; x <= n; x++) { for (long long int v : tq) if (qu.find(tsum + v) != qu.end()) ans += qu[tsum + v]; tsum += A[x]; qu[tsum]--; } printf("%I64d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; long long a = 1; long long n, k, ans; long long v[100010]; vector<long long> V; map<long long, int> M; int main() { cin >> n >> k; for (int i = 1; i <= n; i++) cin >> v[i], v[i] += v[i - 1]; V.push_back(1); if (k != 1 && k != -1) while (a < 1e15) a *= k, V.push_back(a); if (k == -1) V.push_back(-1); M[0]++; for (int i = 1; i <= n; i++) { for (int h = 0; h < V.size(); h++) ans += M[-1 * (V[h] - v[i])]; M[v[i]]++; } cout << ans; }
#include <bits/stdc++.h> using namespace std; vector<bool> visited(200005, false); vector<long long> adj[200005]; vector<long long> tmp(200005); vector<long long> parent(200005, -1); long long ed, no; long long expo(long long x, long long n, long long M) { if (n == 0) return 1; else if (n % 2 == 0) return (expo((x * x) % M, n / 2, M)) % M; else return (x * expo((x * x) % M, (n - 1) / 2, M)) % M; } bool sortbysec( pair<pair<long long, long long>, pair<long long, long long>> p1, pair<pair<long long, long long>, pair<long long, long long>> p2) { if (p1.first.first != p2.first.first) return p1.first.first > p2.first.first; else { return p1.second.first < p2.second.first; } } void dfs(long long v1, long long p) { long long cnt = 1; for (long long j = 0; j < adj[v1].size(); j++) { long long x = adj[v1][j]; if (x == p) continue; while (tmp[v1] == cnt || tmp[p] == cnt) cnt++; tmp[x] = cnt; cnt++; dfs(x, v1); } } long long find(vector<long long> &parent, long long i) { while (parent[i] != i) { parent[i] = parent[parent[i]]; i = parent[i]; } return parent[i]; } void Union(vector<long long> &parent, long long i, long long j) { long long x = find(parent, i); long long y = find(parent, j); parent[x] = y; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long i, j, k, a, b, c, t, x, y, n, m, z, flag = 0, ans = 0, sum = 0; t = 1; while (t--) { string st, p, s1, s2; long long d; cin >> n >> k; vector<long long> v(n); for (i = 0; i < n; i++) { cin >> v[i]; } if (k == 1 || k == -1) { sum = 0; map<long long, long long> make_pair; for (j = 0; j < n; j++) { sum += v[j]; if (sum == 1) { ans++; } if (make_pair.find(sum - 1) != make_pair.end()) ans += make_pair[sum - 1]; make_pair[sum]++; } } if (k == -1) { sum = 0; map<long long, long long> make_pair; for (j = 0; j < n; j++) { sum += v[j]; if (sum == -1) { ans++; } if (make_pair.find(sum + 1) != make_pair.end()) ans += make_pair[sum + 1]; make_pair[sum]++; } } if (k == 1 || k == -1) { cout << ans; return 0; } ans = 0; for (i = 0; i <= 50; i++) { x = pow(k, i); if (x >= LONG_LONG_MAX) break; sum = 0; map<long long, long long> make_pair; for (j = 0; j < n; j++) { sum += v[j]; if (sum == x) { ans++; } if (make_pair.find(sum - x) != make_pair.end()) ans += make_pair[sum - x]; make_pair[sum]++; } } cout << ans; } return 0; }
#include <bits/stdc++.h> using namespace std; vector<long long int> kp; map<long long int, long long int> m; long long int sum[2000000]; long long int M = 1e14; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int n, k; cin >> n >> k; long long int aa = 1; int kk = 1; long long int lim = 60; long long int a[n + 1]; for (int i = 1; i <= n; i++) { cin >> a[i]; if (i == 1) { sum[i] = a[i]; } sum[i] = sum[i - 1] + a[i]; } if (k == 1) { kp.push_back(1); } else if (k == -1) { kp.push_back(-1); kp.push_back(1); } else { while (aa <= M and aa >= -M) { kp.push_back(aa); aa = aa * k; kk++; } } long long int cnt = 0; m[0] = 1; for (int i = 1; i <= n; i++) { for (int j = 0; j < kp.size(); j++) { long long int key1 = sum[i] - kp[j]; cnt += m[key1]; } m[sum[i]]++; } cout << cnt << endl; return 0; }
#include <bits/stdc++.h> using namespace std; long long int n, k; long long int a[1000001]; long long int prefix[1000001]; map<long long int, long long int> save; vector<long long int> power; int main() { cin >> n >> k; for (long long int i = 1; i <= n; i++) { cin >> a[i]; } if (k == 1) { power.push_back(1); } else if (k == -1) { power.push_back(1); power.push_back(-1); } else { long long int temp = 1; while (temp <= 1e16) { power.push_back(temp); temp = temp * k; } } for (long long int i = 1; i <= n; i++) { prefix[i] = prefix[i - 1] + a[i]; } save[0] = 1; long long int ans = 0; for (long long int i = 1; i <= n; i++) { long long int val = prefix[i]; save[val]++; for (long long int j = 0; j < power.size(); j++) { long long int req = val - power[j]; ans = ans + save[req]; } } cout << ans; }
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; using ll = long long; ll a[maxn], pref[maxn]; int n; ll get(ll k) { ll ret = 0; map<ll, int> mp; mp[0] = 1; for (int i = 1; i <= n; ++i) { ret += mp[pref[i] - k]; mp[pref[i]]++; } return ret; } int main(int argc, char const *argv[]) { ll k; scanf("%d %lld", &n, &k); int pos = 0, neg = 0; for (int i = 1; i <= n; ++i) { scanf("%lld", &a[i]); if (a[i] >= 1) { pos = 1; } if (a[i] <= -1) { neg = 1; } pref[i] = pref[i - 1] + a[i]; } if (llabs(k) == 1) { ll ans = 0; if (k == 1) { cout << get(1) << endl; } else { ans += get(1); ans += get(-1); cout << ans << endl; } } else { ll ans = get(1); ll kk = k; while (llabs(kk) <= 100000000000000LL) { ans += get(kk); kk *= k; } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int lcm(int a, int b) { return a * (b / gcd(a, b)); } const int maxSize = 100000 + 5; int main() { int n, k; cin >> n >> k; vector<long long int> arr(n); for (int i = 0; i < n; i++) { cin >> arr[i]; } vector<long long int> pwr; long long int limit = 1e14; long long int ans = 1; pwr.push_back(1); if (abs(k) > 1) { while (ans * k <= limit) { ans *= k; pwr.push_back(ans); } } else if (k == -1) { pwr.push_back(-1); } map<long long int, long long int> make_pair; long long int sum = 0; ans = 0; for (int i = 0; i < n; i++) { make_pair[sum]++; sum += arr[i]; for (auto pw : pwr) { if (make_pair.count(sum - pw) > 0) { ans += make_pair[sum - pw]; } } } cout << ans; }
#include <bits/stdc++.h> using namespace std; map<long long, int> mp; int a[100010], b[100010]; long long dex, x, k, n, p, ans; int main() { cin >> n >> k; for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } p = 1; while (abs(p) < 1e15) { mp.clear(); dex = 0; mp[0] = 1; for (int i = 0; i < n; i++) { dex += a[i]; ans += mp[dex - p]; mp[dex]++; } p *= k; if (p == 1) break; } cout << ans << endl; }