Skip to content

Commit ecfaffc

Browse files
Added All Distinct number solution
1 parent 8c46b8c commit ecfaffc

File tree

14 files changed

+376
-126
lines changed

14 files changed

+376
-126
lines changed

AtCoder/A-intersection.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1-
#include<bits/stdc++.h>
1+
#include <bits/stdc++.h>
22

33
using namespace std;
44

5-
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
5+
#define optimize() \
6+
ios_base::sync_with_stdio(0); \
7+
cin.tie(0); \
8+
cout.tie(0);
69

710
int main() {
811
optimize();
9-
int l1,r1,l2,r2;
12+
int l1, r1, l2, r2;
1013
cin >> l1 >> r1 >> l2 >> r2;
11-
int temp1=min(r1, r2);
12-
int temp2=temp1-l2;
13-
if(l2 < r1) {
14+
int temp1 = min(r1, r2);
15+
int temp2 = temp1 - l2;
16+
if (l2 < r1) {
1417
cout << temp1 - l2 << endl;
15-
}
16-
else cout << 0 << endl;
18+
} else
19+
cout << 0 << endl;
1720
return 0;
1821
}

Codeforces/1030A/1030A.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ int main() {
1919
cout<<"HARD"<<endl;
2020
}
2121
return 0;
22-
}
22+
}
23+

Codeforces/1097A/1097A.cpp

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
Northern University Bangladesh
55
*/
66

7-
#include<bits/stdc++.h>
7+
#include <bits/stdc++.h>
88
using namespace std;
99

1010
typedef long long ll;
1111
typedef vector<int> vi;
1212
typedef vector<ll> vl;
1313
typedef vector<vi> vvi;
1414
typedef vector<vl> vvl;
15-
typedef pair<int,int> pii;
15+
typedef pair<int, int> pii;
1616
typedef pair<double, double> pdd;
1717
typedef pair<ll, ll> pll;
1818
typedef vector<pii> vii;
@@ -22,8 +22,8 @@ typedef double dl;
2222
#define PB push_back
2323
#define F first
2424
#define S second
25-
#define all(a) (a).begin(),(a).end()
26-
#define rall(a) (a).rbegin(),(a).rend()
25+
#define all(a) (a).begin(), (a).end()
26+
#define rall(a) (a).rbegin(), (a).rend()
2727
#define sz(x) (int)x.size()
2828

2929
const double PI = acos(-1);
@@ -32,28 +32,33 @@ const int inf = 2000000000;
3232
const ll infLL = 1000000000000000000;
3333
#define MOD 1000000007
3434

35-
#define mem(a,b) memset(a, b, sizeof(a) )
35+
#define mem(a, b) memset(a, b, sizeof(a))
3636
#define sqr(a) ((a) * (a))
3737

38-
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
39-
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
38+
#define optimize() \
39+
ios_base::sync_with_stdio(0); \
40+
cin.tie(0); \
41+
cout.tie(0);
42+
#define fraction() \
43+
cout.unsetf(ios::floatfield); \
44+
cout.precision(10); \
45+
cout.setf(ios::fixed, ios::floatfield);
4046

41-
ll gcd ( ll a, ll b ) { return __gcd ( a, b ); }
42-
ll lcm ( ll a, ll b ) { return a * ( b / gcd ( a, b ) ); }
43-
44-
int dx[] = { 0, 0, +1, -1, -1 +1, -1, +1 };
45-
int dy[] = { +1, -1, 0, 0, -1, +1, +1, -1 };
47+
ll gcd(ll a, ll b) { return __gcd(a, b); }
48+
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
4649

50+
int dx[] = {0, 0, +1, -1, -1 + 1, -1, +1};
51+
int dy[] = {+1, -1, 0, 0, -1, +1, +1, -1};
4752

