Skip to content

Commit 8e14d8d

Browse files
committed
leetcode 2218
1 parent ebbf31a commit 8e14d8d

File tree

3 files changed

+119
-0
lines changed

3 files changed

+119
-0
lines changed
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+
int solve(){
11+
int a, b;
12+
cin>>a>>b;
13+
vector<vector<int>> x(a+1,vector<int>(a+1,0));
14+
15+
for (int i = 1; i <= a; i++){
16+
for (int j = 1; j <= a; j++){
17+
cin>>x[i][j];
18+
}
19+
}
20+
21+
int sum = 0;
22+
for (int i = 1; i <= a; i++){
23+
for (int j = 1; j <= a; j++){
24+
if (x[i][j] != x[a - i + 1][a - j + 1]){
25+
sum++;
26+
}
27+
}
28+
}
29+
30+
sum /= 2;
31+
if(sum>b){
32+
cout<<"NO"<<endl;
33+
return 0;
34+
}
35+
b-=sum;
36+
if(a&1){
37+
cout<<"YES"<<endl;
38+
}
39+
// size of matrix -> even
40+
else if(b&1){
41+
cout<<"NO"<<endl;
42+
}
43+
else{
44+
cout << "YES" << endl;
45+
}
46+
return 0;
47+
}
48+
int main()
49+
{
50+
int testCase=1;
51+
cin>>testCase;
52+
while(testCase--){
53+
solve();
54+
}
55+
return 0;
56+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
long long k,a,b;
12+
cin >> a >> b;
13+
k = a + b;
14+
for (int i = 2; i <= 100000; i++)
15+
{
16+
k = min(k, (a + i - 1) / i + (b + i - 1) / i + i - 1);
17+
}
18+
cout << k << endl;
19+
return 0;
20+
}
21+
int main()
22+
{
23+
int testCase=1;
24+
cin>>testCase;
25+
while(testCase--){
26+
solve();
27+
}
28+
return 0;
29+
}
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 maxValueOfCoins(vector<vector<int>> &piles, int k)
15+
{
16+
int n=piles.size();
17+
vector<vector<int>> dp(n+1, vector<int>(k+1,0));
18+
19+
for(int noOfPiles=1;noOfPiles<=n;noOfPiles++){
20+
// noOfPiles -> currently aab tak itne pile select kiye coin lene ke liye
21+
for(int noOfCoin=1;noOfCoin<=k;noOfCoin++){
22+
// noOfCoin -> aab tak total itne coin select kiye
23+
dp[noOfPiles][noOfCoin]+=dp[noOfPiles-1][noOfCoin];
24+
int sum=0;
25+
for(int takeCoin=1;takeCoin<=min(noOfCoin,(int)piles[noOfPiles-1].size());takeCoin++){
26+
// takeCoin -> currect pile se itne coin select kiye
27+
sum += piles[noOfPiles - 1][takeCoin-1];
28+
dp[noOfPiles][noOfCoin] = max(dp[noOfPiles][noOfCoin], dp[noOfPiles - 1][noOfCoin - takeCoin] + sum);
29+
}
30+
}
31+
}
32+
return dp[n][k];
33+
}
34+
};

0 commit comments

Comments
 (0)