Skip to content

Commit 6f5e501

Browse files
committed
cf div 2 round
1 parent 2dfc874 commit 6f5e501

34 files changed

+3205
-0
lines changed

LeetCode/practice/120.Triangle.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public:
3+
int minimumTotal(vector<vector<int>>& triangle) {
4+
int n=triangle.size();
5+
vector<vector<int>> dp(n,vector<int>(n,0));
6+
for(int i=n-1;i>=0;i--)
7+
{
8+
for(int j=0;j<=i;j++)
9+
{
10+
if(i==n-1)
11+
dp[i][j]=triangle[i][j];
12+
else
13+
dp[i][j]=min(dp[i+1][j+1],dp[i+1][j])+triangle[i][j];
14+
}
15+
}
16+
return dp[0][0];
17+
}
18+
};

LeetCode/practice/91.Decode_Ways.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
public:
3+
int numDecodings(string s) {
4+
if(s[0]=='0')
5+
return 0;
6+
int n=s.size();
7+
vector<int> dp(n+1,0);
8+
dp[0]=1;
9+
dp[1]=1;
10+
for(int i=2;i<=n;i++)
11+
{
12+
int ones=int(s[i-1]-'0');
13+
int tens=int (s[i-2]-'0');
14+
int nums=(tens*10)+ones;
15+
if(ones>0)
16+
dp[i]=dp[i-1];
17+
if(nums>0&&tens!=0&&nums<=26)
18+
dp[i]+=dp[i-2];
19+
}
20+
return dp[n];
21+
}
22+
};
File renamed without changes.
File renamed without changes.

Spoj/practice/a.out

48.6 KB
Binary file not shown.
+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
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+
// some extra
35+
#define sz(V) ll(V.size())
36+
/* ONLINE JUDGE */
37+
// #ifdef ONLINE_JUDGE
38+
// freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
39+
// #endif
40+
// function
41+
42+
ll power(ll x,ll y,ll mod)
43+
{
44+
ll res=1;
45+
// x=x%mod;
46+
while(y>0)
47+
{
48+
if(y%2==1)
49+
{
50+
res*=x;
51+
// res=res%mod;
52+
}
53+
y/=2; x*=x; // x=x%mod;
54+
}
55+
return res;
56+
}
57+
ll str_to_num(string s)
58+
{
59+
return stoi(s);
60+
}
61+
62+
string num_to_str(ll num)
63+
{
64+
return to_string(num);
65+
}
66+
// datatype definination
67+
#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
68+
69+
/* ascii value
70+
A=65,Z=90,a=97,z=122
71+
*/
72+
/* -----------------------------------------------------------------------------------*/
73+
74+
ll solve()
75+
{
76+
ll flag=0,n;
77+
cin>>n;
78+
string ans="";
79+
while(n%7!=0&&n>0)
80+
{
81+
n-=4;
82+
ans+='4';
83+
}
84+
if(n==0)
85+
{
86+
cout<<ans<<Endl;
87+
return 0;
88+
}
89+
else if(n%7==0)
90+
{
91+
while(n%7==0&&n>0)
92+
{
93+
ans+='7';
94+
n-=7;
95+
}
96+
cout<<ans<<endl;
97+
}
98+
else
99+
cout<<-1<<endl;
100+
return 0;
101+
}
102+
103+
int main()
104+
{
105+
speed;
106+
// freopen("input.txt","r",stdin);
107+
// freopen("output.txt","w",stdout);
108+
solve();
109+
// cc
110+
// {
111+
// solve();
112+
// }
113+
}
114+
115+
/* stuff you should look before submission
116+
* int overflow
117+
* special test case (n=0||n=1||n=2)
118+
* don't get stuck on one approach if you get wrong answer
119+
*/
+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
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+
// some extra
35+
#define sz(V) ll(V.size())
36+
/* ONLINE JUDGE */
37+
// #ifdef ONLINE_JUDGE
38+
// freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
39+
// #endif
40+
// function
41+
42+
ll power(ll x,ll y,ll mod)
43+
{
44+
ll res=1;
45+
// x=x%mod;
46+
while(y>0)
47+
{
48+
if(y%2==1)
49+
{
50+
res*=x;
51+
// res=res%mod;
52+
}
53+
y/=2; x*=x; // x=x%mod;
54+
}
55+
return res;
56+
}
57+
ll str_to_num(string s)
58+
{
59+
return stoi(s);
60+
}
61+
62+
string num_to_str(ll num)
63+
{
64+
return to_string(num);
65+
}
66+
// datatype definination
67+
#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
68+
69+
/* ascii value
70+
A=65,Z=90,a=97,z=122
71+
*/
72+
/* -----------------------------------------------------------------------------------*/
73+
74+
ll solve()
75+
{
76+
ll n,m;
77+
cin>>n>>m;
78+
ll count=0;
79+
vector<vector<char>> v(n,vector<char>(m));
80+
for(ll i=0;i<n;i++)
81+
{
82+
for(ll j=0;j<m;j++)
83+
{
84+
cin>>v[i][j];
85+
}
86+
}
87+
for(ll i=0;i<n;i++)
88+
{
89+
for(ll j=0;j<m;j++)
90+
{
91+
if(v[i][j]=='W')
92+
{
93+
if(j-1>=0&&v[i][j-1]=='P')
94+
{
95+
v[i][j-1]='.';
96+
count++;
97+
}
98+
else if(j+1<m&&v[i][j+1]=='P')
99+
{
100+
v[i][j+1]='.';
101+
count++;
102+
}
103+
else if(i-1>=0&&v[i-1][j]=='P')
104+
{
105+
v[i-1][j]='.';
106+
count++;
107+
}
108+
else if(i+1<n&&v[i+1][j]=='P')
109+
{
110+
v[i+1][j]='.';
111+
count++;
112+
}
113+
}
114+
}
115+
}
116+
cout<<count<<endl;
117+
return 0;
118+
}
119+
120+
int main()
121+
{
122+
speed;
123+
// freopen("input.txt","r",stdin);
124+
// freopen("output.txt","w",stdout);
125+
solve();
126+
}
127+
128+
/* stuff you should look before submission
129+
* int overflow
130+
* special test case (n=0||n=1||n=2)
131+
* don't get stuck on one approach if you get wrong answer
132+
*/

0 commit comments

Comments
 (0)