4853
int main() {
4954
optimize();
5055
string s;
5156
cin >> s;
52-
int n=5;
53-
while(n--) {
57+
int n = 5;
58+
while (n--) {
5459
string s1;
5560
cin >> s1;
56-
if(s1[0]==s[0] || s1[0]==s[1] || s1[1]==s[0] || s1[1]==s[1]) {
61+
if (s1[0] == s[0] || s1[0] == s[1] || s1[1] == s[0] || s1[1] == s[1]) {
5762
return cout << "YES" << endl, 0;
5863
}
5964
}

Codeforces/1692B/1692B.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,37 @@
1-
/*
1+
/*
22
IN THE NAME OF ALLAH
33
Author: Moinul Hossain
44
Northern University Bangladesh
55
*/
66

7-
#include<bits/stdc++.h>
7+
#include <bits/stdc++.h>
88

99
using namespace std;
1010

11-
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
11+
#define optimize() \
12+
ios_base::sync_with_stdio(0); \
13+
cin.tie(0); \
14+
cout.tie(0);
1215

1316
int main() {
17+
optimize();
1418
int t;
1519
cin >> t;
16-
while(t--) {
20+
while (t--) {
1721
int n;
1822
cin >> n;
1923
vector<int> v(n);
20-
for(int i=0; i<n; i++) cin >> v[i];
21-
sort(v.begin(), v.end());
22-
int size = unique(v.begin(), v.end()) - v.begin();
23-
cout << size << endl;
24+
set<int> s;
25+
for (int i = 0; i < n; i++) {
26+
int a;
27+
cin >> a;
28+
v[i] = a;
29+
s.insert(a);
30+
}
31+
if ((n - s.size()) % 2 == 0)
32+
cout << s.size() << endl;
33+
else
34+
cout << s.size() - 1 << endl;
2435
}
2536
return 0;
2637
}

Codeforces/1692B/a.out

37 KB
Binary file not shown.

GFG/max-freq.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ int main() {
3939

4040
return 0;
4141
}
42+

Lightoj/Hex-a-bonacci.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ int main() {
3131
}
3232
return 0;
3333
}
34+

Lightoj/a.out

17.7 KB
Binary file not shown.

Lightoj/brush-v.cpp

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
Northern University Bangladesh
55
*/
66

7-
#include<bits/stdc++.h>
7+
#include <bits/stdc++.h>
88
using namespace std;
99

1010
typedef long long ll;
1111
typedef vector<int> vi;
1212
typedef vector<ll> vl;
1313
typedef vector<vi> vvi;
1414
typedef vector<vl> vvl;
15-
typedef pair<int,int> pii;
15+
typedef pair<int, int> pii;
1616
typedef pair<double, double> pdd;
1717
typedef pair<ll, ll> pll;
1818
typedef vector<pii> vii;
@@ -22,8 +22,8 @@ typedef double dl;
2222
#define PB push_back
2323
#define F first
2424
#define S second
25-
#define all(a) (a).begin(),(a).end()
26-
#define rall(a) (a).rbegin(),(a).rend()
25+
#define all(a) (a).begin(), (a).end()
26+
#define rall(a) (a).rbegin(), (a).rend()
2727
#define sz(x) (int)x.size()
2828

2929
const double PI = acos(-1);
@@ -32,39 +32,47 @@ const int inf = 2000000000;
3232
const ll infLL = 1000000000000000000;
3333
#define MOD 1000000007
3434

35-
#define mem(a,b) memset(a, b, sizeof(a) )
35+
#define mem(a, b) memset(a, b, sizeof(a))
3636
#define sqr(a) ((a) * (a))
3737

38-
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
39-
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
38+
#define optimize() \
39+
ios_base::sync_with_stdio(0); \
40+
cin.tie(0); \
41+
cout.tie(0);
42+
#define fraction() \
43+
cout.unsetf(ios::floatfield); \
44+
cout.precision(10); \
45+
cout.setf(ios::fixed, ios::floatfield);
4046

41-
ll gcd ( ll a, ll b ) { return __gcd ( a, b ); }
42-
ll lcm ( ll a, ll b ) { return a * ( b / gcd ( a, b ) ); }
47+
ll gcd(ll a, ll b) { return __gcd(a, b); }
48+
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
4349

44-
int dx[] = { 0, 0, +1, -1, -1 +1, -1, +1 };
45-
int dy[] = { +1, -1, 0, 0, -1, +1, +1, -1 };
50+
int dx[] = {0, 0, +1, -1, -1 + 1, -1, +1};
51+
int dy[] = {+1, -1, 0, 0, -1, +1, +1, -1};
4652

47-
const int mx=112;
53+
const int mx = 112;
4854
ll dist[mx];
4955
vii adj[mx];
5056

5157
void dijkstra(int s, int n) {
52-
for(int i=0; i<=n; i++) dist[i]=infLL;
58+
for (int i = 0; i <= n; i++)
59+
dist[i] = infLL;
5360
priority_queue<pll, vll, greater<pll>> pq;
54-
dist[s]=0;
61+
dist[s] = 0;
5562
pq.push({0, s});
5663

57-
while(!pq.empty()) {
64+
while (!pq.empty()) {
5865
int u = pq.top().S;
5966
ll currD = pq.top().F;
6067
pq.pop();
6168

62-
if(dist[u] < currD) continue;
69+
if (dist[u] < currD)
70+
continue;
6371

64-
for(auto p : adj[u]) {
72+
for (auto p : adj[u]) {
6573
int v = p.F;
6674
int w = p.S;
67-
if(currD + w < dist[v]) {
75+
if (currD + w < dist[v]) {
6876
dist[v] = currD + w;
6977
pq.push({dist[v], v});
7078
}
@@ -76,18 +84,21 @@ int main() {
7684
optimize();
7785
int t;
7886
cin >> t;
79-
for(int tc=1; tc<=t; tc++) {
80-
int n,m;
87+
for (int tc = 1; tc <= t; tc++) {
88+
int n, m;
8189
cin >> n >> m;
82-
for(int i=0; i<=n; i++) adj[i].clear();
83-
for(int i=1; i<=m; i++) {
90+
for (int i = 0; i <= n; i++)
91+
adj[i].clear();
92+
for (int i = 1; i <= m; i++) {
8493
int u, v, w;
8594
cin >> u >> v >> w;
86-
adj[u].PB({ v, w });
87-
adj[v].PB({ u, w });
95+
adj[u].PB({v, w});
96+
adj[v].PB({u, w});
8897
}
8998
dijkstra(1, n);
90-
if(dist[n] == infLL) cout << "Case " << tc << ": Impossible\n";
91-
else cout << "Case " << tc << ": " << dist[n] << endl;
99+
if (dist[n] == infLL)
100+
cout << "Case " << tc << ": Impossible\n";
101+
else
102+
cout << "Case " << tc << ": " << dist[n] << endl;
92103
}
93104
}

0 commit comments

Comments
 (0)