Skip to content

Commit 5fe0850

Browse files
committed
cf educational round 99
1 parent f4612af commit 5fe0850

4 files changed

+371
-0
lines changed
+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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+
typedef vector<ll> vl;
9+
#define pan cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
10+
// define values.
11+
// #define mod 1000000007
12+
#define phi 1.618
13+
/* Abbrevations */
14+
#define ff first
15+
#define ss second
16+
#define mp make_pair
17+
#define line cout<<endl;
18+
#define pb push_back
19+
#define Endl "\n"
20+
// loops
21+
#define forin(arr,n) for(ll i=0;i<n;i++) cin>>arr[i];
22+
// Some print
23+
#define no cout<<"NO"<<endl;
24+
#define yes cout<<"YES"<<endl;
25+
#define cc ll test;cin>>test;while(test--)
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+
#define printv(v) for(ll i=0;i<ll(v.size());i++){cout<<v[i]<<" ";} line;
31+
/* ONLINE JUDGE */
32+
// #ifndef ONLINE_JUDGE
33+
// freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
34+
// #endif
35+
// function
36+
37+
ll power(ll x,ll y,ll mod)
38+
{
39+
ll res=1;
40+
// x=x%mod;
41+
while(y>0)
42+
{
43+
if(y%2==1)
44+
{
45+
res*=x;
46+
// res=res%mod;
47+
}
48+
y/=2; x*=x; // x=x%mod;
49+
}
50+
return res;
51+
}
52+
// datatype definination
53+
#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
54+
55+
/* ascii value
56+
A=65,Z=90,a=97,z=122
57+
*/
58+
/* -----------------------------------------------------------------------------------*/
59+
60+
ll solve()
61+
{
62+
string s;
63+
cin>>s;
64+
cout<<ll(s.size())<<endl;
65+
return 0;
66+
}
67+
68+
int main()
69+
{
70+
pan;
71+
//freopen("input.txt"a, "r", stdin);
72+
// solve();
73+
cc
74+
{
75+
solve();
76+
}
77+
}
78+
79+
/* stuff you should look before submission
80+
* int overflow
81+
* special test case (n=0||n=1||n=2)
82+
* don't get stuck on one approach if you get wrong answer
83+
*/

codeforces/1455B-Jumps.cpp

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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+
typedef vector<ll> vl;
9+
#define pan cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
10+
// define values.
11+
// #define mod 1000000007
12+
#define phi 1.618
13+
/* Abbrevations */
14+
#define ff first
15+
#define ss second
16+
#define mp make_pair
17+
#define line cout<<endl;
18+
#define pb push_back
19+
#define Endl "\n"
20+
// loops
21+
#define forin(arr,n) for(ll i=0;i<n;i++) cin>>arr[i];
22+
// Some print
23+
#define no cout<<"NO"<<endl;
24+
#define yes cout<<"YES"<<endl;
25+
#define cc ll test;cin>>test;while(test--)
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+
#define printv(v) for(ll i=0;i<ll(v.size());i++){cout<<v[i]<<" ";} line;
31+
/* ONLINE JUDGE */
32+
// #ifndef ONLINE_JUDGE
33+
// freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
34+
// #endif
35+
// function
36+
37+
ll power(ll x,ll y,ll mod)
38+
{
39+
ll res=1;
40+
// x=x%mod;
41+
while(y>0)
42+
{
43+
if(y%2==1)
44+
{
45+
res*=x;
46+
// res=res%mod;
47+
}
48+
y/=2; x*=x; // x=x%mod;
49+
}
50+
return res;
51+
}
52+
// datatype definination
53+
#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
54+
55+
/* ascii value
56+
A=65,Z=90,a=97,z=122
57+
*/
58+
/* -----------------------------------------------------------------------------------*/
59+
ll maxo=1e6+5;
60+
vl dp(maxo+1,0);
61+
62+
ll solve()
63+
{
64+
ll x;
65+
cin>>x;
66+
cout<<dp[x]<<endl;
67+
return 0;
68+
}
69+
70+
int main()
71+
{
72+
pan;
73+
//freopen("input.txt"a, "r", stdin);
74+
// solve();
75+
ll pos=1,temp=1;
76+
while(pos<=1000000)
77+
{
78+
dp[pos]=temp;
79+
dp[pos-1]=temp+1;
80+
dp[pos+1]=temp+1;
81+
temp++;
82+
pos+=temp;
83+
}
84+
for(ll i=2;i<=maxo;i++)
85+
{
86+
if(dp[i]==0)
87+
dp[i]=dp[i-1];
88+
}
89+
cc
90+
{
91+
solve();
92+
}
93+
}
94+
95+
/* stuff you should look before submission
96+
* int overflow
97+
* special test case (n=0||n=1||n=2)
98+
* don't get stuck on one approach if you get wrong answer
99+
*/

