Skip to content

Commit 1c31e83

Browse files
committed
cf, leetcode
1 parent 6d2ddbf commit 1c31e83

File tree

7 files changed

+282
-93
lines changed

7 files changed

+282
-93
lines changed

Codeforces/1272B-Snow_Walking_Robot.cpp

Lines changed: 35 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -4,120 +4,62 @@
44
*/
55
#include <bits/stdc++.h>
66
using namespace std;
7-
typedef long long ll ;
8-
typedef vector<ll> vl;
9-
typedef vector<bool> vb;
10-
typedef vector<char> vc;
11-
typedef map<ll,ll> ml;
12-
typedef set<char>sc;
13-
typedef set<ll> sl;
14-
#define pan cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
15-
// define values.
16-
#define mod 10000009
17-
#define phi 1.618
18-
/* Bit-Stuff */
19-
#define get_set_bits(a) (__builtin_popcount(a))
20-
#define get_set_bitsll(a) ( __builtin_popcountll(a))
21-
#define get_trail_zero(a) (__builtin_ctz(a))
22-
#define get_lead_zero(a) (__builtin_clz(a))
23-
#define get_parity(a) (__builtin_parity(a))
24-
/* Abbrevations */
25-
#define ff first
26-
#define ss second
27-
#define mp make_pair
28-
#define line cout<<endl;
29-
#define pb push_back
30-
#define Endl "\n"
31-
// loops
32-
#define forin(arr,n) for(ll i=0;i<n;i++) cin>>arr[i];
33-
// Some print
34-
#define no cout<<"NO"<<endl;
35-
#define yes cout<<"YES"<<endl;
36-
#define cc ll test;cin>>test;while(test--)
37-
// sort
38-
#define all(V) (V).begin(),(V).end()
39-
#define srt(V) sort(all(V))
40-
#define srtGreat(V) sort(all(V),greater<ll>())
41-
// function
7+
typedef long long ll;
428

43-
ll power(ll x,ll y)
9+
int solve()
4410
{
45-
ll res=1;
46-
// x=x%mod;
47-
while(y>0)
11+
string s;
12+
cin >> s;
13+
map<char, ll> m;
14+
for (auto x : s)
4815
{
49-
if(y%2==1)
50-
{
51-
res*=x;
52-
// res=res%mod;
53-
}
54-
y/=2; x*=x; // x=x%mod;
16+
m[x]++;
5517
}
56-
return res;
57-
}
58-
/* ascii value
59-
A=65,Z=90,a=97,z=122
60-
*/
61-
/* -----------------------------------------------------------------------------------*/
6218

19+
ll minUD = min(m['U'], m['D']);
20+
ll minLR = min(m['L'], m['R']);
6321

