Skip to content

Commit 130ed88

Browse files
authored
Add files via upload
1 parent 692abda commit 130ed88

10 files changed

+1249
-0
lines changed

3SUM.cpp

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
// https://codeforces.com/contest/1692/problem/F
2+
/*
3+
4+
░██████╗██████╗░░█████╗░██████╗░░██████╗██╗░░██╗  ░██████╗░██╗░░░██╗██████╗░████████╗░█████╗░
5+
██╔════╝██╔══██╗██╔══██╗██╔══██╗██╔════╝██║░░██║  ██╔════╝░██║░░░██║██╔══██╗╚══██╔══╝██╔══██╗
6+
╚█████╗░██████╔╝███████║██████╔╝╚█████╗░███████║  ██║░░██╗░██║░░░██║██████╔╝░░░██║░░░███████║
7+
░╚═══██╗██╔═══╝░██╔══██║██╔══██╗░╚═══██╗██╔══██║  ██║░░╚██╗██║░░░██║██╔═══╝░░░░██║░░░██╔══██║
8+
██████╔╝██║░░░░░██║░░██║██║░░██║██████╔╝██║░░██║  ╚██████╔╝╚██████╔╝██║░░░░░░░░██║░░░██║░░██║
9+
╚═════╝░╚═╝░░░░░╚═╝░░╚═╝╚═╝░░╚═╝╚═════╝░╚═╝░░╚═╝  ░╚═════╝░░╚═════╝░╚═╝░░░░░░░░╚═╝░░░╚═╝░░╚═╝
10+
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
11+
█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗
12+
╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝
13+
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
14+
15+
*/
16+
17+
#include <bits/stdc++.h>
18+
19+
using namespace std;
20+
21+
#define fi first
22+
#define se second
23+
#define pb push_back
24+
#define mp make_pair
25+
#define all(x) x.begin(), x.end()
26+
#define ll long long
27+
#define pll pair<ll, ll>
28+
#define vll vector<long long>
29+
#define vpll vector<pll>
30+
#define mll map<ll, ll>
31+
#define sz(x) ((int) x.size())
32+
#define inf 1e18
33+
#define que_max priority_queue<ll>
34+
#define que_min priority_queue <ll, vll, greater<ll>>
35+
#define gcd(a, b) __gcd(a, b)
36+
#define range(a,b) substr(a,b-a+1)
37+
#define setbits(x) __builtin_popcountll(x)
38+
#define zrobits(x) __builtin_ctzll(x)
39+
#define fori(a, n) for (ll i = a; i < n; i++)
40+
#define forj(a, n) for (ll j = a; j < n; j++)
41+
#define fork(a, n) for (ll k = a; k < n; k++)
42+
#define print(x) for (auto i : x) cout << i << " "; cout << "\n";
43+
#define print1(x) for (auto i : x) cout << i.fi << " " << i.se << "\n";
44+
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
45+
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
46+
47+
inline ll power(ll a, ll b)
48+
{
49+
ll x = 1;
50+
while (b) {
51+
if (b & 1)
52+
x *= a;
53+
a *= a;
54+
b >>= 1;
55+
}
56+
return x;
57+
}
58+
59+
template <class T>
60+
bool comp(T a, T b) {
61+
if (a < b)
62+
return true;
63+
return false;
64+
}
65+
66+
void solve() {
67+
ll n;
68+
cin >> n;
69+
map<ll, ll> mps;
70+
vector<ll> freq(10);
71+
fori(0, n) {
72+
ll temp;
73+
cin >> temp;
74+
mps[temp % 10]++;
75+
freq[temp % 10] = 1;
76+
}
77+
bool flag = false;
78+
if ((mps[0] >= 2 && mps[3] >= 1) || mps[1] >= 3 || (mps[2] >= 2 && mps[9] >= 1) || (mps[3] >= 2 && mps[7] >= 1) || (mps[4] >= 2 && mps[5] >= 1) || (mps[5] >= 2 && mps[3] >= 1) || (mps[6] >= 2 && mps[1] >= 1) || (mps[7] >= 2 && mps[9] >= 1) || (mps[8] >= 2 && mps[7] >= 1) || (mps[9] >= 2 && mps[5] >= 1))
79+
flag = true;
80+
else {
81+
for (int i = 0; i < 8; i++)
82+
if (freq[i] == 1)
83+
for (int j = i + 1; j < 9; j++)
84+
if (freq[j] == 1)
85+
for (int k = j + 1; k < 10; k++)
86+
if (freq[k] == 1 && (i + j + k) % 10 == 3) {
87+
flag = true;
88+
break;
89+
}
90+
}
91+
if (flag)
92+
cout << "YES\n";
93+
else
94+
cout << "NO\n";
95+
}
96+
97+
int32_t main()
98+
{
99+
FIO;
100+
101+
#ifndef ONLINE_JUDGE
102+
//remove this piece of code when this has to be submitted in kickstart, coding ninjas
103+
freopen("input.txt", "r", stdin);
104+
freopen("output.txt", "w", stdout);
105+
//freopen is used to associate a file with stdin or stdout stream in C++
106+
#endif
107+
108+
clock_t z = clock();
109+
110+
ll t = 1;
111+
cin >> t;
112+
while (t--) {
113+
solve();
114+
}
115+
116+
cerr << "Run Time: " << ((double)(clock() - z) / CLOCKS_PER_SEC) << "\n";
117+
118+
return 0;
119+
}
120+

