Skip to content

Commit aaa75c5

Browse files
committed
codeforces
1 parent fd5c7d1 commit aaa75c5

File tree

6 files changed

+305
-33
lines changed

6 files changed

+305
-33
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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> v(n);
24+
for(int i=0;i<n;i++){
25+
cin>>v[i];
26+
}
27+
cout<<3*(10-n)+(9-n)<<endl;
28+
return 0;
29+
}
30+
int main()
31+
{
32+
long long testCase;
33+
cin>>testCase;
34+
while(testCase--){
35+
solve();
36+
}
37+
return 0;
38+
}
39+
/* -----------------END OF PROGRAM --------------------*/
40+
/*
41+
* stuff you should look before submission
42+
* constraint and time limit
43+
* int overflow
44+
* special test case (n=0||n=1||n=2)
45+
* don't get stuck on one approach if you get wrong answer
46+
*/
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+
int solve(){
19+
int n;
20+
cin>>n;
21+
vector<int> v(n);
22+
for(int i=0;i<n;i++){
23+
cin>>v[i];
24+
}
25+
string s;
26+
cin>>s;
27+
map<int,set<char>> m;
28+
for(int i=0;i<n;i++){
29+
m[v[i]].insert(s[i]);
30+
}
31+
for(auto x:m){
32+
if(x.second.size()>1){
33+
cout<<"NO"<<endl;
34+
return 0;
35+
}
36+
}
37+
cout<<"YES"<<endl;
38+
}
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: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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 main()
21+
{
22+
long long testCase;
23+
cin>>testCase;
24+
while(testCase--){
25+
int n,q;
26+
cin>>n>>q;
27+
long long temp,evenCount=0,oddCount=0;
28+
long long sum=0;
29+
for(int i=0;i<n;i++){
30+
cin>>temp;
31+
if(temp%2==0){
32+
evenCount++;
33+
sum+=temp;
34+
}
35+
else{
36+
oddCount++;
37+
sum += temp;
38+
}
39+
}
40+
while(q--){
41+
int type,x;
42+
cin>>type>>x;
43+
if(type==1){
44+
sum+=oddCount*x;
45+
if(x&1){
46+
evenCount+=oddCount;
47+
oddCount=0;
48+
}
49+
}
50+
else{
51+
sum+=(evenCount*x);
52+
if(x&1){
53+
oddCount+=evenCount;
54+
evenCount=0;
55+
}
56+
}
57+
cout<<sum<<endl;
58+
}
59+
}
60+
return 0;
61+
}
62+
/* -----------------END OF PROGRAM --------------------*/
63+
/*
64+
* stuff you should look before submission
65+
* constraint and time limit
66+
* int overflow
67+
* special test case (n=0||n=1||n=2)
68+
* don't get stuck on one approach if you get wrong answer
69+
*/
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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+
char ch;
23+
cin>>n>>ch;
24+
string s;
25+
cin>>s;
26+
if(ch=='g'){
27+
cout<<0<<endl;
28+
return 0;
29+
}
30+
31+
int first=-1;
32+
int ans=0;
33+
for(int i=0;i<n;i++){
34+
if(s[i]=='g'){
35+
first=i;
36+
break;
37+
}
38+
}
39+
for(int i=0;i<n;i++){
40+
if(s[i]==ch){
41+
int count=0,flag=0;
42+
for(int j=i+1;j<n;j++){
43+
count++;
44+
if(s[j]=='g'){
45+
flag++;
46+
break;
47+
}
48+
}
49+
i=i+count;
50+
if(flag){
51+
ans=max(ans,count);
52+
}
53+
else{
54+
ans=max(ans,count+1+first);
55+
}
56+
}
57+
}
58+
cout<<ans<<endl;
59+
return 0;
60+
}
61+
int main()
62+
{
63+
long long testCase;
64+
cin>>testCase;
65+
while(testCase--){
66+
solve();
67+
}
68+
return 0;
69+
}
70+
/* -----------------END OF PROGRAM --------------------*/
71+
/*
72+
* stuff you should look before submission
73+
* constraint and time limit
74+
* int overflow
75+
* special test case (n=0||n=1||n=2)
76+
* don't get stuck on one approach if you get wrong answer
77+
*/
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 main()
19+
{
20+
long long testCase;
21+
cin >> testCase;
22+
while (testCase--)
23+
{
24+
int n,temp;
25+
cin >> n;
26+
vector<int> ans(n);
27+
for (int i = 0; i < n; i++)
28+
{
29+
cin>>temp;
30+
ans[n-temp]=i+1;
31+
}
32+
for(auto x:ans){
33+
cout<<x<<" ";
34+
}
35+
cout<<endl;
36+
}
37+
return 0;
38+
}
39+
/* -----------------END OF PROGRAM --------------------*/
40+
/*
41+
* stuff you should look before submission
42+
* constraint and time limit
43+
* int overflow
44+
* special test case (n=0||n=1||n=2)
45+
* don't get stuck on one approach if you get wrong answer
46+
*/

LeetCode/344.Reverse_String.cpp

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,14 @@
11
/*
22
written by Pankaj Kumar.
33
country:-INDIA
4-
Institute: National Institute of Technology, Uttarakhand
54
*/
65
typedef long long ll ;
7-
typedef unsigned long long ull;
8-
typedef vector<int> vl;
9-
typedef vector<vector<int>> vvl;
10-
#define speed cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
11-
/* Abbrevations */
12-
#define ff first
13-
#define ss second
14-
#define mp make_pair
15-
#define pb push_back
16-
// loops
17-
#define forin(arr,n) for(ll i=0;i<n;i++) cin>>arr[i];
18-
// Some print
19-
#define no cout<<"NO"<<endl;
20-
#define yes cout<<"YES"<<endl;
21-
// sort
22-
#define all(V) (V).begin(),(V).end()
23-
#define srt(V) sort(all(V))
24-
#define srtGreat(V) sort(all(V),greater<ll>())
25-
// some extra
26-
#define printv(v) for(ll i=0;i<ll(v.size());i++){cout<<v[i]<<" ";} cout<<endl;
27-
#define precision(x) cout<<fixed<<setprecision(x);
28-
#define sz(V) ll(V.size())
296

307

318
/* ascii value
329
A=65,Z=90,a=97,z=122
3310
*/
3411

35-
/* Some syntax
36-
//Syntax to create a min heap for priority queue
37-
//priority_queue <int, vector<int>, greater<int>>pq;
38-
*/
3912
/* --------------------MAIN PROGRAM----------------------------*/
4013
// to run ctrl+b
4114
const ll INF=1e18;
@@ -51,16 +24,21 @@ const ll mod2=998244353;
5124

5225

5326
//Add main code here
54-
class Solution {
27+
28+
class Solution
29+
{
5530
public:
56-
void reverseString(vector<char>& s) {
57-
reverse(s.begin(),s.end());
31+
void reverseString(vector<char> &s)
32+
{
33+
int n = s.size();
34+
for (int i = 0; i < n / 2; i++)
35+
{
36+
swap(s[i], s[n - i - 1]);
37+
}
38+
return ;
5839
}
5940
};
6041

61-
62-
63-
6442
/* -----------------END OF PROGRAM --------------------*/
6543
/*
6644
* stuff you should look before submission

0 commit comments

Comments
 (0)