Skip to content

Commit aead2cf

Browse files
committed
.
1 parent 61a24d5 commit aead2cf

File tree

10 files changed

+213
-13
lines changed

10 files changed

+213
-13
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"name":"Point Grid","group":"CodeChef - March CodeChef Starters 2021 Division 2 (Unrated)","url":"https://www.codechef.com/START2B/problems/PGRID1","interactive":false,"memoryLimit":256,"timeLimit":1000,"tests":[{"input":"3\n3\n1 1 1\n3\n5 3 2\n3\n4 2 5\n","output":"3\n7\n8\n","id":1616936459803}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"PointGrid"}},"batch":{"id":"cb4e8368-1fcf-428e-b4be-63e7a33474d2","size":1},"srcPath":"c:\\Users\\Dhruv\\myGithub\\Competitive-Programming\\CodeChef\\March Starters 2021\\Point_Grid.cpp"}
1+
{"name":"Point Grid","group":"CodeChef - March CodeChef Starters 2021 Division 2 (Unrated)","url":"https://www.codechef.com/START2B/problems/PGRID1","interactive":false,"memoryLimit":256,"timeLimit":1000,"tests":[{"id":1616936459803,"input":"3\n3\n1 1 1\n3\n5 3 2\n3\n4 2 5","output":"3\n7\n8"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"PointGrid"}},"batch":{"id":"cb4e8368-1fcf-428e-b4be-63e7a33474d2","size":1},"srcPath":"c:\\Users\\Dhruv\\myGithub\\Competitive-Programming\\CodeChef\\March Starters 2021\\Point_Grid.cpp"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"A. GCD Sum","group":"Codeforces - CodeCraft-21 and Codeforces Round #711 (Div. 2)","url":"https://codeforces.com/contest/1498/problem/0","interactive":false,"memoryLimit":256,"timeLimit":1000,"tests":[{"id":1617028741440,"input":"3\n2\n2\n5","output":"12\n33\n75"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"AGCDSum"}},"batch":{"id":"9726aaa8-f9b0-42de-92bd-f611f991fd54","size":1},"srcPath":"c:\\Users\\Dhruv\\myGithub\\Competitive-Programming\\CodeForces\\711 Div 2\\A_GCD_Sum.cpp"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"B. Box Fitting","group":"Codeforces - CodeCraft-21 and Codeforces Round #711 (Div. 2)","url":"https://codeforces.com/contest/1498/problem/B","interactive":false,"memoryLimit":256,"timeLimit":1000,"tests":[{"id":1617030515394,"input":"2\n5 16\n1 2 8 4 8\n6 10\n2 8 8 2 2 8","output":"2\n3"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"BBoxFitting"}},"batch":{"id":"38c0e6ad-7ee4-4b6d-8f69-ebb5c60c436b","size":1},"srcPath":"c:\\Users\\Dhruv\\myGithub\\Competitive-Programming\\CodeForces\\711 Div 2\\B_Box_Fitting.cpp"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"C. Planar Reflections","group":"Codeforces - CodeCraft-21 and Codeforces Round #711 (Div. 2)","url":"https://codeforces.com/contest/1498/problem/C","interactive":false,"memoryLimit":256,"timeLimit":1000,"tests":[{"input":"4\n2 3\n2 2\n3 1\n1 3\n","output":"4\n3\n1\n2\n","id":1617033321889},{"id":1617033321895,"input":"3\n1 1\n1 500\n500 250","output":"1\n2\n257950823"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"CPlanarReflections"}},"batch":{"id":"fb097eac-6400-454d-8380-3c910685f213","size":1},"srcPath":"c:\\Users\\Dhruv\\myGithub\\Competitive-Programming\\CodeForces\\711 Div 2\\C_Planar_Reflections.cpp"}

CodeForces/711 Div 2/A_GCD_Sum.bin

45.3 KB
Binary file not shown.

CodeForces/711 Div 2/A_GCD_Sum.cpp

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
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 sum(int n)
92+
{
93+
int ans = 0;
94+
while (n)
95+
{
96+
ans += n % 10;
97+
n /= 10;
98+
}
99+
return ans;
100+
}
101+
102+
void solve()
103+
{
104+
int n;
105+
cin >> n;
106+
int ans = 1;
107+
int x = n;
108+
for (; ans == 1; x++)
109+
ans = Math.gcd(x, sum(x));
110+
111+
cout << x - 1 << endl;
112+
}
113+
//------------------------------------------------------------------------------
114+
int32_t main()
115+
{
116+
FastIO;
117+
118+
w(T)
119+
solve();
120+
121+
return 0;
122+
}
123+
//------------------------------------------------------------------------------

