Day 2: Keeping It On Despite The Imperfect

Keeping It On Despite The Imperfect

I always would have not posted if my day went like Day 2 yesterday did.

But today in the morning, I realized the goal wasn’t to make this a perfect roadmap.

It is to make it real.

Not study DSA for 2 hours and SQL for 1 and then do Aptitude and other core subjects too.

That sounds good to believe but doesn’t work out.

At least not for me.

Yesterday, I solved 1 CP question that took me an hour.

It was an easy-rated problem; I solved it with DP at first, it got there, and then when I saw the suggested solution in editorials, it was fairly more mathematical, just carefully thought parity checks.

https://codeforces.com/problemset/problem/1845/A

It took me two wrong answers and some AI nudging to get here

My Solution [Click to Expand]
#include <iostream>
#include<vector>
using namespace std;
bool isPossible(int n, int k, int x) {
    int countANO = 0;
    for(int i = 1; i <=k; i++) {
        if(i!=x) {
            countANO++;
        }
    }
    if(countANO==0)return false;
    if(n%2!=0) {
        for(int i =1; i <= k; i++) {
            if(i!=x && i %2!=0) {
                return true;
            }
        }
    } else {
        return true;
    }
    return false;
}
bool dfs(int index,int running_sum, int n, int k, int x, vector<int>&res,vector<vector<int>>&dp) {
    if(running_sum>n)return false;
    if(running_sum==n)return true;
    if(index>k)return false;
    if(dp[index][running_sum]!=-1) {
        return dp[index][running_sum];
    }
    bool notPick = dfs(index+1, running_sum, n, k, x, res, dp); 
    if(notPick) {
        return dp[index][running_sum] =true;
    }
    bool pick = false;
    if(index!=x) {
        res.push_back(index);
        pick = dfs(index, running_sum+index, n, k, x, res,dp);
        if(!pick)res.pop_back();
    }
    return dp[index][running_sum] = pick||notPick;
}
void printMSeq(int n, int k, int x) {
    if(k==n&&x!=n) {
        cout<<1<<endl<<n<<endl;
        return;
    }
    vector<int> res;
    vector<vector<int>> dp(k+1, vector<int>(n,-1));
    dfs(1,0,n, k, x, res,dp);
    
    cout<<res.size()<<endl;
    for(int r: res) {
        cout<<r<<" ";
    }
    cout<<endl;
}
int main()
{
    int t;
    cin>>t;
    while(t--) {
        int n, k, x;
        cin>>n>>k>>x;
        if(isPossible(n,k,x)) {
            cout<<"YES"<<endl;
            printMSeq(n, k, x);
        } else {
            cout<<"NO"<<endl;
        }
    }
    return 0;
}
The Optimized Solution [Click to Expand]
#include <iostream>
using namespace std;
 
int main()
{
    int t;
    cin>>t;
    while(t--) {
        int n, k, x;
        cin>>n>>k>>x;
        if(x!=1){
            cout<<"YES"<<endl;
            cout<<n<<endl;
            for(int i =0; i<n;i++) {
                cout<<1<<" ";
            }cout<<endl;
        } else {
            if(n%2 == 0) {
                if(k<2){
                    cout<<"NO"<<endl;
                } else {
                    cout<<"YES"<<endl;
                    cout<<n/2<<endl;
                    while(n) {
                        n=n-2;
                        cout<<2<<" ";
                    }
                    cout<<endl;
                }
            } else {
                if(k < 3) {
                    cout<<"NO"<<endl;
                } else {
                    cout<<"YES"<<endl;
                    n = n-3;
                    cout<<(n/2)+1<<endl;
                    cout<<3<<" ";
                    while(n) {
                        n=n-2;
                        cout<<2<<" ";
                    }
                    cout<<endl;
                }
            }
        }
    }
    return 0;
}

After that, I solved 4 SQL query questions; they were a little harder than the Day 1 questions.

And I also gave a 30 min Aptitude test of 20 questions.

Got 11/20 [I know it’s bad]

I’ll upsolve the questions I couldn’t

And then I am working on a karaoke platform in Java Spring Boot + Next js as my personal project worked on that.

That’s it. I know it’s less than planned, but that’s how it went.

Leave a Reply