Блог пользователя I_m_sfg

Автор I_m_sfg, история, 5 месяцев назад, По-английски

You have an array of length n and can start at any index. In one operation, you can move either left, right, or stay at your position to pick the value arr[i].After picking the value, increase all the elements in the array by 1. Find the maximum sum you can get after performing k operations.

Полный текст и комментарии »

Теги c++, dp
  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

Автор I_m_sfg, история, 5 месяцев назад, По-английски

Hello coders!

I am very disappointed and frustrated after seeing today's rating on Codeforces. I don't remember the last time I saw 3k+ submissions on the 4th problem of a Div 2 contest. I don't think the 2nd and 3rd problems were easy compared to their solutions. I solved three questions in almost one hour, yet my rating only increased by 4 points.

Can you give me some tips on how to increase my speed on Codeforces (to avoid the cheating effect)?

Should I give up on becoming an expert?

Полный текст и комментарии »

Теги c++
  • Проголосовать: нравится
  • -17
  • Проголосовать: не нравится

Автор I_m_sfg, история, 6 месяцев назад, По-английски

Greetings to everyone, I am struggling with tabulation dp. I am solving the DP question by memorizing, but not all questions should be solved by memorizing, and memorizing adds an extra O(n) space. Please give me some resources and questions where I can learn tabular DP.

Полный текст и комментарии »

  • Проголосовать: нравится
  • +11
  • Проголосовать: не нравится

Автор I_m_sfg, история, 16 месяцев назад, По-английски

--if the question constraints is 10^18 and input is given in digit then never use stoi,atoi,or any kind of string into digit number because it gives always tle.

--Never Use stoi,atoi with to_string it also give tle .I wasted 1 hr to solve this problem.......so don't do that...and

Happy journey to _____ to master.

Полный текст и комментарии »

  • Проголосовать: нравится
  • +10
  • Проголосовать: не нравится

Автор I_m_sfg, история, 16 месяцев назад, По-английски

Hi, this side Imsfg. I used both map/unordered_map since long time. I observed some facts about about this special stl.

1- According to me use mp[i]==0 instead of mp.find(i) because let suppose you increase the value of mp[i]++.after that you decrease the same value mp[i]--. after u find mp.find(i). it show true but according to you this give 0 and does not exist in map. if you not understand what i am saying please see both code u can observed what i say. Case 1-use mp[i]==0 int longestKSubstr(string s, int k) {

int i=0,j=0;

    int cnt=0;

    int ans=-1;

    map<char,int>mp;

    while(i<s.size()){

        while(cnt>k and j<=i){

            mp[s[j]]--;

            if(mp[s[j]]==0){

                cnt--;

            }
            j++;

        }
        if(mp[s[i]]==0){

            cnt++;

        }
        if(cnt==k){

            ans=max(ans,i-j+1);

        }
        mp[s[i]]++;

        i++;

    }


    return ans;
}

Case 2- use mp.find(i)

    //User function template for C++

class Solution{

public:

int longestKSubstr(string s, int k) {


    int i=0,j=0;

    int cnt=0;

    int ans=-1;

    map<char,int>mp;

    while(i<s.size()){

        while(cnt>k and j<=i){

            mp[s[j]]--;

            if(mp[s[j]]==0){

                cnt--;

            }

            j++;

        }
        if(mp.find(s[i])==mp.end()){

            cnt++;

        }

        if(cnt==k){

            ans=max(ans,i-j+1);

        }

        mp[s[i]]++;

        i++;

    }

    return ans;

}

};

hopefully You understand what I am saying.....

Полный текст и комментарии »

  • Проголосовать: нравится
  • +3
  • Проголосовать: не нравится