Google/CodeJam Online Qualification 2021/Median_Sort.cpp

Lines changed: 67 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,30 @@
11
#include <iostream>
22
#include <vector>
3+
#include <set>
4+
#include <map>
35
using namespace std;
46

7+
struct Node
8+
{
9+
int a, b, c;
10+
Node() {}
11+
Node(int a, int b, int c)
12+
{
13+
this->a = min(a, min(b, c));
14+
this->c = max(a, max(b, c));
15+
this->b = a ^ b ^ c ^ this->a ^ this->c;
16+
}
17+
18+
bool operator<(const Node &t) const
19+
{
20+
if (this->a != t.a)
21+
return this->a < t.a;
22+
if (this->b != t.b)
23+
return this->b < t.b;
24+
return this->c < t.c;
25+
}
26+
};
27+
528
void solve(int &n, int &q)
629
{
730
vector<int> A(3);
@@ -13,17 +36,29 @@ void solve(int &n, int &q)
1336
int md;
1437
cin >> md;
1538
swap(A[md - 1], A[1]);
39+
40+
Node temp(A[0], A[1], A[2]);
41+
map<Node, int> myMap;
42+
myMap[temp] = md;
43+
1644
for (int i = 4; i <= n; i++)
1745
{
1846
int l = 1;
1947
int r = A.size() - 1;
2048
int pos = -1;
21-
while (l <= r and pos == -1 and q > 0)
49+
while (l <= r and pos == -1)
2250
{
23-
q--;
2451
int m = (l + r) >> 1;
25-
cout << A[m] << " " << A[m - 1] << " " << i << endl;
26-
cin >> md;
52+
Node temp(A[m], A[m - 1], i);
53+
54+
if (myMap.count(temp) == 0)
55+
{
56+
cout << A[m] << " " << A[m - 1] << " " << i << endl;
57+
cin >> md;
58+
myMap[temp] = md;
59+
}
60+
else
61+
md = myMap[temp];
2762

2863
if (md == i)
2964
pos = m;
@@ -32,18 +67,38 @@ void solve(int &n, int &q)
3267
else
3368
r = m - 1;
3469
}
35-
if (q == 0)
36-
exit(0);
70+
3771
if (pos == -1)
3872
{
39-
cout << A[0] << " " << A[1] << " " << i << endl;
40-
cin >> md;
41-
q--;
42-
if (md == A[0])
43-
pos = 0;
73+
Node temp1(A[1], A[0], i);
74+
Node temp2(A[A.size() - 1], A[A.size() - 2], i);
75+
76+
if (myMap.count(temp1) > 0)
77+
{
78+
if (myMap[temp1] == A[0])
79+
pos = 0;
80+
else
81+
pos = A.size();
82+
}
83+
else if (myMap.count(temp2) > 0)
84+
{
85+
if (myMap[temp2] == A[A.size() - 1])
86+
pos = A.size();
87+
else
88+
pos = 0;
89+
}
4490
else
45-
pos = A.size();
91+
{
92+
cout << A[0] << " " << A[1] << " " << i << endl;
93+
cin >> md;
94+
myMap[temp1] = md;
95+
if (md == A[0])
96+
pos = 0;
97+
else
98+
pos = A.size();
99+
}
46100
}
101+
47102
A.insert(A.begin() + pos, i);
48103
}
49104
for (int i = 0; i < n; i++)
48.8 KB
Binary file not shown.

Practice/1.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
3+
int main()
4+
{
5+
int n, m;
6+
cin >> n >> m;
7+
8+
vector<vector<char>> board(n, vector<char>(m));
9+
10+
for (int i = 0; i < n; ++i)
11+
{
12+
for (int j = 0; j < m; ++j)
13+
{
14+
cin >> board[i][j];
15+
}
16+
}
17+
18+
cout << (hasCycle(board, n, m) ? "true" : "false");
19+
}

Practice/1.exe

160 KB
Binary file not shown.

0 commit comments

Comments
 (0)