64-
ll solve()
65-
{
66-
string s;
67-
cin>>s;
68-
map<char,ll> m;
69-
for(auto x:s)
70-
m[x]++;
71-
ll temp1=min(m['U'],m['D']);
72-
ll temp2=min(m['L'],m['R']);
73-
if(temp1==0&&temp2==0)
22+
if (minUD == 0 && minLR == 0)
7423
{
75-
cout<<0<<endl;
76-
cout<<" "<<endl;
24+
cout << 0 << endl;
25+
cout << " " << endl;
7726
}
78-
else if(temp1==0)
27+
else if (minUD == 0)
7928
{
80-
if(temp2>=1)
81-
{
82-
cout<<2<<endl<<"LR"<<endl;
83-
}
84-
else
85-
{
86-
cout<<0<<endl<<" "<<endl;
87-
}
29+
cout << 2 << endl
30+
<< "LR" << endl;
8831
}
89-
else if(temp2==0)
32+
else if (minLR == 0)
9033
{
91-
if(temp1>=1)
92-
{
93-
cout<<2<<endl<<"UD"<<endl;
94-
}
34+
cout << 2 << endl
35+
<< "UD" << endl;
9536
}
9637
else
9738
{
98-
string s="";
99-
for(ll i=0;i<temp1;i++)
39+
string s = "";
40+
for (ll i = 0; i < minUD; i++)
41+
{
42+
s += 'U';
43+
}
44+
for (ll i = 0; i < minLR; i++)
10045
{
101-
s+='U';
46+
s += 'R';
10247
}
103-
for(ll i=0;i<temp2;i++)
104-
s+='R';
105-
for(ll i=0;i<temp1;i++)
106-
s+='D';
107-
for(ll i=0;i<temp2;i++)
108-
s+='L';
109-
cout<<s.size()<<endl<<s<<endl;
48+
s += string(minUD, 'D');
49+
s += string(minLR, 'L');
50+
51+
cout << s.size() << endl
52+
<< s << endl;
11053
}
11154
return 0;
11255
}
113-
11456
int main()
11557
{
116-
//freopen("input.txt"a, "r", stdin);
117-
pan;
118-
// solve();
119-
cc
58+
int testCase = 1;
59+
cin >> testCase;
60+
while (testCase--)
12061
{
12162
solve();
12263
}
123-
}
64+
return 0;
65+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
int solve(){
11+
int n, m;
12+
cin >> n >> m;
13+
14+
int x1, y1, x2, y2;
15+
cin >> x1 >> y1 >> x2 >> y2;
16+
17+
int d1 = 0, d2 = 0;
18+
19+
if (x1 - 1 >= 1)
20+
d1++;
21+
if (x1 + 1 <= n)
22+
d1++;
23+
if (y1 - 1 >= 1)
24+
d1++;
25+
if (y1 + 1 <= m)
26+
d1++;
27+
28+
if (x2 - 1 >= 1)
29+
d2++;
30+
if (x2 + 1 <= n)
31+
d2++;
32+
if (y2 - 1 >= 1)
33+
d2++;
34+
if (y2 + 1 <= m)
35+
d2++;
36+
37+
cout << min(d1, d2) << endl;
38+
return 0;
39+
}
40+
int main()
41+
{
42+
int testCase=1;
43+
cin>>testCase;
44+
while(testCase--){
45+
solve();
46+
}
47+
return 0;
48+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
int solve()
10+
{
11+
int n;
12+
cin >> n;
13+
vector<int> v(n + 1);
14+
for (int i = 1; i <= n; i++)
15+
{
16+
cin >> v[i];
17+
}
18+
for (int i = 1; i <= n; i++)
19+
{
20+
if (v[i] <= i)
21+
{
22+
cout << "YES" << endl;
23+
return 0;
24+
}
25+
}
26+
cout << "NO" << endl;
27+
return 0;
28+
}
29+
int main()
30+
{
31+
int testCase = 1;
32+
cin >> testCase;
33+
while (testCase--)
34+
{
35+
solve();
36+
}
37+
return 0;
38+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
int solve(){
11+
int n;
12+
cin>>n;
13+
if(n%2==0){
14+
cout<<-1<<endl;
15+
return 0;
16+
}
17+
vector<int> v;
18+
string bits="";
19+
while(n){
20+
if(n&1){
21+
bits+="1";
22+
}
23+
else{
24+
bits+="0";
25+
}
26+
n>>=1;
27+
}
28+
reverse(bits.begin(),bits.end());
29+
// cout<<"string is "<<bits<<endl;
30+
for(int i=0;i<bits.size()-1;i++){
31+
if(bits[i]=='0'){
32+
v.push_back(1);
33+
}
34+
else{
35+
v.push_back(2);
36+
}
37+
}
38+
cout<<v.size()<<endl;
39+
for(auto x:v){
40+
cout<<x<<" ";
41+
}
42+
cout<<endl;
43+
return 0;
44+
}
45+
int main()
46+
{
47+
int testCase=1;
48+
cin>>testCase;
49+
while(testCase--){
50+
solve();
51+
}
52+
return 0;
53+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
int solve(){
11+
int n;
12+
long long c, d;
13+
cin >> n >> c >> d;
14+
vector<int> a(n);
15+
map<int, int> mp;
16+
17+
for (int j = 0; j < n; j++)
18+
{
19+
cin >> a[j];
20+
mp[a[j]]++;
21+
}
22+
long long ans = n * c + d;
23+
int cnt = 0;
24+
for (auto x : mp)
25+
{
26+
cnt++;
27+
ans = min(ans, (n - cnt) * c + (x.first - cnt) * d);
28+
}
29+
cout << ans << endl;
30+
return 0;
31+
}
32+
int main()
33+
{
34+
int testCase=1;
35+
cin>>testCase;
36+
while(testCase--){
37+
solve();
38+
}
39+
return 0;
40+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
typedef long long ll ;
6+
const ll INF=1e18;
7+
const ll mod1=1e9+7;
8+
const ll mod2=998244353;
9+
//Add main code here
10+
11+
class Solution
12+
{
13+
public:
14+
int kItemsWithMaximumSum(int numOnes, int numZeros, int numNegOnes, int k)
15+
{
16+
int ans=0;
17+
if (numOnes >= k)
18+
{
19+
return k;
20+
}
21+
else{
22+
ans = numOnes;
23+
k -= numOnes;
24+
if(numZeros>=k){
25+
return ans;
26+
}
27+
else{
28+
k-=numZeros;
29+
ans-=k;
30+
return ans;
31+
}
32+
}
33+
}
34+
};

0 commit comments

Comments
 (0)