#include<bits/stdc++.h> intmain(){ std::cin.tie(nullptr)->sync_with_stdio(false); #define int long long constexprint N = 123456789LL; int tt; for (std::cin >> tt; tt--;) { int n, d; std::cin >> n >> d; int k = 123456789LL * std::pow<int>(10, 2 + (int)std::log10<int>(n)) / n + 1; auto check = [&](int w) { std::vector<int> c(10); int num = w * n; while (num) c[num % 10] += 1, num /= 10; for (int i = 1; i <= 9; ++i) if (c[i] < 1) { returnfalse; } return c[d] >= 2; }; while (!check(k)) k += 1; std::cout << k << '\n'; } }
#include<bits/stdc++.h> usingnamespace std; using ll = longlong; constexpr ll mod = 998244353;
//快速幂 constexprint P = 998244353; ll ksm(ll a , ll b){ ll res = 1; while (b) { if (b & 1) res = (ll)res * a % P; a = (ll)a * a % P; b >>= 1; } return res; } intmain(){ cin.tie(nullptr)->sync_with_stdio(false);
ll n , pren = 0 , fenzi = 1 , fenmu = 1; cin >> n; n *= 2; priority_queue <ll, vector<ll>, greater<ll>> ql; vector<ll> a(n+2); map<ll , ll> mp; for (int i=1; i <= n; ++ i) { cin >> a[i]; if (a[i] == -1) { ll len = (ll)ql.size(); fenmu = fenmu % mod * len % mod; fenzi = fenzi % mod * mp[ql.top()] % mod; pren = max(ql.top() , pren); mp[ql.top()]--; ql.pop(); } elseif (a[i] != -1) { ql.push(a[i]); mp[a[i]] ++; if (a[i] < pren) { fenzi = 0; } } } ll ans = fenzi * ksm(fenmu , mod - 2) % mod; std::cout << ans << "\n"; }
#include<bits/stdc++.h> using ULL = unsignedlonglong; intmain(){ std::cin.tie(nullptr)->sync_with_stdio(false); int tt; for (std::cin >> tt; tt--;)[&] { int n, k; std::cin >> n >> k; std::string s; std::cin >> s; constexprint P = 131; std::vector<ULL> h(n + 1), p(n + 1); p[0] = 1; for (int i = 0; i < n; ++i) { h[i + 1] = h[i] * P + s[i]; p[i + 1] = p[i] * P; } auto get = [&](int l, int r) { return h[r] - h[l - 1] * p[r - l + 1]; }; auto lcp = [&](int a, int b) { int l = 0, r = n - b; while (l < r) { int mid = l + r >> 1; if (get(a + 1, a + 1 + mid) == get(b + 1, b + 1 + mid)) { l = mid + 1; } else { r = mid; } } return r; }; std::vector<int> vis(n); for (int p = n / 4 + 1; p <= n / 2; ++p) { int cost = 0; for (int i = p; i < n && cost <= k; ++i) { i += lcp(i - p, i); if (i == n) break; int x = i % p; if (vis[x] != p) { vis[x] = p; std::vector<int> cnt(26); int res = 0, tot = 0; for (int j = x; j < n; j += p) { tot += 1; res = std::max(res, ++cnt[s[j] - 'a']); } cost += tot - res; } } if (cost <= k) { std::cout << "Yes" << '\n'; return ; } } std::cout << "No" << '\n'; } (); }
#include<bits/stdc++.h> usingnamespace std; intmain(){ ios::sync_with_stdio(false); cin.tie(nullptr); #define int long long int n, m; cin >> n >> m; vector<int> a(m); for (int i = 0; i < m; ++i) { cin >> a[i]; } auto power = [&](int x) { return x * x * x * x; }; vector<int> dp(m + 1, 0); for (int i = 1; i <= m; ++i) { dp[i] = 2e18; for (int j = max<int>(0, i - 400); j < i; ++j) { dp[i] = min<int>(dp[i] , dp[j] + a[i - 1] + power(i - j)); } } cout << dp[m] << '\n'; }
#include<bits/stdc++.h> intmain(){ std::cin.tie(nullptr)->sync_with_stdio(false); #define int long long int tt; for (std::cin >> tt; tt--;) { int n; std::cin >> n; std::vector<int> a(n), b(n); for (int i = 0; i < n; ++i) { std::cin >> a[i]; } for (int i = 0; i < n; ++i) { std::cin >> b[i]; } auto check = [&](int k) { int x = k * b[0]; int L = a[0] - x, R = a[0] + x; for (int i = 1; i < n; ++i) { x = k * b[i]; int l = a[i] - x, r = a[i] + x; if (r < L || l > R) { returnfalse; } else { L = std::max(L, l); R = std::min(R, r); } } returntrue; }; int l = 0 , r = 1e9; while(l < r) { int mid = l + r >> 1; if (check(mid)) { r = mid; } else { l = mid + 1; } } std::cout << r << '\n'; } }