Skip to content

Commit efcee7a

Browse files
authored
Merge branch 'master' into 3-merge-sort
2 parents e745f52 + 6ea6766 commit efcee7a

File tree

91 files changed

+4056
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+4056
-0
lines changed

CodeChef_problems/CVDRUN.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//************************** it's all about practice ***********************
2+
#include<bits/stdc++.h>
3+
using namespace std;
4+
//**** Abbrevations ****
5+
typedef long long ll;
6+
typedef unsigned long long ull;
7+
typedef long double ld;
8+
//**** STL ****
9+
#define pb push_back
10+
#define pf push_front
11+
#define ppb pop_back
12+
#define ppf pop_front
13+
#define ff first
14+
#define ss second
15+
#define mp make_pair
16+
#define ALL(x) x.begin(), x.end()
17+
//**** some I/O ****
18+
#define no cout << "NO\n"
19+
#define yes cout << "YES\n"
20+
//**** Fast I/O ****
21+
#define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
22+
//**** Short Code ****
23+
#define tc ll t;cin>>t;while(t--)
24+
#define fi(a,b) for(ll i=a;i<b;i++)
25+
#define fj(a,b) for(ll j=a;j<b;j++)
26+
#define fk(a,b) for(ll k=a;k<b;k++)
27+
/*---------------------------------------------------------------------------*/
28+
int main()
29+
{
30+
FAST_IO
31+
tc
32+
{
33+
int n,k,x,y;
34+
cin>>n>>k>>x>>y;
35+
bool c=false;
36+
int i=x;
37+
if(x==y)
38+
c=true;
39+
else
40+
i=(i+k)%n;
41+
while(i!=x)
42+
{
43+
if(i==y)
44+
{
45+
c=true;
46+
break;
47+
}
48+
else
49+
i=(i+k)%n;
50+
}
51+
if(c==true)
52+
yes;
53+
else
54+
no;
55+
56+
}
57+
return 0;
58+
}
59+

