yash_daga's blog

By yash_daga, history, 2 months ago, In English

We invite you to participate in CodeChef’s Starters 155, this Wednesday, 9th October, rated upto 5 stars (i.e. for users with rating < 2200)

Time: 8:00 PM — 10:00 PM IST

Joining us on the problem setting panel are:

Written editorials will be available for all on discuss.codechef.com. Pro users can find the editorials directly on the problem pages after the contest. The video editorials of the problems will be available only to Pro users.

Also, if you have some original and engaging problem ideas, and you’re interested in them being used in CodeChef's contests, you can share them here. Hope to see you participating.

Good Luck!

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

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

The contest starts in around ~15 minutes.

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

What wrong with this Replace With First's logic ?

#include <bits/stdc++.h>
using namespace std;

int main() {
    int tt;
    cin >> tt;
    
    while (tt--) {
        int n, m;
        cin >> n >> m;
        
        string s, t;
        cin >> s >> t;
        
        if (s == t) {
            cout << 0 << endl;
            continue;
        } else if (s[0] != t[0]) {
            cout << -1 << endl;
            continue;
        } else {
            int flag = 0;
            for (int i = 0; i < min(n, m); i++) {
                if (s[i] != t[i]) {
                    flag = 1;
                    break;
                }
            }
            if (flag == 0) {
                cout << 1 << endl;
            } else {
                cout << 2 << endl;
            }
        }
    }
    return 0;
}
  • »
    »
    2 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    lets say s== lion, t = lioeeeeeeen we can make do o-> oeeeeeee in 1 operation but your code will give 2

  • »
    »
    2 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    i wrote the same logic but it wasn't working, I wanna know why so bad

    • »
      »
      »
      2 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      You can remove an internal substring from the larger string to make it equal to the smaller string, that would take just one move too.

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

why is in gcd(hard) question, printing matrix with all number as 2 is wrong?

  • »
    »
    2 months ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    maybe because any row and column gcd will be 2 ??

  • »
    »
    2 months ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    Gcd should be 1 and not 2 in each row and column; printing 1 would make gcd 2; you should atleast look the given test cases

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

I have a question for those who solved problem Div1C (Div2D) Prefix Suffix Min Max ,

How did u figured out the solution ? did u solve almost similar problem before or solved it just now ?

  • »
    »
    2 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    It is a standard mathematical problem solved after the contest but i got WA when i took a[0] = 4 and when i chahged it to 2e6 it got AC .....

    Idk in java it gave tle but in C++ it gives Ac

  • »
    »
    2 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    just assume a[0] to be the max element

  • »
    »
    2 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    solved for the first time.

    logic : If the first element is max, then the sum of next elements till i will be b[i]
    
    -> a[1]=b[1], a[2]=b[2]-b[1] .... a[i]=b[i]-b[i-1]
    

    -> a[0]=max(a[1]....a[n-1]) or 2000000

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

i liked array concatenation (although could not solve in contest)

  • »
    »
    2 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    was an easy observation u should have considered different cases

    • »
      »
      »
      2 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it
      • i got the logic but i don't know how calculate nCx.
      • how to calculate nCx ? , modular operation may not be valid for divisions right?