From 92e68722bf255efc7b7a17d32ab7590de8e2bac9 Mon Sep 17 00:00:00 2001 From: ShazidMahsrafi Date: Sat, 4 May 2024 14:12:10 +0600 Subject: [PATCH] feat: Add solutions for Codeforces problems 1968C and 1968D --- .../1968C.cpp | 33 +++++++++++ Codes/1968 D - Permutation Game/1968D.cpp | 57 +++++++++++++++++++ Readme.md | 6 +- 3 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 Codes/1968 C - Assembly via Remainders/1968C.cpp create mode 100644 Codes/1968 D - Permutation Game/1968D.cpp diff --git a/Codes/1968 C - Assembly via Remainders/1968C.cpp b/Codes/1968 C - Assembly via Remainders/1968C.cpp new file mode 100644 index 0000000..9f6bf38 --- /dev/null +++ b/Codes/1968 C - Assembly via Remainders/1968C.cpp @@ -0,0 +1,33 @@ +#include +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; + vectorv(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<> TCS; + for (int TC = 1; TC <= TCS; ++TC) + { + // cout<<"Case "< +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&p, vector&a, vector&path, ll pos) +{ + vectorvis(p.size()); + while(!vis[pos - 1]) + { + vis[pos - 1] = 1; + path.push_back(a[pos - 1]); + pos = p[pos - 1]; + } +} + +ll score(vector&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; + vectorp(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 "<