CodeChef_problems/ChefinaAndSwaps.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
'''
2+
Problem Link - https://www.codechef.com/JULY20B/problems/CHFNSWPS
3+
'''
4+
5+
from sys import *
6+
from math import *
7+
from collections import *
8+
9+
mod = 1000000007
10+
11+
def get_array(): return list(map(int, stdin.readline().split()))
12+
13+
def get_ints(): return map(int, stdin.readline().split())
14+
15+
def get_int(): return int(stdin.readline())
16+
17+
def get_input(): return stdin.readline().strip()
18+
19+
def main():
20+
tc = get_int()
21+
while(tc):
22+
N = get_int();arr = get_array();arr1 = get_array()
23+
mini = min(min(arr),min(arr1))
24+
counter = Counter(arr+arr1)
25+
set,dic,dic1 = 0,{},{}
26+
for i in counter:
27+
if counter[i]&1:set = 1;break
28+
else:
29+
dic[i] = counter[i]/2
30+
if set:stdout.write("-1\n");
31+
else:
32+
dic1,list1,list2 = dic,[],[]
33+
for i in range(N):
34+
if dic[arr[i]]:
35+
dic[arr[i]] -= 1
36+
else:
37+
list1.append(arr[i])
38+
for i in range(N):
39+
if dic1[arr1[i]]:
40+
dic1[arr1[i]] -= 1
41+
else:
42+
list2.append(arr1[i])
43+
list1.sort();list2.sort(reverse=True)
44+
length = len(list1)
45+
if length==0:stdout.write('0\n')
46+
else:
47+
ans = 0
48+
for i in range(length):
49+
ans += min(2*mini,min(list1[i],list2[i]))
50+
stdout.write(str(ans) + '\n')
51+
tc-=1
52+
53+
if __name__ == "__main__":
54+
main()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
t = int(input())
2+
year = [0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0,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400)*101 + sum(year[:y1%400])
12+
value2 = (y2//400)*101 + sum(year[:y2%400])
13+
print(value2 - value1)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include <bits/stdc++.h>
2+
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
3+
typedef unsigned long long int unt;
4+
using namespace std;
5+
6+
bool Prime(unt n){
7+
8+
if (n <= 1)
9+
return false;
10+
if (n <= 3)
11+
return true;
12+
13+
if (n % 2 == 0 || n % 3 == 0)
14+
return false;
15+
16+
for (unt i = 5; i * i <= n; i = i + 6)
17+
if (n % i == 0 || n % (i + 2) == 0)
18+
return false;
19+
20+
return true;
21+
}
22+
23+
void printPrime(unt a,unt n){
24+
for (unt i = a; i <= n; i++){
25+
if(Prime(i))
26+
cout <<i<<'\n';
27+
}
28+
}
29+
30+
int main(){
31+
fast;
32+
unt t;
33+
cin>>t;
34+
while(t--){
35+
int a,n;
36+
cin>>a>>n;
37+
printPrime(a,n);
38+
}
39+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
for _ in range(int(input())):
3+
n = int(input())
4+
a = list(map(int,input().split()))
5+
b = [0]*n
6+
l = []
7+
r = []
8+
for i in range(n):
9+
if(a[i]%2!=0):
10+
b[i] = 1
11+
else:
12+
if(a[i]%4==0):
13+
b[i] = 4
14+
else:
15+
b[i] = 2
16+
count = 0
17+
for i in range(n):
18+
if(b[i] == 1):
19+
count+=1
20+
if(b[i]==4):
21+
count = 0
22+
elif(b[i]==2):
23+
l.append(count+1)
24+
count = 0
25+
count = 0
26+
for i in range(-1,-n-1,-1):
27+
if(b[i] == 1):
28+
count+=1
29+
elif(b[i]==4):
30+
count = 0
31+
elif(b[i]==2):
32+
r.append(count+1)
33+
count = 0
34+
c = 0
35+
for i in range(len(r)):
36+
c+=l[i]*r[-i-1]
37+
print((n*(n+1)//2)-c)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
#include <iostream>
3+
using namespace std;
4+
5+
int main()
6+
{
7+
int n;
8+
cin>>n;
9+
for(int i=0;i<n;++i){
10+
int a;
11+
cin>>a;
12+
13+
if(a>=4){
14+
cout<<a/2<<"\n";
15+
if(a%2==0){
16+
for(int j=0;j<a;j+=2){
17+
cout<<2<<" "<<j+1<<" "<<j+2<<"\n";
18+
}
19+
}
20+
else{
21+
cout<<3<<" "<<1<<" "<<2<<" "<<a<<"\n";
22+
for(int j=2;j<a-2;j+=2){
23+
cout<<2<<" "<<j+1<<" "<<j+2<<"\n";
24+
}
25+
}
26+
}
27+
else{
28+
cout<<1<<"\n";
29+
if(a==1){
30+
cout<<1<<" "<<1<<"\n";
31+
}
32+
else if(a==2){
33+
cout<<2<<" "<<1<<" "<<2<<"\n";
34+
}
35+
else{
36+
cout<<3<<" "<<1<<" "<<2<<" "<<3<<"\n";
37+
}
38+
}
39+
}
40+
}

CodeChef_problems/expected_change.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
def fun(s):
2+
ans = 0
3+
o = 0
4+
c = 0
5+
for i in s:
6+
if(i=="("):
7+
o+=1
8+
elif(i==")"):
9+
c+=1
10+
if(c>o):
11+
c-=1
12+
o+=1
13+
ans+=1
14+
return ans
15+
16+
t = int(input())
17+
18+
for _ in range(t):
19+
n = int(input())
20+
s = input()
21+
ans = 0
22+
N = 10**9+7
23+
value = ((n+1)*n)//2
24+
value = pow(value,N-2,N)
25+
print(value)
26+
for i in range(n):
27+
ans+=fun(s[i:])
28+
print((ans*value)%N)
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+

0 commit comments

Comments
 (0)