feat: Add solutions for Codeforces problems 1968C and 1968D

This commit is contained in:
ShazidMahsrafi 2024-05-04 14:12:10 +06:00
parent 7823c040b7
commit 92e68722bf
3 changed files with 94 additions and 2 deletions

View File

@ -0,0 +1,33 @@
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define sz(x) (int)(x).size()
#define FAST (ios_base::sync_with_stdio(false), cin.tie(nullptr));
ll pow(ll x,ll y,ll m=1e9+7){ll ans=1;x%=m;while(y){if(y&1)ans=(ans*x)%m;x=(x*x)%m;y>>=1;}return ans;}
void solve()
{
ll n;
cin>>n;
vector<ll>v(n-1),ans;
for(auto &i:v) cin>>i;
ans.push_back(v.back());
ans.push_back(1e9);
for(ll i=n-3; i>=0; --i) ans.push_back(ans.back()-v[i]);
reverse(ans.begin(),ans.end());
for(auto x:ans) cout<<x<<" ";
cout<<endl;
}
signed main()
{
FAST;
int TCS = 1;
cin >> TCS;
for (int TC = 1; TC <= TCS; ++TC)
{
// cout<<"Case "<<TC<<": ";
solve();
}
}

View File

@ -0,0 +1,57 @@
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define FAST (ios_base::sync_with_stdio(false), cin.tie(nullptr));
ll pow(ll x,ll y,ll m=1e9+7){ll ans=1;x%=m;while(y){if(y&1)ans=(ans*x)%m;x=(x*x)%m;y>>=1;}return ans;}
void find(vector<ll>&p, vector<ll>&a, vector<ll>&path, ll pos)
{
vector<bool>vis(p.size());
while(!vis[pos - 1])
{
vis[pos - 1] = 1;
path.push_back(a[pos - 1]);
pos = p[pos - 1];
}
}
ll score(vector<ll>&path, ll k)
{
ll sum = 0,mx = 0,cur;
for(ll i = 0; i < path.size(); ++i)
{
if( k < i + 1) break;
cur = sum + path[i] * (k-i);
mx = max(mx,cur);
sum += path[i];
}
return mx;
}
void solve()
{
ll n, k, pb, ps;
cin >> n >> k >> pb >> ps;
vector<ll>p(n), a(n), pathB, pathS;
for (auto &i : p) cin >> i;
for (auto &i : a) cin >> i;
find(p, a, pathB, pb);
find(p, a, pathS, ps);
ll bs = score(pathB,k), ss = score(pathS,k);
if(bs == ss) cout << "Draw" << endl;
else if(bs > ss) cout << "Bodya" << endl;
else cout << "Sasha" << endl;
}
signed main()
{
FAST;
int TCS = 1;
cin >> TCS;
for (int TC = 1; TC <= TCS; ++TC)
{
// cout<<"Case "<<TC<<": ";
solve();
}
}

View File

@ -308,8 +308,10 @@ This repository contains my solutions of Codeforces problems. They are in C++ la
| 296 | 1957 C | How Does the Rook Move | [Question](https://codeforces.com/problemset/problem/1957/C) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1957%20C%20-%20How%20Does%20the%20Rook%20Move)
| 297 | 1968 A | Maximize | [Question](https://codeforces.com/problemset/problem/1968/A) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1968%20A%20-%20Maximize)
| 298 | 1968 B | Prefiquence | [Question](https://codeforces.com/problemset/problem/1968/B) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1968%20B%20-%20Prefiquence)
| 299 | 1969 A | Two Friends | [Question](https://codeforces.com/problemset/problem/1969/A) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1969%20A%20-%20Two%20Friends)
| 300 | 1969 B | Shifts and Sorting | [Question](https://codeforces.com/problemset/problem/1969/B) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1969%20B%20-%20Shifts%20and%20Sorting)
| 299 | 1968 C | Assembly via Remainders | [Question](https://codeforces.com/problemset/problem/1968/C) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1968%20C%20-%20Assembly%20via%20Remainders)
| 300 | 1968 D | Permutation Game | [Question](https://codeforces.com/problemset/problem/1968/D) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1968%20D%20-%20Permutation%20Game)
| 301 | 1969 A | Two Friends | [Question](https://codeforces.com/problemset/problem/1969/A) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1969%20A%20-%20Two%20Friends)
| 302 | 1969 B | Shifts and Sorting | [Question](https://codeforces.com/problemset/problem/1969/B) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1969%20B%20-%20Shifts%20and%20Sorting)