Спасибо за участие! Надеюсь задачи вам понравились.
Идея: Galina_Basalova
Разбор
Tutorial is loading...
Решение(Galina_Basalova)
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
cout << n * 2 << "\n";
}
return 0;
}
2086B - Large Array and Segments
Идея: FelixArg
Разбор
Tutorial is loading...
Решение(FelixArg)
#include<bits/stdc++.h>
using namespace std;
#define int long long
void solve(){
int n, k, x;
cin >> n >> k >> x;
vector<int> a(n);
for (int i = 0; i < n; i++){
cin >> a[i];
}
if (accumulate(a.begin(), a.end(), 0ll) * k < x){
cout << 0 << '\n';
return;
}
int l = 1, r = n * k;
while(l <= r){
int m = l + (r - l) / 2;
int cnt_a = (n * k - m + 1) / n;
int suff = (n * k - m + 1) % n;
int sum = cnt_a * accumulate(a.begin(), a.end(), 0ll);
for (int i = n - suff; i < n; i++){
sum += a[i];
}
if (sum < x){
r = m - 1;
}
else{
l = m + 1;
}
}
cout << r << '\n';
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while(t--){
solve();
}
}
2086C - Disappearing Permutation
Идея: FelixArg
Разбор
Tutorial is loading...
Решение(FelixArg)
#include<bits/stdc++.h>
using namespace std;
#define int long long
void solve(){
int n;
cin >> n;
vector<int> p(n);
for (int i = 0; i < n; i++){
cin >> p[i];
p[i]--;
}
set<int> X;
for (int i = 0; i < n; i++){
int d;
cin >> d;
d--;
while(!X.contains(d)){
X.insert(d);
d = p[d];
}
cout << X.size() << ' ';
}
cout << endl;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while(t--){
solve();
}
}
Идея: FelixArg
Разбор
Tutorial is loading...
Решение(FelixArg)
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 998'244'353;
int bpow(int x, int p){
int res = 1;
while(p){
if (p % 2){
res = (res * x) % MOD;
}
p >>= 1;
x = (x * x) % MOD;
}
return res;
}
int fact(int x){
int res = 1;
for (int i = 1; i <= x; i++){
res = (res * i) % MOD;
}
return res;
}
void solve(){
vector<int> c(26);
for (int i = 0; i < 26; i++){
cin >> c[i];
}
int s = accumulate(c.begin(), c.end(), 0ll);
vector<int> dp(s + 1);
dp[0] = 1;
for (int i = 0; i < 26; i++){
if (c[i] == 0){
continue;
}
for (int j = s; j >= 0; j--){
if (j + c[i] <= s){
dp[j + c[i]] = (dp[j + c[i]] + dp[j]) % MOD;
}
}
}
int ans = dp[s / 2] * fact(s / 2) % MOD * fact((s + 1) / 2) % MOD;
for (int i = 0; i < 26; i++){
ans = (ans * bpow(fact(c[i]), MOD - 2)) % MOD;
}
cout << ans << '\n';
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while(t--){
solve();
}
}
Идея: FelixArg
Разбор
Tutorial is loading...
Идея: Valentin_E
Разбор
Tutorial is loading...



