returnA's blog

By returnA, history, 15 months ago, In English

 Keval has forgotten the password to his I-Pad. The password is a 4-digit number where each digit takes a value from 0 to 9. The good thing is that Keval remembers that his password had exactly two unique digits, and each of these digits appeared exactly twice in the password. Keval also remembers that n digits (where, 0 ≤ n ≤ 10) from 0-9 were definitely not used in the password.

Find the number of different possible passwords Keval could have. Note that the password can start with the digit 0

Input constraints 0 ≤ n ≤ 10

Input format The only line of input contains a single integer n, the number of digits which were not used in the password.

Output Format Output a single integer that denotes the number of possible password sequences.

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By returnA, history, 15 months ago, In English

Below is my code, don't know where is the error!

#include <bits/stdc++.h>
using namespace std;
int maxp(vector<vector<int>>& garden)
{
	int n = garden.size();
	int m = garden[0].size();

	vector<vector<int>> dp(n, vector<int>(m, 0));

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			if (garden[i][j] == -1)
			{
				dp[i][j] = (i > 0) ? dp[i - 1][j] : 0;
			}
			else
			{
				if (i == 0)
				{
					dp[i][j] = 1;
				}
				else
				{
					dp[i][j] = max((i > 0) ? dp[i - 1][j] : 0, (i > 1) ? dp[i - 2][j] : 0) + 1;
				}
			}
		}
	}

	int maxPlants = 0;
	for (int j = 0; j < m; j++)
	{
		maxPlants = max(maxPlants, dp[n - 1][j]);
	}

	return maxPlants;
}

int minp(vector<vector<int>> &garden)
{
	int n = garden.size();
	int m = garden[0].size();

	int count = 0;

	for (int i = 0; i < n; i++)
	{
		bool planted = false;
		for (int j = 0; j < m; j++)
		{
			if (garden[i][j] == 1 && (!planted || j == 0))
			{
				count++;
				planted = true;
			}
			else
			{
				planted = false;
			}
		}
	}

	return count;
}
void tate()
{
	int n, m;
	cin >> n >> m;
	vector<vector<int>> grid(n, vector<int>(m, 1));
	int broke;
	cin >> broke;
	while (broke--)
	{
		int x, y;
		cin >> x >> y;
		grid[x][y] = -1;
	}
	int ans1 = maxp(grid);
	int ans2 = minp(grid);
	cout << ans1 << ' ' << ans2;
}

signed main()
{
	int t = 1;
	// cin >> t;
	while (t--)
		tate();
	return 0;
}

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By returnA, history, 17 months ago, In English

Given two strings A and B(binary string) of size n, and an Integer K. Two types of operation available-

  1. Choose two indices i and j, flip both A[i], A[j]. Cost of this is K.

  2. Choose any adjacent pairs(A[i], A[i+1]) and flip both. Cost is 1.

Minimum no of operation to convert A to B. If not possible print Not possible.

Full text and comments »

  • Vote: I like it
  • +1
  • Vote: I do not like it