Skip to content

Commit 6d861df

Browse files
committed
.
1 parent 1920b45 commit 6d861df

7 files changed

+417
-67
lines changed
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\\Practice\\temp.cpp","tests":[{"id":1618670693466,"input":"3\n2\n2 3\n2\n5 1\n1\n2","output":"Case #1: ABDCBA\nCase #2: ABCDEFA\nCase #3: ABC"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\Dhruv\\myGithub\\Competitive-Programming\\Practice\\temp.cpp","group":"local","local":true}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"Local: temp2","url":"c:\\Users\\Dhruv\\myGithub\\Competitive-Programming\\Practice\\temp2.cpp","tests":[{"id":1618733957371,"input":"3\n4\n10 20 10 25\n5\n7 7 7 7 7\n2\n100 1\n","output":"Case #1: 7\nCase #2: 5\nCase #3: 3\n"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\Dhruv\\myGithub\\Competitive-Programming\\Practice\\temp2.cpp","group":"local","local":true}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"Local: temp4","url":"c:\\Users\\Dhruv\\myGithub\\Competitive-Programming\\Practice\\temp4.cpp","tests":[{"id":1618672091906,"input":"5\nIOIOOOII\nOIIIIO\nIO\nIOIOIOI\nIOIOIOOIO","output":"Case #1: I 8\nCase #2: O 7\nCase #3: O 1\nCase #4: I 1\nCase #5: O 6"},{"id":1618673389450,"input":"1\nIIIIO","output":""}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\Dhruv\\myGithub\\Competitive-Programming\\Practice\\temp4.cpp","group":"local","local":true}

Practice/temp.cpp

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
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+
void solve()
91+
{
92+
int n;
93+
cin >> n;
94+
v(int) A(n);
95+
for (int i = 0; i < n; i++)
96+
cin >> A[i];
97+
v(string) Ans(n);
98+
99+
for (int i = 0; i < n; i++)
100+
{
101+
char ch = (i % 2 == 1) ? 'A' : 'B';
102+
for (int j = 0; j < A[i]; j++, ch++)
103+
Ans[i] += ch;
104+
105+
if (i % 2 == 1)
106+
{
107+
reverse(Ans[i].begin(), Ans[i].end());
108+
if (Ans[i][0] >= Ans[i - 1][A[i - 1] - 1])
109+
Ans[i - 1][A[i - 1] - 1] = Ans[i][0] + 1;
110+
}
111+
}
112+
cout << 'A';
113+
for (int i = 0; i < n; i++)
114+
cout << Ans[i];
115+
cout << endl;
116+
}
117+
//------------------------------------------------------------------------------
118+
int32_t main()
119+
{
120+
FastIO;
121+
int test = 1;
122+
w(T)
123+
{
124+
cout << "Case #" << test++ << ": ";
125+
solve();
126+
}
127+
return 0;
128+
}
129+
//------------------------------------------------------------------------------

Practice/temp2.cpp

Lines changed: 110 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,121 @@
1-
#include <bits/stdc++.h>
2-
using namespace std;
31

4-
class Solution
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
528
{
629
public:
7-
string fractionToDecimal(long long int numerator, long long int denominator)
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)
838
{
39+
return a * (b / gcd(a, b));
40+
}
941

10-
if (numerator == 0)
11-
{
12-
return "0";
13-
}
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;
1453

15-
bool isPointIntroduced = false;
16-
string s = "";
17-
unordered_map<long long int, long long int> mp;
18-
bool numNeg = (numerator < 0);
19-
bool denNeg = (denominator < 0);
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+
}
2065

21-
numerator = abs(numerator);
22-
denominator = abs(denominator);
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+
}
2374

24-
while (1)
25-
{
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+
}
2687

27-
if (numerator < denominator)
28-
{
29-
if (isPointIntroduced)
30-
{
31-
numerator *= 10;
32-
s += '0';
33-
}
34-
else
35-
{
36-
if (s.size() == 0)
37-
{
38-
s += '0';
39-
}
40-
s += '.';
41-
numerator *= 10;
42-
isPointIntroduced = true;
43-
}
44-
}
45-
else
46-
{
88+
} Math;
89+
//------------------------------------------------------------------------------
90+
void solve()
91+
{
92+
int n;
93+
cin >> n;
94+
v(int) A(n);
95+
for (int i = 0; i < n; i++)
96+
cin >> A[i];
4797

48-
if (numerator % denominator == 0)
49-
{
50-
s += to_string(numerator / denominator);
51-
if (numNeg ^ denNeg)
52-
{
53-
s = '-' + s;
54-
}
55-
return s;
56-
}
57-
else if (mp.count(numerator) > 0)
58-
{
59-
s.insert(mp[numerator], "(");
60-
s += ')';
61-
if (numNeg ^ denNeg)
62-
{
63-
s = '-' + s;
64-
}
65-
return s;
66-
}
67-
else
68-
{
69-
mp[numerator] = s.length();
70-
s += to_string(numerator / denominator);
71-
numerator %= denominator;
72-
if (isPointIntroduced)
73-
numerator *= 10;
74-
}
75-
}
76-
}
98+
sort(A.begin(), A.end());
99+
int cur = 1;
100+
int ans = 1;
101+
for (int i = 1; i < n; i++)
102+
{
103+
if (A[i] != A[i - 1])
104+
cur++;
105+
ans += cur;
106+
}
107+
cout << ans << endl;
108+
}
109+
//------------------------------------------------------------------------------
110+
int32_t main()
111+
{
112+
FastIO;
113+
int test = 1;
114+
w(T)
115+
{
116+
cout << "Case #" << test++ << ": ";
117+
solve();
77118
}
78-
};
119+
return 0;
120+
}
121+
//------------------------------------------------------------------------------

0 commit comments

Comments
 (0)