Skip to content

Commit 244c1dc

Browse files
author
ashcode07
committed
added april long challenge solutions
1 parent c8a98ac commit 244c1dc

File tree

7 files changed

+400
-0
lines changed

7 files changed

+400
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
#define ll long long int
4+
#define mod 1000000007
5+
int main() {
6+
ios_base::sync_with_stdio(false);
7+
cin.tie(nullptr);
8+
cout.tie(nullptr);
9+
int t ;
10+
cin >> t ;
11+
ll n;
12+
while (t--) {
13+
cin>>n;
14+
vector<ll> vec;
15+
ll z,profit=0;
16+
for (ll i = 0; i < n; ++i) {
17+
cin>>z;
18+
vec.emplace_back(z);
19+
}
20+
sort(vec.begin(),vec.end(),greater<>());
21+
profit+=vec[0];
22+
for (ll j = 1; j < n; ++j) {
23+
if(vec[j]-j>0)
24+
profit+=(vec[j]-j);
25+
else
26+
break;
27+
}
28+
cout<<profit%mod<<"\n";
29+
}
30+
return 0;
31+
}
32+
33+
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
#define ll long long int
4+
#define mod 1000000007
5+
int main() {
6+
ios_base::sync_with_stdio(false);
7+
cin.tie(nullptr);
8+
cout.tie(nullptr);
9+
int t ;
10+
cin >> t ;
11+
ll n,z;
12+
while (t--) {
13+
cin>>n;
14+
vector<ll> vec;
15+
bool poss= false;
16+
ll count=0;
17+
for (ll i = 0; i <n ; ++i) {
18+
cin>>z;
19+
if(z==1)
20+
count++;
21+
vec.emplace_back(z);
22+
}
23+
ll prev=0,pos1=0;
24+
if(count==1)
25+
poss=true;
26+
else
27+
{
28+
if(n>=6){
29+
for (ll j = 0; j <n ; ++j) {
30+
if(vec[j]==1){
31+
if(prev==0){
32+
prev=1;
33+
pos1=j;
34+
}
35+
else{
36+
if(j-pos1>=6)
37+
{
38+
poss=true;
39+
pos1=j;
40+
41+
} else{
42+
poss= false;
43+
break;
44+
}
45+
}
46+
47+
}
48+
}
49+
}}
50+
if(poss)
51+
cout<<"YES\n";
52+
else
53+
cout<<"NO\n";
54+
}
55+
return 0;
56+
}
57+
58+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
#define ll long long int
4+
#define mod 1000000007
5+
int main() {
6+
ios_base::sync_with_stdio(false);
7+
cin.tie(nullptr);
8+
cout.tie(nullptr);
9+
int t ;
10+
cin >> t ;
11+
ll x,k;
12+
while (t--) {
13+
cin>>x>>k;
14+
unordered_map<ll,ll> umap;
15+
ll n=x;
16+
while (n % 2 == 0)
17+
{
18+
umap[2]++;
19+
n = n/2;
20+
}
21+
for (ll i = 3; i <= sqrt(n); i = i + 2)
22+
{
23+
while (n % i == 0)
24+
{
25+
umap[i]++;
26+
n = n/i;
27+
}
28+
}
29+
ll sum=0;
30+
if (n > 2)
31+
umap[n]++;
32+
for (auto part : umap){
33+
sum+=part.second;
34+
}
35+
if(x>=pow(2,k)&&k<=sum)
36+
cout<<"1\n";
37+
else
38+
cout<<"0\n";
39+
40+
}
41+
return 0;
42+
}
43+
44+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
#define ll long long int
4+
int main(){
5+
ios_base::sync_with_stdio(false);
6+
cin.tie(nullptr);
7+
int t;
8+
cin>>t;
9+
ll n;
10+
while (t--){
11+
cin>>n;
12+
if(n==1)
13+
cout<<"1\n1 1\n";
14+
else
15+
{
16+
cout<<n/2<<"\n";
17+
if(n%2==0)
18+
cout<<"2 1 2\n";
19+
else
20+
cout<<"3 1 2 "<<n<<"\n";
21+
for (ll i = 3; i <n ; i+=2) {
22+
cout<<"2 "<<i<<" "<<i+1<<"\n";
23+
}
24+
}
25+
}
26+
return 0;
27+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
#define ll long long int
4+
ll sumArr(vector<ll>arr, ll n, ll sum)
5+
{
6+
unordered_map<ll, ll> prevSum;
7+
8+
ll res = 0;
9+
10+
// Sum of elements so far.
11+
ll currsum = 0;
12+
13+
for (ll i = 0; i < n; i++) {
14+
15+
currsum += arr[i];
16+
if (currsum == sum)
17+
res++;
18+
19+
if (prevSum.find(currsum - sum) !=
20+
prevSum.end())
21+
res += (prevSum[currsum - sum]);
22+
prevSum[currsum]++;
23+
}
24+
25+
return res;
26+
}
27+
int main(){
28+
ios_base::sync_with_stdio(false);
29+
cin.tie(nullptr);
30+
int t;
31+
cin>>t;
32+
ll n,z;
33+
ll count,mul,odd,even4,even;
34+
while (t--){
35+
cin>>n;
36+
odd=0;even4=0;
37+
even=0;
38+
vector<ll> vec,arr;
39+
ll total =(n*(n+1))/2;
40+
for (ll i = 0; i <n ; ++i) {
41+
cin >> z;
42+
// vec.emplace_back(abs(z));
43+
if(z%4==0)
44+
arr.emplace_back(2);
45+
else if(z%2==0)
46+
arr.emplace_back(1);
47+
else
48+
arr.emplace_back(0);
49+
}
50+
for (ll j = 0; j <n ; ++j) {
51+
52+
}
53+
ll minus=sumArr(arr,n,1);
54+
55+
cout<<total-minus<<"\n";
56+
}
57+
return 0;
58+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
#define ll long long int
4+
ll printRandoms(ll lower, ll upper)
5+
{
6+
ll num = (rand() %(upper - lower + 1)) + lower;
7+
}
8+
int main(){
9+
ios_base::sync_with_stdio(false);
10+
cin.tie(nullptr);
11+
int t;
12+
cin>>t;
13+
ll n,m,k;
14+
while(t--){
15+
cin>>n>>m>>k;
16+
vector<vector<ll>> vec(n,vector<ll>(k,0));
17+
for (ll i = 0; i <n ; ++i) {
18+
vector<int> mp(m+1,1);
19+
for (ll j = 0; j < k; ++j) {
20+
cin>>vec[i][j];
21+
mp[vec[i][j]]++;
22+
}
23+
sort(mp.begin(),mp.end(),greater<>());
24+
int pos=distance(mp.begin(),max_element(mp.begin(), mp.end()));
25+
// ll pos=printRandoms(1,m);
26+
cout<< pos<<" ";
27+
}
28+
cout<<'\n';
29+
}
30+
return 0;
31+
}

0 commit comments

Comments
 (0)