Add Modulo 10.cpp

+135
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
// https://codeforces.com/contest/1714/problem/E
2+
/*
3+
4+
░██████╗██████╗░░█████╗░██████╗░░██████╗██╗░░██╗  ░██████╗░██╗░░░██╗██████╗░████████╗░█████╗░
5+
██╔════╝██╔══██╗██╔══██╗██╔══██╗██╔════╝██║░░██║  ██╔════╝░██║░░░██║██╔══██╗╚══██╔══╝██╔══██╗
6+
╚█████╗░██████╔╝███████║██████╔╝╚█████╗░███████║  ██║░░██╗░██║░░░██║██████╔╝░░░██║░░░███████║
7+
░╚═══██╗██╔═══╝░██╔══██║██╔══██╗░╚═══██╗██╔══██║  ██║░░╚██╗██║░░░██║██╔═══╝░░░░██║░░░██╔══██║
8+
██████╔╝██║░░░░░██║░░██║██║░░██║██████╔╝██║░░██║  ╚██████╔╝╚██████╔╝██║░░░░░░░░██║░░░██║░░██║
9+
╚═════╝░╚═╝░░░░░╚═╝░░╚═╝╚═╝░░╚═╝╚═════╝░╚═╝░░╚═╝  ░╚═════╝░░╚═════╝░╚═╝░░░░░░░░╚═╝░░░╚═╝░░╚═╝
10+
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
11+
█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗
12+
╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝
13+
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
14+
15+
*/
16+
17+
#include <bits/stdc++.h>
18+
19+
using namespace std;
20+
21+
#define fi first
22+
#define se second
23+
#define pb push_back
24+
#define mp make_pair
25+
#define all(x) x.begin(), x.end()
26+
#define ll long long
27+
#define pll pair<ll, ll>
28+
#define vll vector<long long>
29+
#define vpll vector<pll>
30+
#define mll map<ll, ll>
31+
#define sz(x) ((int) x.size())
32+
#define inf 1e18
33+
#define que_max priority_queue<ll>
34+
#define que_min priority_queue <ll, vll, greater<ll>>
35+
#define gcd(a, b) __gcd(a, b)
36+
#define range(a,b) substr(a,b-a+1)
37+
#define setbits(x) __builtin_popcountll(x)
38+
#define zrobits(x) __builtin_ctzll(x)
39+
#define fori(a, n) for (ll i = a; i < n; i++)
40+
#define forj(a, n) for (ll j = a; j < n; j++)
41+
#define fork(a, n) for (ll k = a; k < n; k++)
42+
#define print(x) for (auto i : x) cout << i << " "; cout << "\n";
43+
#define print1(x) for (auto i : x) cout << i.fi << " " << i.se << "\n";
44+
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
45+
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
46+
47+
inline ll power(ll a, ll b)
48+
{
49+
ll x = 1;
50+
while (b) {
51+
if (b & 1)
52+
x *= a;
53+
a *= a;
54+
b >>= 1;
55+
}
56+
return x;
57+
}
58+
59+
template <class T>
60+
bool comp(T a, T b) {
61+
if (a < b)
62+
return true;
63+
return false;
64+
}
65+
66+
void solve() {
67+
ll n, cnt0 = 0, cnt5 = 0, cnt = 0, temp;
68+
cin >> n;
69+
set<ll> st;
70+
fori(0, n) {
71+
cin >> temp;
72+
if ((temp % 10) != 0 && (temp % 10) != 5) {
73+
while (temp % 10 != 2)
74+
temp = temp + temp % 10;
75+
st.insert(temp + temp % 10);
76+
}
77+
else if ((temp % 10) == 5)
78+
st.insert(temp + 5);
79+
else
80+
st.insert(temp);
81+
if (temp % 10 == 0)
82+
cnt0++;
83+
else if (temp % 10 == 5)
84+
cnt5++;
85+
else
86+
cnt++;
87+
}
88+
if ((cnt0 > 0 || cnt5 > 0) && cnt > 0) {
89+
cout << "No\n";
90+
}
91+
else if (cnt == 0) {
92+
if (st.size() > 1)
93+
cout << "No\n";
94+
else
95+
cout << "Yes\n";
96+
}
97+
else {
98+
vll arr;
99+
for (auto i : st)
100+
arr.pb(i);
101+
fori(0, arr.size()) {
102+
if ((arr.back() - arr[i]) % 20 != 0) {
103+
cout << "No\n";
104+
return;
105+
}
106+
}
107+
cout << "Yes\n";
108+
return;
109+
}
110+
}
111+
112+
int32_t main()
113+
{
114+
FIO;
115+
116+
#ifndef ONLINE_JUDGE
117+
//remove this piece of code when this has to be submitted in kickstart, coding ninjas
118+
freopen("input.txt", "r", stdin);
119+
freopen("output.txt", "w", stdout);
120+
//freopen is used to associate a file with stdin or stdout stream in C++
121+
#endif
122+
123+
clock_t z = clock();
124+
125+
ll t = 1;
126+
cin >> t;
127+
while (t--) {
128+
solve();
129+
}
130+
131+
cerr << "Run Time: " << ((double)(clock() - z) / CLOCKS_PER_SEC) << "\n";
132+
133+
return 0;
134+
}
135+

