voidsolve(){ int _; cin >> _; for (int tc = 0; tc < _; ++tc) { int n; cin >> n; vector<int> data(n); for (auto &i: data) cin >> i; int tar = 0; for (constauto &i: data) tar += i; tar /= n; int last = 0; bool flag = true; for (constauto& i:data) { last += i - tar; if (last < 0) flag = false; } cout << (flag ? "YES" : "No") << endl; } }
voidsolve(){ int _; cin >> _; for (int tc = 0; tc < _; ++tc) { int n, x, y; cin >> n >> x >> y; map<int, int> cnt; int ans = 0; for (int i = 0; i < n; ++i) { int tmp; cin >> tmp; int a = tmp % x, b = tmp % y; auto iter = cnt.find(a << 32 | b); if (iter != cnt.end()) ans += iter->second; ++cnt[(a == 0 ? 0 : (x - a)) << 32 | b]; } cout << ans << endl; } }
voidsolve(){ int _; cin >> _; for (int tc = 0; tc < _; ++tc) { int n, m; cin >> n >> m; vector<int> data(n); int tot = 0; for (int i = 0; i < n; ++i) { int tmp; cin >> tmp; for (int j = 1000000000, k = 9; j >= 1; j /= 10, --k) if (tmp % j == 0) { data[i] = k; break; } for (int j = 1000000000, k = 10; j >= 1; j /= 10, --k) if (tmp >= j) { tot += k; break; } } sort(data.begin(), data.end(), greater<>()); for (int i = 0; i < n; i += 2) tot -= data[i]; cout << (tot > m ? "Sasha" : "Anna") << endl; } }
voidsolve(){ int _; cin >> _; for (int tc = 0; tc < _; ++tc) { int n, k; cin >> n >> k; vector<vector<int>> data(k); for (auto &v: data) { v.resize(n); for (auto &i: v) cin >> i; }
if (k == 1) { cout << "YES" << endl; continue; }
vector<set<int>> map(n); for (constauto &v: data) for (int i = 2; i < n; ++i) map[v[i - 1] - 1].insert(v[i] - 1);
vector<int> deg(n); for (constauto &v: map) for (constauto &i: v) ++deg[i]; queue<int> q; int cnt = 0; for (int i = 0; i < n; ++i) if (!deg[i]) q.push(i); while (!q.empty()) { auto cur = q.front(); q.pop(); ++cnt; for (constauto& i: map[cur]) if (!--deg[i]) q.push(i); } cout << (cnt == n ? "YES" : "NO") << endl; } }
voidsolve(){ int _; cin >> _; for (int tc = 0; tc < _; ++tc) { constexprint mod = 998244353; auto qp = [&](int a, int p) { int res = 1; while (p) { if (p & 1) res = res * a % mod; a = a * a % mod; p >>= 1; } return res; }; auto inv = [&](int v) { returnqp(v, mod - 2); }; auto step = [&](int n) { int res = 1; for (int i = 2; i <= n; ++i) res = res * i % mod; return res; }; auto cal = [&](int n, int m) { int a = step(n + m -1), b = step(m - 1), c = step(n); a = a * inv(b) % mod; a = a * inv(c) % mod; return a; };
int c1, c2, c3, c4; cin >> c1 >> c2 >> c3 >> c4; if (abs(c1 - c2) > 1 || (c1 == 0 && c2 == 0 && c3 != 0 && c4 != 0)) { cout << 0 << endl; continue; } if (c1 == 0 && c2 == 0) { cout << 1 << endl; continue; } int ans = 1; int tmp = max(c1, c2); if (c1 == c2) { int ans1 = 1, ans2 = 1; if (c3 != 0) { ans1 = ans1 * cal(c3, tmp) % mod; ans2 = ans2 * cal(c3, tmp + 1) % mod; } if (c4 != 0) { ans2 = ans2 * cal(c4, tmp) % mod; ans1 = ans1 * cal(c4, tmp + 1) % mod; } ans = (ans1 + ans2) % mod; } else { if (c3 != 0) ans = ans * cal(c3, tmp) % mod; if (c4 != 0) ans = ans * cal(c4, tmp) % mod; } cout << ans << endl; } }