codeforces/1455C-Ping-pong.cpp

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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+
typedef vector<ll> vl;
9+
#define pan cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
10+
// define values.
11+
// #define mod 1000000007
12+
#define phi 1.618
13+
/* Abbrevations */
14+
#define ff first
15+
#define ss second
16+
#define mp make_pair
17+
#define line cout<<endl;
18+
#define pb push_back
19+
#define Endl "\n"
20+
// loops
21+
#define forin(arr,n) for(ll i=0;i<n;i++) cin>>arr[i];
22+
// Some print
23+
#define no cout<<"NO"<<endl;
24+
#define yes cout<<"YES"<<endl;
25+
#define cc ll test;cin>>test;while(test--)
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+
#define printv(v) for(ll i=0;i<ll(v.size());i++){cout<<v[i]<<" ";} line;
31+
/* ONLINE JUDGE */
32+
// #ifndef ONLINE_JUDGE
33+
// freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
34+
// #endif
35+
// function
36+
37+
ll power(ll x,ll y,ll mod)
38+
{
39+
ll res=1;
40+
// x=x%mod;
41+
while(y>0)
42+
{
43+
if(y%2==1)
44+
{
45+
res*=x;
46+
// res=res%mod;
47+
}
48+
y/=2; x*=x; // x=x%mod;
49+
}
50+
return res;
51+
}
52+
// datatype definination
53+
#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
54+
55+
/* ascii value
56+
A=65,Z=90,a=97,z=122
57+
*/
58+
/* -----------------------------------------------------------------------------------*/
59+
60+
ll solve()
61+
{
62+
ll x,y;
63+
cin>>x>>y;
64+
if(x>0)
65+
x--;
66+
cout<<x<<" "<<y<<endl;
67+
return 0;
68+
}
69+
70+
int main()
71+
{
72+
pan;
73+
//freopen("input.txt"a, "r", stdin);
74+
// solve();
75+
cc
76+
{
77+
solve();
78+
}
79+
}
80+
81+
/* stuff you should look before submission
82+
* int overflow
83+
* special test case (n=0||n=1||n=2)
84+
* don't get stuck on one approach if you get wrong answer
85+
*/
+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
#include <bits/stdc++.h>
6+
#include <ext/pb_ds/assoc_container.hpp>
7+
#include <ext/pb_ds/tree_policy.hpp>
8+
using namespace std;
9+
using namespace __gnu_pbds;
10+
typedef long long ll ;
11+
typedef vector<ll> vl;
12+
#define speed cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
13+
// define values.
14+
// #define mod 1000000007
15+
#define phi 1.618
16+
/* Abbrevations */
17+
#define ff first
18+
#define ss second
19+
#define mp make_pair
20+
#define line cout<<endl;
21+
#define pb push_back
22+
#define Endl "\n"
23+
// loops
24+
#define forin(arr,n) for(ll i=0;i<n;i++) cin>>arr[i];
25+
// Some print
26+
#define no cout<<"NO"<<endl;
27+
#define yes cout<<"YES"<<endl;
28+
#define cc ll test;cin>>test;while(test--)
29+
// sort
30+
#define all(V) (V).begin(),(V).end()
31+
#define srt(V) sort(all(V))
32+
#define srtGreat(V) sort(all(V),greater<ll>())
33+
#define printv(v) for(ll i=0;i<ll(v.size());i++){cout<<v[i]<<" ";} line;
34+
/* ONLINE JUDGE */
35+
// #ifndef ONLINE_JUDGE
36+
// freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
37+
// #endif
38+
// function
39+
40+
ll power(ll x,ll y,ll mod)
41+
{
42+
ll res=1;
43+
// x=x%mod;
44+
while(y>0)
45+
{
46+
if(y%2==1)
47+
{
48+
res*=x;
49+
// res=res%mod;
50+
}
51+
y/=2; x*=x; // x=x%mod;
52+
}
53+
return res;
54+
}
55+
// datatype definination
56+
#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
57+
58+
/* ascii value
59+
A=65,Z=90,a=97,z=122
60+
*/
61+
/* -----------------------------------------------------------------------------------*/
62+
63+
ll solve()
64+
{
65+
ll n,x;
66+
cin>>n>>x;
67+
vl v(n);
68+
forin(v,n);
69+
ll i=0,ans=0;
70+
while(i<n)
71+
{
72+
if(v[i]<=x)
73+
{
74+
i++;
75+
continue;
76+
}
77+
if(is_sorted(all(v))) break;
78+
swap(v[i],x);
79+
ans++;
80+
i++;
81+
}
82+
if(is_sorted(all(v)))
83+
cout<<ans<<endl;
84+
else
85+
cout<<-1<<endl;
86+
return 0;
87+
}
88+
89+
int main()
90+
{
91+
speed;
92+
//freopen("input.txt"a, "r", stdin);
93+
// solve();
94+
cc
95+
{
96+
solve();
97+
}
98+
}
99+
100+
/* stuff you should look before submission
101+
* int overflow
102+
* special test case (n=0||n=1||n=2)
103+
* don't get stuck on one approach if you get wrong answer
104+
*/

0 commit comments

Comments
 (0)