Skip to content

Commit 23dda38

Browse files
committed
codeforces round
1 parent 009937a commit 23dda38

8 files changed

+862
-0
lines changed

Codeforces/1594C-Make_Them_Equal.cpp

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
Institute: National Institute of Technology, Uttarakhand
5+
*/
6+
#include <bits/stdc++.h>
7+
#include <ext/pb_ds/assoc_container.hpp>
8+
#include <ext/pb_ds/tree_policy.hpp>
9+
using namespace std;
10+
using namespace __gnu_pbds;
11+
typedef long long ll ;
12+
typedef vector<ll> vl;
13+
typedef vector<vector<ll>> vvl;
14+
#define speed cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
15+
/* Abbrevations */
16+
#define ff first
17+
#define ss second
18+
#define mp make_pair
19+
#define line cout<<endl;
20+
#define pb push_back
21+
// loops
22+
#define forin(arr,n) for(ll i=0;i<n;i++) cin>>arr[i];
23+
// Some print
24+
#define no cout<<"NO"<<endl;
25+
#define yes cout<<"YES"<<endl;
26+
// sort
27+
#define all(V) (V).begin(),(V).end()
28+
#define srt(V) sort(all(V))
29+
#define srtGreat(V) sort(all(V),greater<ll>())
30+
// some extra
31+
#define printv(v) for(ll i=0;i<ll(v.size());i++){cout<<v[i]<<" ";} line;
32+
#define precision(x) cout<<fixed<<setprecision(x);
33+
#define sz(V) ll(V.size())
34+
// datatype definination
35+
#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
36+
37+
38+
ll ppow(ll n, ll m, ll mod){
39+
if(m==0) return 1;
40+
ll tmp=ppow(n, m/2, mod);
41+
tmp=tmp*tmp%mod;
42+
return m%2 ? tmp*n%mod: tmp;
43+
}
44+
namespace mod_operations{
45+
ll modInv(ll n, ll mod){
46+
return ppow(n,mod-2, mod);
47+
}
48+
ll modAdd(ll n, ll m, ll mod){
49+
n=(n%mod+mod)%mod; m=(m%mod+mod)%mod;
50+
return (n+m)%mod;
51+
}
52+
ll modMul(ll n, ll m, ll mod){
53+
n=(n%mod+mod)%mod; m=(m%mod+mod)%mod;
54+
return n*m %mod;
55+
}
56+
ll modSub(ll n, ll m, ll mod){
57+
n=(n%mod+mod)%mod; m=(m%mod+mod)%mod;
58+
return modAdd(n,-m, mod);
59+
}
60+
ll modDiv(ll n, ll m, ll mod){
61+
return modMul(n, modInv(m, mod), mod);
62+
}
63+
}
64+
using namespace mod_operations;
65+
66+
67+
class Codeforces
68+
{
69+
private:
70+
// read only variable
71+
const ll INF=1e18;
72+
const ll mod1=1e9+7;
73+
const ll mod2=998244353;
74+
75+
76+
public:
77+
Codeforces(){
78+
79+
}
80+
81+
ll power(ll x,ll y){
82+
ll result=1;
83+
while(y>0){
84+
if(y&1){
85+
result*=x;
86+
}
87+
y>>=1;
88+
x*=x;
89+
}
90+
return result;
91+
}
92+
93+
ll power(ll x,ll y,ll mod){
94+
ll result=1;
95+
x%=mod;
96+
while(y>0){
97+
if(y&1){
98+
result*=x;
99+
result%=mod;
100+
}
101+
y>>=1;
102+
x*=x;
103+
x%=mod;
104+
}
105+
return result;
106+
}
107+
108+
ll str_to_num(string s)
109+
{
110+
stringstream pk(s);
111+
ll num;
112+
pk>>num;
113+
return num;
114+
}
115+
116+
string num_to_str(ll num)
117+
{
118+
return to_string(num);
119+
}
120+
// Techniques :
121+
// divide into cases, brute force, pattern finding
122+
// sort, greedy, binary search, two pointer
123+
// transform into graph
124+
125+
// Experience :
126+
// Cp is nothing but only observation and mathematics.
127+
ll solve()
128+
{
129+
ll n;
130+
char ch;
131+
cin>>n>>ch;
132+
string s;
133+
cin>>s;
134+
ll last=-1;
135+
for(ll i=1;i<n;i++){
136+
if(s[i-1]!=ch){
137+
last=i;
138+
}
139+
}
140+
if(s[n-1]!=ch){
141+
ll index=n-1;
142+
while(index>=0&&s[index]!=ch){
143+
index--;
144+
}
145+
if(index<0){
146+
cout<<"2\n"<<n<<" "<<n-1<<endl;
147+
}
148+
else{
149+
index++;
150+
if(index*2>n){
151+
cout<<"1\n"<<index<<endl;
152+
}
153+
else{
154+
cout<<"2\n"<<n<<" "<<n-1<<endl;
155+
}
156+
}
157+
}
158+
else{
159+
if(last==-1){
160+
cout<<0<<endl;
161+
}
162+
else{
163+
cout<<"1\n"<<n<<endl;
164+
}
165+
}
166+
return 0;
167+
}
168+
};
169+
170+
171+
/* --------------------MAIN PROGRAM----------------------------*/
172+
173+
int main()
174+
{
175+
speed;
176+
/* #ifndef ONLINE_JUDGE
177+
freopen("input.txt","r",stdin);
178+
freopen("output.txt","w",stdout);
179+
#endif */
180+
ll TestCase=1;
181+
cin>>TestCase;
182+
while(TestCase--)
183+
{
184+
Codeforces cf;
185+
cf.solve();
186+
}
187+
}
188+
/* -----------------END OF PROGRAM --------------------*/
189+
/*
190+
* stuff you should look before submission
191+
* constraint and time limit
192+
* int overflow
193+
* special test case (n=0||n=1||n=2)
194+
* don't get stuck on one approach if you get wrong answer
195+
*/