All Distinct.cpp

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
// https://codeforces.com/contest/1692/problem/B
2+
/*
3+
4+
░██████╗██████╗░░█████╗░██████╗░░██████╗██╗░░██╗  ░██████╗░██╗░░░██╗██████╗░████████╗░█████╗░
5+
██╔════╝██╔══██╗██╔══██╗██╔══██╗██╔════╝██║░░██║  ██╔════╝░██║░░░██║██╔══██╗╚══██╔══╝██╔══██╗
6+
╚█████╗░██████╔╝███████║██████╔╝╚█████╗░███████║  ██║░░██╗░██║░░░██║██████╔╝░░░██║░░░███████║
7+
░╚═══██╗██╔═══╝░██╔══██║██╔══██╗░╚═══██╗██╔══██║  ██║░░╚██╗██║░░░██║██╔═══╝░░░░██║░░░██╔══██║
8+
██████╔╝██║░░░░░██║░░██║██║░░██║██████╔╝██║░░██║  ╚██████╔╝╚██████╔╝██║░░░░░░░░██║░░░██║░░██║
9+
╚═════╝░╚═╝░░░░░╚═╝░░╚═╝╚═╝░░╚═╝╚═════╝░╚═╝░░╚═╝  ░╚═════╝░░╚═════╝░╚═╝░░░░░░░░╚═╝░░░╚═╝░░╚═╝
10+
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
11+
█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗
12+
╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝
13+
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
14+
15+
*/
16+
17+
#include <bits/stdc++.h>
18+
19+
using namespace std;
20+
21+
#define fi first
22+
#define se second
23+
#define pb push_back
24+
#define mp make_pair
25+
#define all(x) x.begin(), x.end()
26+
#define ll long long
27+
#define pll pair<ll, ll>
28+
#define vll vector<long long>
29+
#define vpll vector<pll>
30+
#define mll map<ll, ll>
31+
#define sz(x) ((int) x.size())
32+
#define inf 1e18
33+
#define que_max priority_queue<ll>
34+
#define que_min priority_queue <ll, vll, greater<ll>>
35+
#define gcd(a, b) __gcd(a, b)
36+
#define range(a,b) substr(a,b-a+1)
37+
#define setbits(x) __builtin_popcountll(x)
38+
#define zrobits(x) __builtin_ctzll(x)
39+
#define fori(a, n) for (ll i = a; i < n; i++)
40+
#define forj(a, n) for (ll j = a; j < n; j++)
41+
#define fork(a, n) for (ll k = a; k < n; k++)
42+
#define print(x) for (auto i : x) cout << i << " "; cout << "\n";
43+
#define print1(x) for (auto i : x) cout << i.fi << " " << i.se << "\n";
44+
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
45+
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
46+
47+
inline ll power(ll a, ll b)
48+
{
49+
ll x = 1;
50+
while (b) {
51+
if (b & 1)
52+
x *= a;
53+
a *= a;
54+
b >>= 1;
55+
}
56+
return x;
57+
}
58+
59+
template <class T>
60+
bool comp(T a, T b) {
61+
if (a < b)
62+
return true;
63+
return false;
64+
}
65+
66+
void solve() {
67+
ll n;
68+
cin >> n;
69+
vll arr(n);
70+
map<ll, ll> mpa;
71+
fori(0, n) {
72+
int temp;
73+
cin >> temp;
74+
mpa[temp]++;
75+
}
76+
int cnt = 0;
77+
for(auto i:mpa)
78+
cnt += i.second - 1;
79+
if (cnt % 2 == 0)
80+
cout << n - cnt << "\n";
81+
else
82+
cout << n - cnt - 1 << "\n";
83+
}
84+
85+
int32_t main()
86+
{
87+
FIO;
88+
89+
#ifndef ONLINE_JUDGE
90+
//remove this piece of code when this has to be submitted in kickstart, coding ninjas
91+
freopen("input.txt", "r", stdin);
92+
freopen("output.txt", "w", stdout);
93+
//freopen is used to associate a file with stdin or stdout stream in C++
94+
#endif
95+
96+
clock_t z = clock();
97+
98+
ll t = 1;
99+
cin >> t;
100+
while (t--) {
101+
solve();
102+
}
103+
104+
cerr << "Run Time: " << ((double)(clock() - z) / CLOCKS_PER_SEC) << "\n";
105+
106+
return 0;
107+
}
108+

0 commit comments

Comments
 (0)