Comments
+13

For Problem F ; You can use SOS DP. Question Statement changed : We need to find out 2 substrings such that they contain different letters and are non overlapping.

If we were to consider the strings as integers, where each character represents a bit ( where in set bit means that, the character is present ). For eg : binary for ac would be 101. Now you need to form all such numbers(strings which cannot have length more than 20, as then it would for sure contain a repeat).So insert all the strings starting at one position without having any repeated character. And then you need to check for each number whether it has a subset of its complement. We will consider the subset having the maximum number of set bits, which can be found out by simple SOS DP. Link to the solution : Using long long int (not required) : it may give tle as this solution : https://codeforces.me/contest/1234/submission/61652445 Using int : https://codeforces.me/contest/1234/submission/61743609

0

Great ;p

+12

No it is not my assumption. Very simply, you can compare the memory of both of my solutions. Why open the documentation when you can code... LOL.

map < int,int > mark;
mark[1] = 2;
cout << mark.size() << endl;
int val = mark[0];
cout << mark.size() << endl;

Output :

1

2

+13

DP Solution for Problem E

DP state : (node, cur, par)

node -> The index of the node

cur ( 0 or 1 ) -> Whether the given node either has or is supplied with an extra edge connecting it to the root

par ( 0 or 1 ) -> Whether the parent of the given node either has or is supplied with an extra edge connecting it to the root

Now 3 cases arise :

cur:1 -> sum over all children {min(solve(child,1,1) + 1, solve(child,0,1))}

cur:0 par:1 -> In this case the current node has a path of length 2 to the root by going to its parent and then from parent to the root. sum over all children {min(solve(child,1,0) + 1, solve(child,0,0))}

cur:0 par:0 -> This is the most important case. Main Point : This node doesn't have a path of length atmost 2 to the root, so it has to make use of ATLEAST 1 of its children*

Case 1: Leaf node -> You need to make an edge straight from here to the root. ans =1

Case 2: Internal node -> Select atleast one child from which you will make a direct edge to the root. Code for this :

vector < pii > vec;
int sum = 0,idx = 0;
for ( auto child : adj[node] )
{
    vec.pb({solve(solve(child,1,0)+1,solve(child,0,0)});
    sum += min(vec[idx].first,vec[idx].second);idx++;
}
int ans = INT_MAX;
for ( auto child : vec )
    ans = min(ans,sum+child.first-min(child.first,child.second);
+1

http://codeforces.me/blog/entry/61399?#comment-453807 . Hopefully this comment of mine helps you to get an AC by using map only.

+54

For Problem D — TLE issue

People here find the Time limit strict ( even I did ) , but actually it isn't that strict. The only issue while using map which almost everyone is facing is :

If u simply do ans += mark[digits][requiredmod]; then even though that required mod doesn't exist in the map, then also it will be added to that map and now the size of the map = (actualsize+1), and if you do this n*10 times the size of the map would increase and therefore the time to search as well

So what u need to do is first search whether that element is present in the map and then add it to the answer, as shown below :

if ( mark[digits].find(requiredmod)!=mark[digits].end() ) ans += mark[digits][requiredmod];

This is the only difference in my accepted and TLE solution.

Accepted Solution : http://codeforces.me/contest/1029/submission/42081763 TLE Solution : http://codeforces.me/contest/1029/submission/42082128

Absolutely Perfect.

When will the list of winners of championship souvenirs be published ?

Why is rating predictor not working ?

this happened because someone hacked it before u and was waiting in the queue for a longer time than u were. u didnt get negative because the problem was already hacked by someone else before so ur hack was not taken into consideration