Jinwoo-Sung's blog

By Jinwoo-Sung, history, 11 months ago, In English

TO ALL MY STRONG CODER FRIENDS

Guys i was recently solving

Problem ---> 2106D - Flower Boy

I did solved it in O(n*m), that's brute force solution, however we are given t <= 10^4 and n <= 2 * 10 ^ 5, so we gotta solve it in O(n log(x)) or better, however i feel it very less intutive to think of binary search in this problem ._.

Can anyone please recommend me approach ?

Full text and comments »

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

By Jinwoo-Sung, history, 11 months ago, In English

TO ALL MY STRONG PROGRAMMING FRIENDS

Hi Guys , i was just upsolving

Contest ---> Codeforces Round 1022 (Div. 2)

Problem ---> 2108C - Neo's Escape

After a grind of an hour i thought of an approach that does the work as shown below,

void solve(){
    LL n , clones = 0;
    cin >> n;
    vector<LL>a(n);
    priority_queue<pair<LL,LL>>pq;
    for(LL l = 0;l < n; l++) {
        cin >> a[l];
        pq.push({a[l] , l});
    }

    vector<bool>pressed(n , false); // not pressed
    vector<LL>clone(n , 0); // 0 means no clone 

    while(!pq.empty()){
        pair<LL,LL> p = pq.top();
        pq.pop();
        LL j = p.second;
        bool t = false;

        for(LL l = j+1; l < n; l++){
            if(!pressed[l]) break;
            if(pressed[l] && clone[l] == 1) {
                clone[j] = 1;
                clone[l] = 0;
                pressed[j] = true;
                t = true;
            }
        }

        if(!t){
            for(LL l = j-1; l >= 0; l--){
                if(!pressed[l]) {
                    if(a[l] != p.first) break;
                }
                if(pressed[l] && clone[l] == 1) {
                    clone[j] = 1;
                    clone[l] = 0;
                    pressed[j] = true;
                }
            }
        }

        if(!pressed[j]){
            clones++;
            pressed[j] = true;
            clone[j] = 1;
        }
    }

    cout << clones << endl;
}

I got struck by TLE, can anyone help me optimize it, any suggestion or advice is highly appreciated :)

Full text and comments »

  • Vote: I like it
  • -15
  • Vote: I do not like it

By Jinwoo-Sung, history, 11 months ago, In English

TO ALL GOOD CODERS PLEASE HELP ME OUT

Hey guys, i have spent way too much time on upsolving this problem but i cant get what i am doing wrong

Problem --> 2109D - D/D/D

My code --> `void dfs(int x , vector &visited , vector<vector>&adj , string &res , int &count , int &j){ if(count > j) return; if(count % 2 == j % 2) res[x-1] = '1'; visited[x] = true;

for(int neighbour : adj[x]){
    if(!visited[neighbour]){
        count++;
        dfs(neighbour , visited , adj ,res , count , j);
    }
}

}

void solve(){ int n , m , l; cin >> n >> m >> l;

string res(n , '0');

vector<vector<int>>adj(n+1);
vector<int>a(l);
vector<int>visited(n , false);

//* members of multiset
for(int k = 0; k < l; k++){
    cin >> a[k];
}

//* adj list
for(int k =0 ; k < m; k++){
    int u , v;
    cin >> u >> v;

    adj[u].pb(v);
    adj[v].pb(u);
}


res[0] = '1';
for(int k = 0; k < l; k++){
    int count = 0, j = a[k];
    dfs(1 , visited , adj ,res , count , j);
}

cout << res << endl;

}

int main(){ int t; cin >> t;

while(t--){
    solve();
}

}`

Full text and comments »

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