Skip to content

Commit

Permalink
Merge pull request #358 from SanyamAgrawal07/main
Browse files Browse the repository at this point in the history
Added Google Kickstart Solutions
  • Loading branch information
tanus786 authored Oct 21, 2022
2 parents 4cd38e0 + d3b3e10 commit 0229c40
Show file tree
Hide file tree
Showing 5 changed files with 374 additions and 0 deletions.
59 changes: 59 additions & 0 deletions Google KickStart 2022/Round F/sort_the_fabrics.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;
#define pb push_back
#define ppb pop_back
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define mod 1000000007
#define mod1 998244353

bool cmp1(pair<string,int> a,pair<string,int> b){
if(a.ff!=b.ff) return a.ff<b.ff;
return a.ss<b.ss;
}

bool cmp2(pair<int,int> a,pair<int,int> b){
if(a.ff!=b.ff) return a.ff<b.ff;
return a.ss<b.ss;
}

void solve(int test){
int n;
cin>>n;
vector <pair<string,int>> c(n);
vector <pair<int,int>> d(n);
for(int i=0 ; i<n ; i++){
cin>>c[i].ff>>d[i].ff>>c[i].ss;
d[i].ss=c[i].ss;
}
sort(all(c),cmp1);
sort(all(d),cmp2);
int ct=0;
for(int i=0 ; i<n ; i++){
if(c[i].ss==d[i].ss) ct++;
}
cout<<"Case #"<<test<<": ";
cout<<ct<<"\n";
}

int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

int t;
cin>>t;
int test=1;
while(t--){
solve(test);
test++;
}
return 0;
}
102 changes: 102 additions & 0 deletions Google KickStart 2022/Round F/story_of_seasons.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;
#define pb push_back
#define ppb pop_back
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define mod 1000000007
#define mod1 998244353

/* ****** THIS CODE PASSES ONLY THE FIRST TWO TESTS NOT THE FINAL ONE ****** */

ll x;
set <ll> s;

ll Lower_Bound2(ll d){
auto it=s.lower_bound(d);
if(it==s.end()) return -1;
return (*it);
}

vll l(1e5+5);

bool cmp(pair<ll,ll> a,pair<ll,ll> b){
if(a.ff!=b.ff) return a.ff>b.ff;
return l[a.ss]<l[b.ss];
}

void solve(int test){
ll d,n;
cin>>d>>n>>x;
vll q(n);
vector <pair<ll,ll>> v(n);
for(int i=0 ; i<n ; i++){
cin>>q[i]>>l[i]>>v[i].ff;
v[i].ss=i;
}
sort(all(v),cmp);
int cur=0;
vector <pair<ll,ll>> fin(d);

for(int i=0 ; i<d ; i++){
fin[i].ff=0;
fin[i].ss=0;
if(i!=0)
s.insert(i);
}
while(cur!=n){
ll ind=Lower_Bound2(l[v[cur].ss]);

if(ind==-1){
cur++;
continue;
}
ll avail=x-fin[ind].ss;
if(q[v[cur].ss]<=avail){
fin[ind].ss+=q[v[cur].ss];
if(fin[ind].ss==x){
auto temp=s.find(ind);
s.erase(temp);
}
fin[ind].ff+=(q[v[cur].ss]*v[cur].ff);
q[v[cur].ss]=0;
cur++;
}
else{
fin[ind].ss+=avail;
auto temp=s.find(ind);
s.erase(temp);
q[v[cur].ss]-=avail;
fin[ind].ff+=(avail*v[cur].ff);
}
}
ll ans=0;
for(int i=0 ; i<d ; i++){
ans+=fin[i].ff;
}
cout<<"Case #"<<test<<": ";
cout<<ans<<"\n";
s.clear();
}

int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

int t;
cin>>t;
int test=1;
while(t--){
solve(test);
test++;
}
return 0;
}
81 changes: 81 additions & 0 deletions Google KickStart 2022/Round F/water_container_system.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;
#define pb push_back
#define ppb pop_back
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define mod 1000000007
#define mod1 998244353

const int N=1e5+7;
vi graph[N];
vi depth(N);
vb vis(N);

void dfs(int vertex,int d){
vis[vertex]=true;
depth[vertex]=d;

for(int child : graph[vertex]){
if(vis[child]==false){
dfs(child,d+1);
}
}
}

void solve(int test){
int n,q;
cin>>n>>q;
for(int i=0 ; i<n-1 ; i++){
int a,b;
cin>>a>>b;
graph[a].pb(b);
graph[b].pb(a);
}
dfs(1,0);
vi dep(n,0);
for(int i=1 ; i<=n ; i++){
dep[depth[i]]++;
}
int level=0;
int cur=0;
int ans=0;
for(int i=0 ; i<q ; i++){
int a;
cin>>a;
cur++;
if(cur==dep[level]){
level++;
ans+=cur;
cur=0;
}
}
cout<<"Case #"<<test<<": ";
cout<<ans<<"\n";
for(int i=0 ; i<=n ; i++){
graph[i].clear();
vis[i]=false;
}
}

int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

int t;
cin>>t;
int test=1;
while(t--){
solve(test);
test++;
}
return 0;
}
73 changes: 73 additions & 0 deletions Google KickStart 2022/Round G/curling.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;
#define pb push_back
#define ppb pop_back
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define mod 1000000007
#define mod1 998244353

void solve(int test){
ll rs,rh;
cin>>rs>>rh;
int n;
cin>>n;
ll mdist=rs+rh;
vector <pair<ll,int>> v;
for(int i=0 ; i<n ; i++){
ll x,y;
cin>>x>>y;
ll dis=(((x)*(x))+((y)*(y)));
if(dis<=((mdist)*(mdist))) v.pb({dis,1});
}
int m;
cin>>m;
for(int i=0 ; i<m ; i++){
ll x,y;
cin>>x>>y;
ll dis=(((x)*(x))+((y)*(y)));
if(dis<=((mdist)*(mdist))) v.pb({dis,2});
}
cout<<"Case #"<<test<<": ";
if(v.size()==0){
cout<<"0 0\n";
return;
}
sort(all(v));
int ans=0;
int ini=v[0].ss;
for(int i=0 ; i<v.size() ; i++){
if(v[i].ss==ini){
ans++;
}
else break;
}
if(ini==1){
cout<<ans<<" "<<"0\n";
}
else{
cout<<"0 "<<ans<<"\n";
}
}

int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

int t;
cin>>t;
int test=1;
while(t--){
solve(test);
test++;
}
return 0;
}
59 changes: 59 additions & 0 deletions Google KickStart 2022/Round G/walktober.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;
#define pb push_back
#define ppb pop_back
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define mod 1000000007
#define mod1 998244353

void solve(int test){
int m,n,p;
cin>>m>>n>>p;
p--;
vi v(n,0);
vi john(n);
for(int i=0 ; i<m ; i++){
if(i==p){
for(int j=0 ; j<n ; j++){

cin>>john[j];

}
continue;
}
for(int j=0 ; j<n ; j++){
int temp;
cin>>temp;
v[j]=max(v[j],temp);
}
}
ll ans=0;
for(int i=0 ; i<n ; i++){
ans+=max(0,v[i]-john[i]);
}
cout<<"Case #"<<test<<": ";
cout<<ans<<"\n";
}

int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

int t;
cin>>t;
int test=1;
while(t--){
solve(test);
test++;
}
return 0;
}

0 comments on commit 0229c40

Please sign in to comment.