Do you have starting 2-3 Questions (not asking for solution )of mockvita 2 , actually I need them because last night when I log in using my id, i go through first question and left the contest(problems spoiled my mood xD), now one of my professor is asking for solution of 2nd and 3rd problem, can you please provide the ss of 2nd and 3rd problem.
Bro ham to uth gye in cheezo se upar ab , I m 2020 batch not eligible for TCS codevita 2020
hahahaha…great to see that you still are doing CP
CP is fun , it is journey
and aadmi fr pura din kya kre 
I can’t help but image how in the world the website is designed so badly. Now I am no experienced web developer but it seems like there are memory leaks everywhere. Forget the shitty backend, the front end alone makes me want to puke. Now coming to the servers, has TCS gone bankrupt that they can’t afford decent servers?
Warnings in program are shown as compilation errors, questions are worded poorly, input format is stupid, brute force solution passes many questions. People told me TCS pays less but you will get good exposure and you can get good experience. I seriously doubt this. My disappointment is immeasurable and my day is ruined.
And then there are some reputed coders complaining that even after solving five-six questions they couldn’t qualify but their batchmate solved one and they qualified. What a complete brainfuck this competition is.
Don’t try to login for 15 min and then you will be able to login after 15 mins.
Still same error bro. SED LYFE.
Nope , If it this happens then surely they are in plag , otherwise no case of this type .
That is why I mentioned “reputed”, I can take their word not because of their rating but because I know they would never cheat. By looking at a shitty website like CodeVita it isn’t difficult to deduce the plagiarism detection mechanism would be shitty as well.
Anyone who solved D ?
Mahn, I really dont know what to say. I hope the actual codevita goes well.
You have to divide the array in 2 subsets such that their difference is minimum. You can either use DP or Recursion, the constraints were small enough to use recursion. You can read more about it here: Subset Sum - gfg . You have to output the maximum of both sums while keeping the difference minimum. In the above link you can make a minor change in return statement and you will get your answer.
𝐆𝐞𝐭 𝐭𝐡𝐞 𝐟𝐮𝐥𝐥 𝐪𝐮𝐞𝐬𝐭𝐢𝐨𝐧 𝐝𝐞𝐬𝐜𝐫𝐢𝐩𝐭𝐢𝐨𝐧 of 𝐦𝐨𝐜𝐤𝐕𝐢𝐭𝐚 𝟐 𝟐𝟎𝟐𝟎 𝐡𝐞𝐫𝐞:
Swayamvar: Swayamvar | TCS MockVita 2 2020 | By CodingHumans
Death Battle: Death Battle | TCS MockVIta 2 2020 | By CodingHumans |
Grooving Monkey: Grooving Monkeys | TCS MockVIta 2 2020 | By CodingHumans |
Petrol Pump: Petrol Pump |TCS MockVIta 2 2020 | By CodingHumans |
Dole CAdbury: Dole Out Cadbury | TCS MockVIta 2 2020 | By CodingHumans |
DIgit Pairs: Digit Pairs | TCS MockVIta 2 2020 | By CodingHumans |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define lld long long int
lld gcd(lld a, lld b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
int main() {
// your code goes here
ios_base::sync_with_stdio(false);
cin.tie(NULL);
lld t;
cin>>t;
//t=1;
while(t--)
{
int n;
cin>>n;
int arr[n+1];
for(int i=1;i<=n;i++)
cin>>arr[i];
set <lld> v;
for(int i=1;i<=n;i++)
{
int val=arr[i],cnt=1,j=i;
while(val!=i)
{
val=arr[arr[j]];
cnt++;
j=arr[j];
}
v.insert(cnt);
}
lld ans=*v.begin();
for(auto it=v.begin();it!=v.end();it++)
{
lld as=*it;
ans = (((as * ans)) / (gcd(as, ans)));
}
cout<<ans<<"\n";
}
}
This gave me TLE. Any reason. (Question E)
I guess because of this while loop.You can simply use Disjoint Set Union, instead of finding “cnt” for each element.
In worst case it will be O(n^2). So, this should be accepted
Test Cases 1 <= t <= 10 and 1 <= n <= 1e4. O(t * n * n) will be a TLE then.
A. Swayamwar
#include<bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
string s1, s2; cin >> s1 >> s2;
int m=0, r=0;
for(char c:s2) {
if(c == 'm') m++;
else r++;
}
for(char c:s1) {
if(c == 'm') {
if(m) m--;
else break;
} else {
if(r) r--;
else break;
}
}
cout << m+r;
return 0;
}
B. Digit Pairs
#include<bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
int temp, small, large, num;
unordered_map<int, int> odd, even;
for(int i=0; i<n; i++) {
cin >> temp;
small=10, large=0;
while(temp > 0) {
small = min(small, temp%10);
large = max(large, temp%10);
temp /= 10;
}
num = large*11 + small*7;
if(num > 99) num = num%100;
num /= 10;
if(i & 1) odd[num]++;
else even[num]++;
}
int ans = 0;
int pairs[10] = {0};
for(auto x:odd) pairs[x.first] += min(x.second-1, 2);
for(auto x:even) pairs[x.first] += min(x.second-1, 2);
for(int x:pairs) ans += min(2, x);
cout << ans;
return 0;
}
C. Dole Out Cadbury
#include<bits/stdc++.h>
using namespace std;
int main() {
int p,q,r,s; cin>>p>>q>>r>>s;
int ans = 0;
for(int i=p; i<=q; i++) {
for(int j=r; j<=s; j++) {
int a = max(i, j), b = min(i, j);
while(a>0 && b>0) {
swap(a, b);
int x = b / a;
ans += x;
b -= a*x;
}
}
}
cout << ans;
return 0;
}
D. Petrol Pump
#include<bits/stdc++.h>
using namespace std;
int subset(vector<int> &arr, int s) {
int n = arr.size();
bool dp[n+1][s+1];
for(int i=0; i<=s; i++) dp[0][i] = false;
for(int i=0; i<=n; i++) dp[i][0] = true;
for(int i=1; i<=n; i++) {
for(int j=1; j<=s; j++) {
dp[i][j] = dp[i-1][j];
if(arr[i-1] <= j) dp[i][j] = dp[i][j] || dp[i-1][j-arr[i-1]];
}
}
int i=s;
for(; i>=0; i--) {
if(dp[n][i]) break;
}
return i;
}
int main() {
vector<int> arr;
int sum=0;
string inp, t;
getline(cin, inp);
stringstream ss(inp);
while(ss >> t) {
int n = stoi(t);
arr.push_back(n);
sum += n;
}
int ans = subset(arr, sum/2);
cout << max(ans, sum-ans);
return 0;
}
E. Grooving Monkeys
#include<bits/stdc++.h>
#define int long long
using namespace std;
int Find(int i, int *Parent) {
if(Parent[i] != i) Parent[i] = Find(Parent[i], Parent);
return Parent[i];
}
void Union(int i, int temp, int *Rank, int *Parent) {
int x = Find(i, Parent);
int y = Find(temp, Parent);
if(Rank[x] < Rank[y]) Parent[x] = Parent[y];
else if(Rank[x] > Rank[y]) Parent[y] = Parent[x];
else {
Parent[y] = Parent[x];
Rank[x]++;
}
}
signed main() {
int t; cin >> t;
while(t--) {
int n; cin >> n;
int temp;
int Rank[n], Parent[n];
for(int i=0; i<n; i++) Rank[i] = 0;
for(int i=0; i<n; i++) Parent[i] = i;
for(int i=1; i<=n; i++) {
cin >> temp;
Union(i-1, temp-1, Rank, Parent);
}
for(int i=0; i<n; i++) Find(i, Parent);
unordered_map<int, int> freq;
for(int p:Parent) freq[p]++;
unordered_set<int> s;
for(auto x:freq) s.insert(x.second);
vector<int> v;
for(int x:s) v.push_back(x);
int l=v[0];
for(int i=1; i<(int)v.size(); i++) {
l = (v[i]*l) / (__gcd(v[i], l));
}
cout << l << endl;
}
return 0;
}
F. Death Battle
#include<bits/stdc++.h>
#define int long long
using namespace std;
int ncr[105][105];
void fill_ncr() {
for(int n=1; n<105; n++) {ncr[n][1] = n; ncr[n][0] = 1;}
for(int n=2; n<105; n++) {
for(int r=2; r<105; r++) {
ncr[n][r] = ncr[n-1][r-1] + ncr[n-1][r];
}
}
}
int pow(int x, int n) {
int res = 1;
while(n > 0) {
if(n&1) {res = res*x; n--;}
x=x*x; n=n/2;
}
return res;
}
void add(int &n1, int &d1, int n2, int d2) {
n1 = (d2*n1 + d1*n2);
d1 = (d1 * d2);
int g = __gcd(n1, d1);
n1 /= g; d1 /= g;
}
void mul(int &n1, int &d1, int n2, int d2) {
n1 = (n1 * n2);
d1 = (d1 * d2);
int g = __gcd(n1, d1);
n1 /= g; d1 /= g;
}
signed main() {
fill_ncr();
int t; cin >> t;
while(t--) {
int a,h,l1,l2,m,c; cin>>a>>h>>l1>>l2>>m>>c;
int numerator = h - m*a;
if(numerator <= 0) {cout<<"1/1\n"; continue;}
if(numerator > m*c) {cout<<"RIP\n"; continue;}
int p = ceil((float)numerator / c);
int an=0, ad=1;
for(; p<=m; p++) {
int mn=1, md=1;
mul(mn, md, ncr[m][p]*pow(l1, p), pow(l2, p));
mul(mn, md, pow((l2-l1), (m-p)), pow(l2, (m-p)));
add(an, ad, mn, md);
}
cout << an << "/" << ad << endl;
}
return 0;
}
But 1e9 can be done in 1 sec I guess?