Idea: BledDest
Tutorial
Tutorial is loading...
Solution (BledDest)
t = int(input())
for i in range(t):
n = int(input())
s = input()
if '2025' in s and not '2026' in s:
print(1)
else:
print(0)
Idea: BledDest
Tutorial
Tutorial is loading...
Solution (BledDest)
t = int(input())
for i in range(t):
a, b = map(int, input().split())
if a < b:
a, b = b, a
x, y = 0, 0
ans = 0
cur = 1
while True:
x, y = y + cur, x
if x <= a and y <= b:
ans += 1
cur *= 2
else:
break
print(ans)
Idea: Roms
Tutorial
Tutorial is loading...
Solution (BledDest)
def good(x, y, n, k):
ans = True
for i in range(n):
if x[i] <= y[(i + k) % n]:
ans = False
return ans
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
k1, k2 = 0, 0
for i in range(n):
if good(b, a, n, i):
k1 += 1
if good(c, b, n, i):
k2 += 1
print(k1 * k2 * n)
2182D - Christmas Tree Decoration
Idea: BledDest
Tutorial
Tutorial is loading...
Solution (Neon)
#include <bits/stdc++.h>
using namespace std;
const int N = 55;
const int MOD = 998244353;
int mul(int x, int y) {
return x * 1LL * y % MOD;
}
int binpow(int x, int y) {
int z = 1;
while (y > 0) {
if (y & 1) z = mul(z, x);
x = mul(x, x);
y >>= 1;
}
return z;
}
int main() {
vector<int> f(N, 1);
for (int i = 1; i < N; ++i)
f[i] = (f[i - 1] * 1LL * i) % MOD;
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> a(n + 1);
for (int &x : a) cin >> x;
int k = accumulate(a.begin(), a.end(), 0) / n;
int z = 0, bad = 0;
for (int i = 1; i <= n; ++i) {
int x = min(a[i], k);
a[i] -= x;
a[0] -= k - x;
z += a[i] == 0;
bad |= a[i] > 1 || a[0] < 0;
}
bad |= a[0] > z;
int ans = bad ? 0 : f[z];
if (!bad) {
ans = mul(ans, f[n - z + a[0]]);
ans = mul(ans, binpow(f[a[0]], MOD - 2));
}
cout << ans << '\n';
}
}
Idea: BledDest
Tutorial
Tutorial is loading...
Solution (Neon)
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, m;
long long k;
cin >> n >> m >> k;
vector<vector<int>> ev(m);
for (int i = 0; i < m; ++i) {
int x; cin >> x;
ev[x - 1].push_back(-1);
}
for (int i = 0; i < n; ++i) {
int x, y, z;
cin >> x >> y >> z;
ev[x - 1].push_back(z - y);
k -= y;
}
int ans = 0;
multiset<int> s;
for (int i = 0; i < m; ++i) {
reverse(ev[i].begin(), ev[i].end());
for (int x : ev[i]) {
if (x == -1) {
if (!s.empty()) {
s.erase(--s.end());
++ans;
}
} else {
s.insert(x);
}
}
}
while (!s.empty() && *s.begin() <= k) {
k -= *s.begin();
s.erase(s.begin());
++ans;
}
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(false); cin.tie(0);
int t;
cin >> t;
while (t--) solve();
}
2182F1 - Christmas Reindeer (easy version)
2182F2 - Christmas Reindeer (hard version)
Idea: Roms
Tutorial
Tutorial is loading...
Solution (BledDest)
#include<bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
const int LOGN = 61;
int add(int x, int y)
{
x += y;
if(x >= MOD) x -= MOD;
if(x < 0) x += MOD;
return x;
}
int sub(int x, int y)
{
return add(x, -y);
}
int mul(int x, int y)
{
return (x * 1ll * y) % MOD;
}
int binpow(int x, int y)
{
int z = 1;
while(y > 0)
{
if(y % 2 == 1) z = mul(z, x);
x = mul(x, x);
y /= 2;
}
return z;
}
vector<int> get_required(long long x)
{
vector<int> ans(LOGN);
int cnt = 0;
for(int i = LOGN - 1; i >= 0; i--)
{
if((x >> i) & 1)
{
ans[i + cnt]++;
cnt++;
}
}
return ans;
}
void solve()
{
int n, m;
cin >> n >> m;
vector<int> freq(LOGN);
for(int i = 0; i < n; i++)
{
int x;
cin >> x;
freq[x]++;
}
int max_n = n + m + 111;
vector<int> fact(max_n, 1);
for(int i = 1; i < max_n; i++)
fact[i] = mul(fact[i - 1], i);
vector<int> inv_fact(max_n);
for(int i = 0; i < max_n; i++)
inv_fact[i] = binpow(fact[i], MOD - 2);
vector<int> pow2(max_n, 1);
for(int i = 1; i < max_n; i++)
pow2[i] = mul(pow2[i - 1], 2);
auto choose = [&](int x, int y)
{
if(x < y || x < 0 || y < 0) return 0;
return mul(fact[x], mul(inv_fact[y], inv_fact[x - y]));
};
auto sum_greater = [&](int x, int y)
{
if(y >= x) return 0;
int ans = pow2[x];
for(int i = 0; i <= y; i++)
ans = sub(ans, choose(x, i));
return ans;
};
for(int i = 0; i < m; i++)
{
int t;
long long x;
cin >> t >> x;
if(t == 1)
freq[x]++;
else if(t == 2)
freq[x]--;
else
{
auto req = get_required(x);
int ans = 0;
int cur = 1;
int cnt_less = 0;
for(int i = 0; i < LOGN; i++) cnt_less += freq[i];
for(int i = LOGN - 1; i >= 0; i--)
{
cnt_less -= freq[i];
ans = add(ans, mul(cur, mul(sum_greater(freq[i], req[i]), pow2[cnt_less])));
cur = mul(cur, choose(freq[i], req[i]));
}
ans = add(ans, cur);
cout << ans << "\n";
}
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
//cin >> t;
for(int i = 0; i < t; i++) solve();
}
Idea: BledDest
Tutorial
Tutorial is loading...
Solution (awoo)
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
const int MOD = 998244353;
int add(int a, int b){
a += b;
if (a >= MOD) a -= MOD;
if (a < 0) a += MOD;
return a;
}
int mul(int a, int b){
return a * 1ll * b % MOD;
}
int binpow(int a, int b){
int res = 1;
while (b){
if (b & 1)
res = mul(res, a);
a = mul(a, a);
b >>= 1;
}
return res;
}
int n, k;
vector<vector<int>> g;
struct dpar{
vector<int> dp;
int ml, ad;
dpar(){
ml = 1, ad = 0;
dp.clear();
}
int& operator [](int k){
return dp[max(0, int(dp.size()) - k - 1)];
}
int get(int k){
int x = dp[max(0, int(dp.size()) - k - 1)];
return add(mul(x, ml), ad);
}
};
vector<dpar> dp;
vector<int> fact;
void dfs(int v){
int bst = -1;
vector<int> val;
for (int u : g[v]){
dfs(u);
dp[u].dp.push_back(add(0, mul(binpow(dp[u].ml, MOD - 2), -dp[u].ad)));
if (bst == -1 || dp[u].dp.size() > dp[bst].dp.size())
bst = u;
val.push_back(dp[u].get(k - 1));
}
if (val.empty()){
dp[v].dp.push_back(1);
return;
}
vector<int> pr(val.size() + 1, 1), su(val.size() + 1, 1);
forn(i, val.size()){
pr[i + 1] = mul(pr[i], val[i]);
su[val.size() - i - 1] = mul(su[val.size() - i], val[val.size() - i - 1]);
}
swap(dp[v], dp[bst]);
{
int i = find(g[v].begin(), g[v].end(), bst) - g[v].begin();
int cur = mul(fact[g[v].size() - 1], mul(pr[i], su[i + 1]));
if (cur == 0){
int mx = 1;
for (int u : g[v]) mx = max(mx, int(dp[u].dp.size()));
dp[v].dp.assign(mx, 0);
dp[v].ml = 1, dp[v].ad = 0;
}
else{
dp[v].ml = mul(dp[v].ml, cur);
dp[v].ad = mul(dp[v].ad, cur);
}
}
int rev = binpow(dp[v].ml, MOD - 2);
forn(i, g[v].size()){
int u = g[v][i];
if (u == bst) continue;
int cur = mul(fact[g[v].size() - 1], mul(pr[i], su[i + 1]));
int tot = mul(cur, dp[u].get(n));
dp[v].ad = add(dp[v].ad, tot);
forn(j, dp[u].dp.size()){
dp[v][j] = add(dp[v][j], -mul(rev, tot));
dp[v][j] = add(dp[v][j], mul(mul(cur, dp[u].get(j)), rev));
}
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int t;
cin >> t;
while (t--){
cin >> n >> k;
g.assign(n, {});
for (int i = 1; i < n; ++i){
int p;
cin >> p;
--p;
g[p].push_back(i);
}
dp.assign(n, {});
fact.resize(n + 1, 1);
for (int i = 1; i <= n; ++i)
fact[i] = mul(fact[i - 1], i);
dfs(0);
cout << dp[0].get(n) << '\n';
}
return 0;
}




