Skip to content

Commit b69f1b5

Browse files
committed
weekly contest
1 parent 2b2a88b commit b69f1b5

File tree

6 files changed

+130
-0
lines changed

6 files changed

+130
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
int solve()
10+
{
11+
string a, b;
12+
cin >> a >> b;
13+
reverse(a.begin(), a.end());
14+
reverse(b.begin(), b.end());
15+
int pos = 0;
16+
for (int i = 0; i < b.size(); i++)
17+
{
18+
if (b[i] == '1')
19+
{
20+
while (pos < a.size())
21+
{
22+
if (pos >= i && a[pos] == '1')
23+
{
24+
cout << abs(i - pos) << endl;
25+
return 0;
26+
}
27+
pos++;
28+
}
29+
}
30+
}
31+
cout << 0 << endl;
32+
return 0;
33+
}
34+
int main()
35+
{
36+
int testCase = 1;
37+
cin >> testCase;
38+
while (testCase--)
39+
{
40+
solve();
41+
}
42+
return 0;
43+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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 n,k;
12+
cin>>n>>k;
13+
vector<int> v1(n,0),v2(n,0);
14+
for(int i=0;i<n;i+=k){
15+
v1[i]++;
16+
}
17+
for(int i=n-1;i>=0;i-=k){
18+
v2[i]++;
19+
}
20+
int count=0;
21+
for(int i=0;i<n;i++){
22+
if(v1[i]>0 || v2[i]>0){
23+
count++;
24+
}
25+
int req=(i+k)/k;
26+
if(count>req&&v1[i]>0){
27+
v1[i]=0;
28+
}
29+
}
30+
int ans=0;
31+
for(int i=0;i<n;i++){
32+
if(v1[i]>0 || v2[i]>0){
33+
ans++;
34+
}
35+
}
36+
cout<<ans<<endl;
37+
return 0;
38+
}
39+
int main()
40+
{
41+
int testCase=1;
42+
cin>>testCase;
43+
while(testCase--){
44+
solve();
45+
}
46+
return 0;
47+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
long long matrixSumQueries(int n, vector<vector<int>> &queries)
15+
{
16+
set<int> r, c;
17+
reverse(queries.begin(), queries.end());
18+
long long ans = 0;
19+
for (auto it : queries)
20+
{
21+
if (it[0] == 0)
22+
{
23+
if (r.find(it[1]) == r.end())
24+
{
25+
ans += (n - c.size()) * it[2];
26+
r.insert(it[1]);
27+
}
28+
}
29+
else
30+
{
31+
if (c.find(it[1]) == c.end())
32+
{
33+
ans += (n - r.size()) * it[2];
34+
c.insert(it[1]);
35+
}
36+
}
37+
}
38+
return ans;
39+
}
40+
};

0 commit comments

Comments
 (0)