Skip to content

Commit 948cc77

Browse files
committed
leetcode weekly 324
1 parent f5a25f1 commit 948cc77

9 files changed

+675
-282
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
#include <bits/stdc++.h>
6+
using namespace std;
7+
typedef long long ll;
8+
9+
10+
/* ascii value
11+
A=65,Z=90,a=97,z=122
12+
*/
13+
14+
// Techniques :
15+
// divide into cases, brute force, pattern finding
16+
// sort, greedy, binary search, two pointer
17+
// transform into graph
18+
19+
20+
int solve(){
21+
int n;
22+
cin >> n;
23+
vector<int> a(n);
24+
for (int i = 0; i < n; i++){
25+
cin >> a[i];
26+
}
27+
int sum = 0;
28+
for (auto it : a)
29+
sum += it;
30+
if (sum % 2 == 0)
31+
{
32+
cout << 0 << endl;
33+
return 0;
34+
}
35+
int ans = 1e9;
36+
for (auto x : a){
37+
int temp=0;
38+
while (x % 2 == (x / 2) % 2)
39+
{
40+
temp++;
41+
x /= 2;
42+
}
43+
ans = min(ans, temp+1);
44+
}
45+
cout << ans << endl;
46+
return 0;
47+
}
48+
int main()
49+
{
50+
long long testCase;
51+
cin>>testCase;
52+
while(testCase--){
53+
solve();
54+
}
55+
return 0;
56+
}
57+
/* -----------------END OF PROGRAM --------------------*/
58+
/*
59+
* stuff you should look before submission
60+
* constraint and time limit
61+
* int overflow
62+
* special test case (n=0||n=1||n=2)
63+
* don't get stuck on one approach if you get wrong answer
64+
*/
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
#include <bits/stdc++.h>
6+
using namespace std;
7+
typedef long long ll;
8+
9+
/* ascii value
10+
A=65,Z=90,a=97,z=122
11+
*/
12+
13+
// Techniques :
14+
// divide into cases, brute force, pattern finding
15+
// sort, greedy, binary search, two pointer
16+
// transform into graph
17+
18+
int solve()
19+
{
20+
int n;
21+
cin >> n;
22+
vector<ll> a(n);
23+
for (int i = 0; i < n; i++)
24+
{
25+
cin >> a[i];
26+
}
27+
cout << n << endl;
28+
for (int i = 0; i < n; i++)
29+
{
30+
ll deg = 1;
31+
while (deg < a[i])
32+
{
33+
deg *= 2;
34+
}
35+
cout << i + 1 << ' ' << deg - a[i] << endl;
36+
}
37+
return 0;
38+
}
39+
int main()
40+
{
41+
long long testCase;
42+
cin >> testCase;
43+
while (testCase--)
44+
{
45+
solve();
46+
}
47+
return 0;
48+
}
49+
/* -----------------END OF PROGRAM --------------------*/
50+
/*
51+
* stuff you should look before submission
52+
* constraint and time limit
53+
* int overflow
54+
* special test case (n=0||n=1||n=2)
55+
* don't get stuck on one approach if you get wrong answer
56+
*/
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
#include <bits/stdc++.h>
6+
using namespace std;
7+
typedef long long ll;
8+
9+
10+
/* ascii value
11+
A=65,Z=90,a=97,z=122
12+
*/
13+
14+
// Techniques :
15+
// divide into cases, brute force, pattern finding
16+
// sort, greedy, binary search, two pointer
17+
// transform into graph
18+
19+
20+
int solve(){
21+
int n;
22+
cin >> n;
23+
int x = INT_MAX;
24+
int y = 0;
25+
for (int i = 0; i < n; i++)
26+
{
27+
int a;
28+
cin >> a;
29+
x &= a;
30+
y |= a;
31+
}
32+
cout << y - x << '\n';
33+
return 0;
34+
}
35+
int main()
36+
{
37+
long long testCase;
38+
cin>>testCase;
39+
while(testCase--){
40+
solve();
41+
}
42+
return 0;
43+
}
44+
/* -----------------END OF PROGRAM --------------------*/
45+
/*
46+
* stuff you should look before submission
47+
* constraint and time limit
48+
* int overflow
49+
* special test case (n=0||n=1||n=2)
50+
* don't get stuck on one approach if you get wrong answer
51+
*/
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
#include <bits/stdc++.h>
6+
using namespace std;
7+
typedef long long ll;
8+
9+
10+
/* ascii value
11+
A=65,Z=90,a=97,z=122
12+
*/
13+
14+
// Techniques :
15+
// divide into cases, brute force, pattern finding
16+
// sort, greedy, binary search, two pointer
17+
// transform into graph
18+
19+
20+
int solve(){
21+
vector<int> v(6);
22+
for(int i=0;i<6;i++){
23+
cin>>v[i];
24+
}
25+
vector<long long> dist;
26+
dist.push_back(abs(v[0]-v[2])*abs(v[0]-v[2]*1LL)+abs(v[1]-v[3])*abs(v[1]-v[3]*1LL));
27+
dist.push_back(abs(v[0]-v[4])*abs(v[0]-v[4]*1LL)+abs(v[1]-v[5])*abs(v[1]-v[5]*1LL));
28+
dist.push_back(abs(v[2]-v[4])*abs(v[2]-v[4]*1LL)+abs(v[3]-v[5])*abs(v[3]-v[5]*1LL));
29+
sort(dist.begin(),dist.end());
30+
31+
if(dist[0]+dist[1]==dist[2] && (v[0]==v[2] || v[0]==v[4] || v[2]==v[4]) && (v[1]==v[3] || v[1]==v[5] || v[3]==v[5])){
32+
cout<<"NO"<<endl;
33+
}
34+
else{
35+
cout<<"YES"<<endl;
36+
}
37+
return 0;
38+
}
39+
int main()
40+
{
41+
long long testCase;
42+
cin>>testCase;
43+
while(testCase--){
44+
solve();
45+
}
46+
return 0;
47+
}
48+
/* -----------------END OF PROGRAM --------------------*/
49+
/*
50+
* stuff you should look before submission
51+
* constraint and time limit
52+
* int overflow
53+
* special test case (n=0||n=1||n=2)
54+
* don't get stuck on one approach if you get wrong answer
55+
*/
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
#include <bits/stdc++.h>
6+
using namespace std;
7+
typedef long long ll;
8+
9+
10+
/* ascii value
11+
A=65,Z=90,a=97,z=122
12+
*/
13+
14+
// Techniques :
15+
// divide into cases, brute force, pattern finding
16+
// sort, greedy, binary search, two pointer
17+
// transform into graph
18+
19+
20+
int solve(){
21+
long long n;
22+
cin>>n;
23+
vector<long long> v(n-1);
24+
int first=0;
25+
cin>>first;
26+
for(int i=0;i<n-1;i++){
27+
cin>>v[i];
28+
}
29+
sort(v.begin(),v.end());
30+
for(int i=0;i<n-1;i++){
31+
if(v[i]>first){
32+
int x=(v[i]-first+1)/2;
33+
first+=x;
34+
}
35+
}
36+
37+
cout<<first<<endl;
38+
return 0;
39+
}
40+
int main()
41+
{
42+
long long testCase;
43+
cin>>testCase;
44+
while(testCase--){
45+
solve();
46+
}
47+
return 0;
48+
}
49+
/* -----------------END OF PROGRAM --------------------*/
50+
/*
51+
* stuff you should look before submission
52+
* constraint and time limit
53+
* int overflow
54+
* special test case (n=0||n=1||n=2)
55+
* don't get stuck on one approach if you get wrong answer
56+
*/
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
#include <bits/stdc++.h>
6+
using namespace std;
7+
typedef long long ll;
8+
9+
10+
/* ascii value
11+
A=65,Z=90,a=97,z=122
12+
*/
13+
14+
// Techniques :
15+
// divide into cases, brute force, pattern finding
16+
// sort, greedy, binary search, two pointer
17+
// transform into graph
18+
19+
20+
int solve(){
21+
int n;
22+
string s;
23+
cin>>n>>s;
24+
int value=0;
25+
if(s[0]=='1'){
26+
value=1;
27+
}
28+
for(int i=1;i<n;i++){
29+
if(s[i]=='1'){
30+
if(value>0){
31+
cout<<"-";
32+
value--;
33+
}
34+
else{
35+
cout<<"+";
36+
value++;
37+
}
38+
}
39+
else{
40+
cout<<"-";
41+
}
42+
}
43+
cout<<endl;
44+
return 0;
45+
}
46+
int main()
47+
{
48+
long long testCase;
49+
cin>>testCase;
50+
while(testCase--){
51+
solve();
52+
}
53+
return 0;
54+
}
55+
/* -----------------END OF PROGRAM --------------------*/
56+
/*
57+
* stuff you should look before submission
58+
* constraint and time limit
59+
* int overflow
60+
* special test case (n=0||n=1||n=2)
61+
* don't get stuck on one approach if you get wrong answer
62+
*/

0 commit comments

Comments
 (0)