Skip to content

Commit 09cfc8f

Browse files
committed
.
1 parent e6c9eb4 commit 09cfc8f

8 files changed

+318
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"Append Sort","group":"Google Coding Competitions - Round 1A 2021 - Code Jam 2021","url":"https://codingcompetitions.withgoogle.com/codejam/round/000000000043585d/00000000007549e5","interactive":false,"memoryLimit":1024,"timeLimit":10000,"tests":[{"id":1618016676088,"input":"4\n3\n199929 19 12\n2\n10 10\n3\n4 19 1\n3\n1 2 3","output":"Case #1: 4\nCase #2: 1\nCase #3: 2\nCase #4: 0"},{"id":1618020271610,"input":"1\n2\n1991 19","output":""}],"testType":"multiNumber","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Solution","taskClass":"AppendSort"}},"batch":{"id":"f9ccb874-78e2-4dd3-8743-1658aa531465","size":1},"srcPath":"c:\\Users\\Dhruv\\myGithub\\Competitive-Programming\\Google\\CodeJam Round 1A 2021\\Append_Sort.cpp"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"Hacked Exam","group":"Google Coding Competitions - Round 1A 2021 - Code Jam 2021","url":"https://codingcompetitions.withgoogle.com/codejam/round/000000000043585d/0000000000754750","interactive":false,"memoryLimit":1024,"timeLimit":30000,"tests":[{"id":1618023666007,"input":"4\n1 3\nFFT 3\n1 3\nFFT 2\n2 6\nFFTTTF 2\nFTFTFT 4\n2 2\nFF 1\nTT 1","output":"Case #1: FFT 3/1\nCase #2: FFT 2/1\nCase #3: FTFTFT 4/1\nCase #4: TT 1/1"},{"input":"1\n3 120\nFFTFFFTFFFTTTTTTTFTFFFFFFTTTFTFFFTFTFFTTFTFFTFFTTTFTFTFFTFTFTTFFFFTFTFFFFTTTFTTFTTTTFFFTTFFFFFTTFFTFFTFFTTTFFFFTTFFTFTTF 55\nFFFTFFTTFFFFTFTFFTFFFTTTTTTFFFTTTFTTTTFFTFTTTFTTFFTTTFTFFFFTFFTTFFTTFTTFFTFTFFTFTTFTFTFFTTTFFTFTFTTFFTFTFTFTTFFTFFFTFTFT 62\nFFFTFTTFFFFFTFTFTTTTTTFFTTFTFFFTFFTTTTTTFFFTTTFFFTTFTFFFFFFTFTTFFTFTTTFTTTTFTTFFFFTFFTTFTFFTTTTTTFTFFFFFTTFFTFTFTFFTTTTT 64\n","output":"Case #1: FFFTFTTTFFFFTFTFFTFTTTTTTTFFFFTTTFTTTTFFTFTTTTTFFFTFTFTFFFFTFFTTFTFTFTTTTTFFTFFFFFFFFTTFTTTTTTFTTTTFFFFTFTFTTFTFFFFTTTFT 189154508532118369075350624633/2901503505434414233388602018\n","id":1618023665972}],"testType":"multiNumber","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Solution","taskClass":"HackedExam"}},"batch":{"id":"b8c9bbb2-d699-4646-b99d-cb92eb61e96a","size":1},"srcPath":"c:\\Users\\Dhruv\\myGithub\\Competitive-Programming\\Google\\CodeJam Round 1A 2021\\Hacked_Exam.cpp"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"Prime Time","group":"Google Coding Competitions - Round 1A 2021 - Code Jam 2021","url":"https://codingcompetitions.withgoogle.com/codejam/round/000000000043585d/00000000007543d8","interactive":false,"memoryLimit":1024,"timeLimit":45000,"tests":[{"id":1618020862770,"input":"4\n5\n2 2\n3 1\n5 2\n7 1\n11 1\n1\n17 2\n2\n2 2\n3 1\n1\n2 7","output":"Case #1: 25\nCase #2: 17\nCase #3: 0\nCase #4: 8"}],"testType":"multiNumber","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Solution","taskClass":"PrimeTime"}},"batch":{"id":"62d3d3a2-2b77-4eeb-8441-5cafb65c788b","size":1},"srcPath":"c:\\Users\\Dhruv\\myGithub\\Competitive-Programming\\Google\\CodeJam Round 1A 2021\\Prime_Time.cpp"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"Local: temp","url":"c:\\Users\\Dhruv\\myGithub\\Competitive-Programming\\Google\\CodeJam Round 1A 2021\\temp.cpp","tests":[{"id":1618027838598,"input":"","output":""}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\Dhruv\\myGithub\\Competitive-Programming\\Google\\CodeJam Round 1A 2021\\temp.cpp","group":"local","local":true}
68.8 KB
Binary file not shown.
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
2+
//------------------------------------------------------------------------------
3+
#include <iostream>
4+
#include <vector>
5+
// #include <bits/stdc++.h>
6+
// #include <cmath>
7+
// #include <algorithm>
8+
// #include <unordered_map>
9+
// #include <map>
10+
// #include <set>
11+
// #include <unordered_set>
12+
//------------------------------------------------------------------------------
13+
using namespace std;
14+
//------------------------------------------------------------------------------
15+
#define FastIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
16+
#define v(Type) vector<Type>
17+
#define w(T) \
18+
int T; \
19+
cin >> T; \
20+
while (T--)
21+
#define int long long int
22+
#define mod 1000000007ll
23+
#define endl "\n"
24+
//------------------------------------------------------------------------------
25+
// Any fucntion can be called using Math.function_name();
26+
//------------------------------------------------------------------------------
27+
class Math
28+
{
29+
public:
30+
//Returns gcd of two numbers
31+
int gcd(int a, int b)
32+
{
33+
return (a % b == 0) ? b : gcd(b, a % b);
34+
}
35+
36+
//Returns lcm of two numbers
37+
int lcm(int a, int b)
38+
{
39+
return a * (b / gcd(a, b));
40+
}
41+
42+
// Returns flag array isPrime
43+
// isPrime[i] = true (if i is Prime)
44+
// isPrime[i] = false (if i is not Prime)
45+
vector<bool> *seiveOfEratosthenes(const int N)
46+
{
47+
vector<bool> *isPrime = new vector<bool>(N + 1, true);
48+
(*isPrime)[0] = (*isPrime)[1] = false;
49+
for (int i = 2; i * i <= N; ++i)
50+
if ((*isPrime)[i])
51+
for (int j = i * i; j <= N; j += i)
52+
(*isPrime)[j] = false;
53+
54+
return isPrime;
55+
}
56+
57+
//Returns (x ^ n)
58+
int pow(const int &x, int n)
59+
{
60+
if (n == 0)
61+
return 1;
62+
int h = pow(x, n / 2);
63+
return (n & 1) ? h * h * x : h * h;
64+
}
65+
66+
//Returns (x ^ n) % M
67+
int pow(const int &x, int n, const int &M)
68+
{
69+
if (n == 0)
70+
return 1;
71+
int h = pow(x, n / 2) % M;
72+
return (n & 1) ? (h * h * x) % M : (h * h) % M;
73+
}
74+
75+
//Returns all Primes <= N
76+
vector<int> *primesUptoN(const int N)
77+
{
78+
vector<bool> *isPrime = seiveOfEratosthenes(N);
79+
vector<int> *Primes = new vector<int>;
80+
if (2 <= N)
81+
(*Primes).push_back(2);
82+
for (int i = 3; i <= N; i += 2)
83+
if ((*isPrime)[i])
84+
(*Primes).push_back(i);
85+
return Primes;
86+
}
87+
88+
} Math;
89+
//------------------------------------------------------------------------------
90+
91+
int f(string &cur, string &prev)
92+
{
93+
for (int i = 0; i < cur.length(); i++)
94+
{
95+
if (cur[i] < prev[i])
96+
{
97+
int ans = 0;
98+
while (cur.length() <= prev.length())
99+
cur += '0', ans++;
100+
return ans;
101+
}
102+
else if (cur[i] > prev[i])
103+
{
104+
int ans = 0;
105+
while (cur.length() < prev.length())
106+
cur += '0', ans++;
107+
return ans;
108+
}
109+
}
110+
111+
for (int j = prev.length() - 1; j >= cur.length(); j--)
112+
if (prev[j] != '9')
113+
{
114+
int i = cur.length();
115+
int ans = 0;
116+
while (i < j)
117+
{
118+
cur += prev[i];
119+
i++;
120+
ans++;
121+
}
122+
cur.push_back(prev[i] + 1);
123+
i++;
124+
ans++;
125+
while (i < prev.length())
126+
{
127+
cur += '0';
128+
i++;
129+
ans++;
130+
}
131+
return ans;
132+
}
133+
int ans = 0;
134+
while (cur.length() <= prev.length())
135+
cur += '0', ans++;
136+
return ans;
137+
}
138+
void solve()
139+
{
140+
int n;
141+
cin >> n;
142+
v(string) A(n);
143+
for (int i = 0; i < n; i++)
144+
cin >> A[i];
145+
int ans = 0;
146+
147+
for (int i = 1; i < n; i++)
148+
{
149+
150+
if (A[i].length() > A[i - 1].length())
151+
continue;
152+
else if (A[i].length() == A[i - 1].length() and stoll(A[i - 1]) < stoll(A[i]))
153+
continue;
154+
155+
else
156+
ans += f(A[i], A[i - 1]);
157+
}
158+
cout << ans << endl;
159+
}
160+
//------------------------------------------------------------------------------
161+
int32_t main()
162+
{
163+
FastIO;
164+
int test = 1;
165+
w(T)
166+
{
167+
cout << "Case #" << test++ << ": ";
168+
solve();
169+
}
170+
return 0;
171+
}
172+
//------------------------------------------------------------------------------
162 KB
Binary file not shown.
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
2+
//------------------------------------------------------------------------------
3+
#include <iostream>
4+
#include <vector>
5+
// #include <bits/stdc++.h>
6+
// #include <cmath>
7+
// #include <algorithm>
8+
// #include <unordered_map>
9+
#include <map>
10+
// #include <set>
11+
// #include <unordered_set>
12+
//------------------------------------------------------------------------------
13+
using namespace std;
14+
//------------------------------------------------------------------------------
15+
#define FastIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
16+
#define v(Type) vector<Type>
17+
#define w(T) \
18+
int T; \
19+
cin >> T; \
20+
while (T--)
21+
#define int long long int
22+
#define mod 1000000007ll
23+
#define endl "\n"
24+
//------------------------------------------------------------------------------
25+
// Any fucntion can be called using Math.function_name();
26+
//------------------------------------------------------------------------------
27+
class Math
28+
{
29+
public:
30+
//Returns gcd of two numbers
31+
int gcd(int a, int b)
32+
{
33+
return (a % b == 0) ? b : gcd(b, a % b);
34+
}
35+
36+
//Returns lcm of two numbers
37+
int lcm(int a, int b)
38+
{
39+
return a * (b / gcd(a, b));
40+
}
41+
42+
// Returns flag array isPrime
43+
// isPrime[i] = true (if i is Prime)
44+
// isPrime[i] = false (if i is not Prime)
45+
vector<bool> *seiveOfEratosthenes(const int N)
46+
{
47+
vector<bool> *isPrime = new vector<bool>(N + 1, true);
48+
(*isPrime)[0] = (*isPrime)[1] = false;
49+
for (int i = 2; i * i <= N; ++i)
50+
if ((*isPrime)[i])
51+
for (int j = i * i; j <= N; j += i)
52+
(*isPrime)[j] = false;
53+
54+
return isPrime;
55+
}
56+
57+
//Returns (x ^ n)
58+
int pow(const int &x, int n)
59+
{
60+
if (n == 0)
61+
return 1;
62+
int h = pow(x, n / 2);
63+
return (n & 1) ? h * h * x : h * h;
64+
}
65+
66+
//Returns (x ^ n) % M
67+
int pow(const int &x, int n, const int &M)
68+
{
69+
if (n == 0)
70+
return 1;
71+
int h = pow(x, n / 2) % M;
72+
return (n & 1) ? (h * h * x) % M : (h * h) % M;
73+
}
74+
75+
//Returns all Primes <= N
76+
vector<int> *primesUptoN(const int N)
77+
{
78+
vector<bool> *isPrime = seiveOfEratosthenes(N);
79+
vector<int> *Primes = new vector<int>;
80+
if (2 <= N)
81+
(*Primes).push_back(2);
82+
for (int i = 3; i <= N; i += 2)
83+
if ((*isPrime)[i])
84+
(*Primes).push_back(i);
85+
return Primes;
86+
}
87+
88+
} Math;
89+
//------------------------------------------------------------------------------
90+
int S = 0;
91+
int solve(v(int) & A, int n, int sum, int p, vector<vector<map<int, int>>> &dp)
92+
{
93+
if (n == 0)
94+
{
95+
if (sum == p)
96+
return sum;
97+
98+
return 0;
99+
}
100+
if (p > S)
101+
return 0;
102+
103+
if ((dp[n][sum]).count(p) != 0)
104+
return dp[n][sum][p];
105+
int ans1 = solve(A, n - 1, sum + A[n - 1], p, dp);
106+
int ans2 = solve(A, n - 1, sum, p * A[n - 1], dp);
107+
108+
return dp[n][sum][p] = max(ans1, ans2);
109+
}
110+
void solve()
111+
{
112+
int n;
113+
cin >> n;
114+
v(int) A;
115+
S = 0;
116+
for (int i = 0; i < n; i++)
117+
{
118+
int p, f;
119+
cin >> p >> f;
120+
while (f--)
121+
{
122+
A.push_back(p);
123+
S += p;
124+
}
125+
}
126+
vector<vector<map<int, int>>> dp(A.size() + 1, vector<map<int, int>>(S + 1));
127+
int ans = solve(A, A.size(), 0, 1, dp);
128+
cout << ans << endl;
129+
}
130+
//------------------------------------------------------------------------------
131+
int32_t main()
132+
{
133+
FastIO;
134+
int test = 1;
135+
w(T)
136+
{
137+
cout << "Case #" << test++ << ": ";
138+
solve();
139+
}
140+
return 0;
141+
}
142+
//------------------------------------------------------------------------------

0 commit comments

Comments
 (0)