Codeforces/1598A-Computer_Game.cpp

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
Institute: National Institute of Technology, Uttarakhand
5+
*/
6+
#include <bits/stdc++.h>
7+
#include <ext/pb_ds/assoc_container.hpp>
8+
#include <ext/pb_ds/tree_policy.hpp>
9+
using namespace std;
10+
using namespace __gnu_pbds;
11+
typedef long long ll ;
12+
typedef vector<ll> vl;
13+
typedef vector<vector<ll>> vvl;
14+
#define speed cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
15+
/* Abbrevations */
16+
#define ff first
17+
#define ss second
18+
#define mp make_pair
19+
#define line cout<<endl;
20+
#define pb push_back
21+
// loops
22+
#define forin(arr,n) for(ll i=0;i<n;i++) cin>>arr[i];
23+
// Some print
24+
#define no cout<<"NO"<<endl;
25+
#define yes cout<<"YES"<<endl;
26+
// sort
27+
#define all(V) (V).begin(),(V).end()
28+
#define srt(V) sort(all(V))
29+
#define srtGreat(V) sort(all(V),greater<ll>())
30+
// some extra
31+
#define printv(v) for(ll i=0;i<ll(v.size());i++){cout<<v[i]<<" ";} line;
32+
#define precision(x) cout<<fixed<<setprecision(x);
33+
#define sz(V) ll(V.size())
34+
// datatype definination
35+
#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
36+
37+
38+
ll ppow(ll n, ll m, ll mod){
39+
if(m==0) return 1;
40+
ll tmp=ppow(n, m/2, mod);
41+
tmp=tmp*tmp%mod;
42+
return m%2 ? tmp*n%mod: tmp;
43+
}
44+
namespace mod_operations{
45+
ll modInv(ll n, ll mod){
46+
return ppow(n,mod-2, mod);
47+
}
48+
ll modAdd(ll n, ll m, ll mod){
49+
n=(n%mod+mod)%mod; m=(m%mod+mod)%mod;
50+
return (n+m)%mod;
51+
}
52+
ll modMul(ll n, ll m, ll mod){
53+
n=(n%mod+mod)%mod; m=(m%mod+mod)%mod;
54+
return n*m %mod;
55+
}
56+
ll modSub(ll n, ll m, ll mod){
57+
n=(n%mod+mod)%mod; m=(m%mod+mod)%mod;
58+
return modAdd(n,-m, mod);
59+
}
60+
ll modDiv(ll n, ll m, ll mod){
61+
return modMul(n, modInv(m, mod), mod);
62+
}
63+
}
64+
using namespace mod_operations;
65+
66+
67+
class Codeforces
68+
{
69+
private:
70+
// read only variable
71+
const ll INF=1e18;
72+
const ll mod1=1e9+7;
73+
const ll mod2=998244353;
74+
75+
76+
public:
77+
Codeforces(){
78+
79+
}
80+
81+
ll power(ll x,ll y){
82+
ll result=1;
83+
while(y>0){
84+
if(y&1){
85+
result*=x;
86+
}
87+
y>>=1;
88+
x*=x;
89+
}
90+
return result;
91+
}
92+
93+
ll power(ll x,ll y,ll mod){
94+
ll result=1;
95+
x%=mod;
96+
while(y>0){
97+
if(y&1){
98+
result*=x;
99+
result%=mod;
100+
}
101+
y>>=1;
102+
x*=x;
103+
x%=mod;
104+
}
105+
return result;
106+
}
107+
108+
ll str_to_num(string s)
109+
{
110+
stringstream pk(s);
111+
ll num;
112+
pk>>num;
113+
return num;
114+
}
115+
116+
string num_to_str(ll num)
117+
{
118+
return to_string(num);
119+
}
120+
// Techniques :
121+
// divide into cases, brute force, pattern finding
122+
// sort, greedy, binary search, two pointer
123+
// transform into graph
124+
125+
// Experience :
126+
// Cp is nothing but only observation and mathematics.
127+
ll solve()
128+
{
129+
ll n;
130+
cin>>n;
131+
string s1,s2;
132+
cin>>s1>>s2;
133+
for(ll i=0;i<n;i++){
134+
if(s1[i]=='1'&&s2[i]=='1'){
135+
no
136+
return 0;
137+
}
138+
}
139+
yes
140+
return 0;
141+
}
142+
};
143+
144+
145+
/* --------------------MAIN PROGRAM----------------------------*/
146+
147+
int main()
148+
{
149+
speed;
150+
/* #ifndef ONLINE_JUDGE
151+
freopen("input.txt","r",stdin);
152+
freopen("output.txt","w",stdout);
153+
#endif */
154+
ll TestCase=1;
155+
cin>>TestCase;
156+
while(TestCase--)
157+
{
158+
Codeforces cf;
159+
cf.solve();
160+
}
161+
}
162+
/* -----------------END OF PROGRAM --------------------*/
163+
/*
164+
* stuff you should look before submission
165+
* constraint and time limit
166+
* int overflow
167+
* special test case (n=0||n=1||n=2)
168+
* don't get stuck on one approach if you get wrong answer
169+
*/

0 commit comments

Comments
 (0)