Please subscribe to the official Codeforces channel in Telegram via the link https://t.me/codeforces_official. ×

sebi420p's blog

By sebi420p, history, 4 years ago, In English

Hello, everyone.

I am organizing my first contest and I would really appreciate your feedback. All the details about the contest are on the sign-up page. A rough estimate of the difficulties of the tasks would be [800-2000]. Solutions are accepted only in C++. Feel free to ask any questions in the comment section or via a private talk.

UPD1: I added java, C and python.

UPD2: Thank you for attending and congratulations to everybody! I am eager to hear your impressions.

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

| Write comment?
»
4 years ago, # |
  Vote: I like it +33 Vote: I do not like it

If its through hackkerank, why only cpp?

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +28 Vote: I do not like it

    Agreed, all the infrastructure is there for you to allow Java + other languages, so why the arbitrary restriction?

  • »
    »
    4 years ago, # ^ |
    Rev. 5   Vote: I like it +5 Vote: I do not like it

    I am not experienced enough to set proper time/memory limits for other languages. Better safe than sorry.

    UPD1: I added java, C and python.

    UPD2: I tried my best to set adequate time/memory limits

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

      Hey, I have a doubt in the first question. We have been given an array of speed and we choose two horses for a race in such a way that the absolute difference between their speed is as small as possible. Then we need two return an array of index of horses which wins the race. Is my understanding correct??

      If it is correct, then consider this test case: N = 6 speed = [90, 92, 93, 95, 96, 98] Currently, least difference is 1 so we select the pairs (92,93),(95,96) for the first two selection. For the third race, we select the pair(90,98). Hence, my answer is (3,5,6). The editorial code answer is (2,4,6).

      Can you tell me where I am going wrong??

      • »
        »
        »
        »
        4 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Now i realize that i wasn't clear enough with the statement. In your example you should first take care of the horse with the speed 90 and pair it with the horse 92.

        • »
          »
          »
          »
          »
          4 years ago, # ^ |
            Vote: I like it +3 Vote: I do not like it

          No problem ;) The problems are good!!

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

what are the prizes?

»
4 years ago, # |
  Vote: I like it +3 Vote: I do not like it

Good questions. In 3rd question, why my Binary indexed tree approach gives TLE? Question MySolution

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

    You don't take into account the case when one given number is equal to 0. You can just skip those zeroes:)

»
4 years ago, # |
  Vote: I like it +4 Vote: I do not like it

Interesting problems bro. Hope you organise these contests regularly :)

»
4 years ago, # |
  Vote: I like it +7 Vote: I do not like it

Good idea for E, I really forgot that the bits were just being flipped. I think the time complexity can be improved though. Instead of a Fenwick tree, just a simple set<pair<int, int>> can be used to store the endpoints of continuous segments of ones. To find which segment containing some index, just find the segment with the closest left endpoint to that index, and check if the right endpoint is on the right of that endpoint.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +8 Vote: I do not like it

    Nice idea. Yeah, my solution can definitely be improved.

»
4 years ago, # |
  Vote: I like it +3 Vote: I do not like it

Nice problems,very well balanced in my opinion. Just one question, what would be the approximate ratings of each of the problems according to codeforces standard? TIA.

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

    Quite hard to tell. The only thing that I can say is that according to plenty of participants problem B was harder than problem C.

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

I am very sorry but i am stuggling with B question in this contest for hours, i am unable to find the mistake in my code (i am ashamed of this), please help me . Code is here ----->

#include <bits/stdc++.h>
#define int long long
#define MAX 1000000
#define deb(x) cout << #x << "=" << x << endl;
using namespace std;

vector<int> phi(MAX + 5);

signed main() {
    phi[1] = 1;
    for (int i = 2; i <= MAX; i++) {
        phi[i] = i;
    }
    for (int i = 2; i * i <= MAX; i++) {
        if (phi[i] == i) {
            phi[i] = i - 1;
            for (int j = i + i; j <= MAX; j += i) {
                phi[j] -= (phi[j]/i);
            }
        }
    }

    int sum = 0;
    for (int i = 1; i <= MAX; i++) {
        sum += phi[i];
        phi[i] = sum;
        phi[i] = (2LL * phi[i]) - 1;
    }

    int q, ans = 0;
    cin >> q;
    while (q--) {
        int n;
        cin >> n;
        int temp = phi[n];
        ans += temp;
    }
    cout << ans;

    return 0;
}

  • »
    »
    4 years ago, # ^ |
    Rev. 3   Vote: I like it +3 Vote: I do not like it

    Change int ans to long long ans, and long long sum too. And phi to vector of long long as well.

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      i am sorry but you haven't seen#define int long long on top

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I just changed the evaluation of phi(all but 1 cases got accepted) and then updated MAX. It got accepted. ModifiedCode. BTW how to format code as it is in comments?

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Glad you got it accepted. There is an option called

    Spoiler
  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    While calculating the phi array, why you only iterated till $$$\sqrt{MAX}$$$ tho? What about the prime bigger than $$$\sqrt{MAX}$$$? Their phi value will be itself minus 1 and seem like you did not update that.

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

I am getting wrong answer in 4 test cases for problem B( GCD Table ), can someone help me ? . Link to my code