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

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

Hey there!

Thank you for being part of the ICPC India Prelims 2024! 🚀

I've put together hints and solutions for the problems to help you reflect on the challenges. As the contest admin, I even recorded myself solving the problems live — it's a mix of strategy, insights, and a behind-the-scenes look at my thought process.

🎥 Watch the video here: https://youtu.be/NsIj7CgDPY8

Let me know what you think, and feel free to share your thoughts or questions! 😊

The problems are ordered from easy to hard.

Unsatisfying Array

Hint
Solution

AND Quest

Hint
Solution

Small Indices

Hint
Solution

Yet Another GCD Problem

Hint
Solution

Equations

Hint
Solution

Update:

I'm sorry about what happened in the ICPC prelims. The problems passed to me just 10 hours before the contest. As you can see in the video almost all the time I was just engaged with solving them. The time was such tight that I was occupied with just solving the problems to finish them before the contest started. I didn't have any time to test.

I know that the organizers are making a decision that will make everyone happy.

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

»
17 месяцев назад, скрыть # |
 
Проголосовать: нравится +35 Проголосовать: не нравится

Thanks for the fast editorial.

Spoiler
  • »
    »
    17 месяцев назад, скрыть # ^ |
    Rev. 3  
    Проголосовать: нравится +26 Проголосовать: не нравится

    Regarding the small indices problem, there are other explanations for the sudden rise as well.

    Towards the end of the contest, you have a fight or flight response. According to the constraints, n**3 shall not be accepted. However, if the only solution I had was n**3 and I was not getting anywhere, I would try it regardless. As a matter of fact, I was about to attempt a n**3 solution. As per the information I have seen, n**3 solutions have been accepted.

    Apart from that, even if someone just tried brute force as a last resort, it would get accepted (which is literally the solution provided in the editorial). Even if your team had no idea why brute force would work, it wouldn't change the outcome of the submission.

    I am not saying that there has not been cheating, but I am saying that it is likely a large number of those solutions are not a result of cheating. Regardless, I hope the contest organizers pay their due diligence towards checking for plagiarism, sharing of solutions and any other form of malpractices and cheating.

»
17 месяцев назад, скрыть # |
 
Проголосовать: нравится +44 Проголосовать: не нравится

Why was there a test case with K=0 in problem Yet Another GCD Problem? The constraint mentioned in the problem states that 1<=K<=1e9

  • »
    »
    17 месяцев назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится 0 Проголосовать: не нравится

    At what testcase was your answer failing?

  • »
    »
    17 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится -127 Проголосовать: не нравится

    Apologies for this error. We will re-judge the solution which failed due to this and the penalties will be adjusted accordingly.

    • »
      »
      »
      17 месяцев назад, скрыть # ^ |
       
      Проголосовать: нравится +54 Проголосовать: не нравится

      What about the time wasted because of that?

    • »
      »
      »
      17 месяцев назад, скрыть # ^ |
       
      Проголосовать: нравится +49 Проголосовать: не нравится

      we were stuck on this problem for $$$58$$$ mins, this is not a small mistake? You can't make such mistakes in ICPC....

    • »
      »
      »
      17 месяцев назад, скрыть # ^ |
       
      Проголосовать: нравится +22 Проголосовать: не нравится

      when will the problems be made available for practice [wanna submit some solutions]

    • »
      »
      »
      17 месяцев назад, скрыть # ^ |
      Rev. 3  
      Проголосовать: нравится +30 Проголосовать: не нравится

      [deleted]

    • »
      »
      »
      17 месяцев назад, скрыть # ^ |
       
      Проголосовать: нравится +10 Проголосовать: не нравится

      By when can we expect an update to the rankings?

    • »
      »
      »
      17 месяцев назад, скрыть # ^ |
       
      Проголосовать: нравится -17 Проголосовать: не нравится

      I hope you are doing well. I wanted to share some feedback about the recent contest, specifically regarding the problem 'Yet Another GCD Problem.'

      While solving the problem, we encountered a test case where K = 0. This was surprising since the problem clearly mentioned that 1 <= K <= 1e9 in the constraints. This inconsistency made it confusing and directly impacted how we approached the problem. It feels unfair to include cases outside the constraints, especially in a competition where precision matters so much. Now just removing the penalty won’t be of much help, as teams from our college lost a lot of time trying to debug which also caused energy drain.

      Additionally, in small indices problem it seems like many n^3 or incorrect greedy solutions were able to pass, likely because the test cases were not strong enough. As participants, we invest a lot of time preparing for these contests and even pay to participate. It’s really disheartening when the quality of the contest doesn’t match the effort we put in.

      Because of issues like these, our team couldn’t qualify for the next round, even though we had a rank close to 100 in the first ICPC prelims, which unfortunately got canceled. It feels frustrating to miss out due to errors that could have been avoided with better problem testing.

      I hope that the test organizers keep a best-of-two-ranks method, which would ultimately be the best solution, as none of the two contest was perfect, and would thereby prevent unnecessary penalization of any team.

      I hope you take this feedback into account and make sure future contests have stronger quality control. We just want a fair environment where our hard work pays off.

      Thank you for listening.

      Best regards, Monis

      • »
        »
        »
        »
        17 месяцев назад, скрыть # ^ |
        Rev. 2  
        Проголосовать: нравится +35 Проголосовать: не нравится

        Lets take an ex-

        Suppose a team got a rank x in both rounds(cancelled and this one), which was good enough to qualify for the regionals. But now you are saying lets take the best of two. Due to which the number of teams higher ranked than this team are more now and it could result in this team not qualifying.

        I am not not saying what happened was right, I am just giving my opinion on why I feel this best of two is not right.

        • »
          »
          »
          »
          »
          17 месяцев назад, скрыть # ^ |
           
          Проголосовать: нравится -9 Проголосовать: не нравится

          Yes, I get that this might not seem fair to that team in this situation, though it is also not fair that we are having so many difficulties in such an important contest. I mean such things have rarely if not never happened in codeforces contest. It is quite shameful that we can't do even one contest without such issues. (also, I wouldn't consider getting good rank in first contest as a fluke because everyone experienced the same problem of delayed submissions)

      • »
        »
        »
        »
        17 месяцев назад, скрыть # ^ |
         
        Проголосовать: нравится +23 Проголосовать: не нравится

        Yes, I agree that accepting n**3 solutions shall not be possible and k=0 is a mistake that shall not have happened. However, best of 2 is straight up stupid and much worse. Cases with k=0 shall be removed, yes, but the same is not as easy for the small indices n**3 issue.

        Another re-contest would be terrible as well. I wish I could suggest a good way to deal with this, but best of 2 definitely isn't.

        "I hope that the test organizers keep a best-of-two-ranks method, which would ultimately be the best solution, as none of the two contest was perfect", the first contest was cancelled mid-way, its standings have no value. The solution of having one flat tire is not to replace every tire with a flat one.

        Honestly, the "best of two" idea can't be described as anything but selfish interest from your end.

»
17 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

umm , we came 2nd in our college and in top 100 overall, the first place team from our college had chosen amritapuri and one more region and we had only chosen amritapuri , so is there much chance of us getting selected or no? ;-;

»
17 месяцев назад, скрыть # |
 
Проголосовать: нравится +9 Проголосовать: не нравится

How can we run backtrack for n=3000??

»
17 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится +24 Проголосовать: не нравится

What is the proof for Small Indices problem that the proposed backtracking solution works in O(n^2). Also could you share the dynamic programming solution of the same?

Update:

The proof is as follows:

b[i] > level (b[i] > sum of 2 previous max numbers) can only occur about O(logn) times.

So at O(logn) times we have 2 choices to explore and hence works in the given time complexity

  • »
    »
    17 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится +3 Проголосовать: не нравится

    Damn, wild to think brute force works. If someone would have just tried brute force, would work. I did think that it was possible to do so, but I couldn't prove that time complexity would be n**2.

    I think someone randomly used GPT and it got accepted. That's why we might have as many solves as we did

  • »
    »
    17 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    If you checkout the video, you can see I say there is not that much number of elements that we have two choices for them. After that I generate the worst case and count the number of such elements.

  • »
    »
    17 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится
    Iterative 2D DP
»
17 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится +15 Проголосовать: не нравится

In small indices, if the array size is n then elements of array are <= 2*n and not <= 6000. right? Arpa Enigma27

»
17 месяцев назад, скрыть # |
 
Проголосовать: нравится +77 Проголосовать: не нравится

So, solutions were tested against inputs which clearly defy given constraints in the absence of which many would've AC'd for Yet Another GCD (not to mention many teams saving enough time to attempt at least one more problem), and GPT written brute forces would pass Small Indices? And somehow both things flew under the radar during testing? That too in ICPC prelims, one chance a year for students which they've paid good money for? Must say, stellar work.

  • »
    »
    17 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится +79 Проголосовать: не нравится

    I agree, I don't know how people are fine with this. There are plenty of n^3 or incorrect greedy solutions which AC'd for small indices. The contest which people prepare for months for and have paid for is conducted with little to no standards.

    I know nothing can be done now, they won't redo the contest again, but this is just sad.

    • »
      »
      »
      17 месяцев назад, скрыть # ^ |
       
      Проголосовать: нравится -11 Проголосовать: не нравится

      We can only hope that problem setters for future contests learn from the mistakes made.

      • »
        »
        »
        »
        17 месяцев назад, скрыть # ^ |
         
        Проголосовать: нравится +52 Проголосовать: не нравится

        Wow, ICPC prelims are now serving as training grounds for organizers to learn from.

        Just to put into perspective how easily the so called "mistakes" could've been avoided : it's the most basic of standard practices to write validators for input files (Yet Another GCD) and perform AI checks (Small Indices) for contest problems. Even if they somehow forgot to validate inputs (beats me how that happens but let's just say), some organizers should've been following submissions while contest was live, and given the large number of failing solutions at the same test case it's at least expected for them to have investigated at the time. An announcement, either updating constraints in the PS or notifying teams of running separate tests post rounds so that they could have moved on was the bare minimum acceptable from any responsible organizer.

        The above is stuff I know to be mandatory aspects of problem setting from having set local contests with participant pools of less than size 50. Judging by the credentials of organizers it'd be ridiculous for them to not know the same. The only reason for screw ups this big is negligence. And of course, the cost was paid by students who lost an attempt and a year.

        The latest concern seems to be an incorrect editorial solution for Equations (just saw an upvoted comment about this, can't confirm atm but if it's true, this could mean that outputs generated from such setters' code was faulty and testing was potentially wrong, not to mention an astounding 3 out of 5 problems being blatantly faulty).

        This at least calls for them acknowledging the screw ups in a comment or edit somewhere and the only means to give a fair chance to contestants would be a re given both the magnitude of the contest and that of their sheer blunders, but I guess we should know better than to expect such accountability.

        • »
          »
          »
          »
          »
          17 месяцев назад, скрыть # ^ |
           
          Проголосовать: нравится 0 Проголосовать: не нравится

          Absolutely, a lot of these mistakes are easily avoidable and really make me doubt the contest makers. However, little can be done over the mistakes already made.

          It is common sense to attempt the problemset with GPT as GPT will be a tool used by lots of people. As a problem setter you must take heed of that fact and adjust accordingly.

          Furtherby, having good test cases is a must, without good test cases, you might as well give a free point to any one who attempts the question.

          These mistakes may be acceptable in practice rounds, but for a contest with such importance, rigorous testing of the problem set is necessary.

          However, the damage is done and another re-contest is beyond question.

»
17 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can anyone identify where my code for unsatisfied array goes wrong?

ll n, k;
    cin >> n >> k;
    vector<ll> a(n + 1, 0);
    vector<set<ll>> bound(n + 1);
    for (ll i = 0; i < k; i++) {
        ll x, y, m;
        cin >> x >> y >> m;
        if (x < 1 || y > n || x > y || m < 1 || m > n) {
            cout << -1 << '\n';
            return;
        }
        for (ll j = x; j <= y; j++) {
            bound[j].insert(m);
        }
    }
    for (ll i = 1; i <= n; i++) {
        if ((ll)bound[i].size() == n) {
            cout << -1 << '\n';
            return;
        }
    }

    ll i = 1;
    while (i <= n) {
        ll t = 1;
        while (bound[i].find(t) != bound[i].end() && t <= n) {
            t++;
        }
        a[i] = t;
        i++;
    }
    for (ll i = 1; i <= n; i++) {
        cout << a[i] << " ";
    }
    cout << '\n';
  • »
    »
    17 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    take this testcase and rethink 3 3 1 2 1 1 3 3 2 2 2

    • »
      »
      »
      17 месяцев назад, скрыть # ^ |
       
      Проголосовать: нравится 0 Проголосовать: не нравится

      Hey can you tell where this is going wrong

      Code
»
17 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

where can i find the questions.?

»
17 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

how to solve the problem Small Indices? I cant understand Arpa's Solution.

  • »
    »
    17 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    https://mirror.codeforces.com/blog/entry/136522?#comment-1220912

    try proving why b[i] > level (b[i] > sum of 2 previous max numbers) can only occur about O(logn) times.

    Hint: try to make a case like 1 1 3 5 9 15, you will observe a pattern.

  • »
    »
    17 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится -57 Проголосовать: не нравится

    There are always two choices for each element, right? But think about it, almost always the optimal choice is obvious. For example if sum of two maximums from the left (named level in my code) is very big, i.e. whatever we do, we can't increase it.

    The interesting fact here is, almost always the optimal choice is obvious and there are at most 18 elements that you need to pick. You can use backtracking here to end up with $$$\mathcal{O}(2^{18} \times n)$$$ solution.

    • »
      »
      »
      17 месяцев назад, скрыть # ^ |
       
      Проголосовать: нравится +78 Проголосовать: не нравится

      The complexity of your solution is at least $$$\mathcal{O}((n/\log n)^{\log n})$$$, which would TLE (about $$$200^{10}$$$ operations). I have tested it with the following test case with your code, let me know if there are any mistakes with it.

      $$$n = 3000$$$, let $$$A_i = 1$$$ for all i. Set Bi as follows: $$$B_0 = B_1 = 1$$$. For the rest, consider this sequence: $$$L_i = 2^{i+1} - 1$$$. Now construct $$$B$$$ by setting it from $$$B_2$$$ onwards as $$$L_i$$$ in blocks of 200. So $$$B_2$$$ to $$$B_{202}$$$ is $$$3$$$, next is $$$7$$$ and so on. Of course we never go above $$$4095$$$ to ensure $$$B_i \lt 2n$$$.

      The only valid solution I've found till now is an $$$\mathcal{O}(n^2\log n)$$$ DP which not a lot of people submitted. Most teams submitted completely incorrect solutions which would either TLE or WA. I would like you and the organizing team to please look into this and find a solution.

      • »
        »
        »
        »
        17 месяцев назад, скрыть # ^ |
         
        Проголосовать: нравится -99 Проголосовать: не нравится

        Thanks! I updated my code. Now, I'm using caching. Check it out. Can you find counter case?

        • »
          »
          »
          »
          »
          17 месяцев назад, скрыть # ^ |
           
          Проголосовать: нравится +90 Проголосовать: не нравится

          Thanks for the update, but you are missing the point here. The point is that the official solution, as well as many other solutions would TLE, and many greedy ones would WA. The test cases were weak enough for naive GPT solutions to pass through.

          As I requested earlier, please look into this along with the organizing team. This is no way to organize such an important contest. I hope this is fixed by the organizers.

          Apart from this, there is still no proof that the proposed solution is sub-cubic, as the $$$2^{18}N$$$ claim is not true.

      • »
        »
        »
        »
        17 месяцев назад, скрыть # ^ |
         
        Проголосовать: нравится +5 Проголосовать: не нравится

        Hey

        Sorry to piggyback over your comment, but I don't understand how unsatisfying array model solution is optimal.

        for i in range(1, n + 1): for rng in triplets[i]: if min(a[rng[0]:rng[1]]) == i: a[rng[0]:rng[1]] = [i + 1] * (rng[1] — rng[0])

        This is O(N*K*N) according to me, while Sum(N) == 2000, sum(K) == 2000 should make it TLE. I used a segment tree for the min part, was that unnecessary?

      • »
        »
        »
        »
        17 месяцев назад, скрыть # ^ |
         
        Проголосовать: нравится 0 Проголосовать: не нравится

        Can you please share that (n^2logn) DP solution?

        • »
          »
          »
          »
          »
          17 месяцев назад, скрыть # ^ |
          Rev. 4  
          Проголосовать: нравится +6 Проголосовать: не нравится

          A trivial solution would be to make a n^3 dp where dp [i][j][k] would represent the max number of small indices you have if the max value and second max value till the ith index is j and k respectively.

          But think about number of NON small indices, those can only be around logn.

          You can just swap the states of the dp matrix to something like dp[i][j][k] would represent the second maximum value till ith index if j the the maximum value and you have k NON small indices up till now.

          Note:- Max value and Second Max value is Cj and Ck respectively.

          As 1<=i<=n & 1<=j<=2*n & 1<=k<=25 and for each state there only some constant transitions.

          Memory limit was kinda strict for us so we mem optimized it.

        • »
          »
          »
          »
          »
          17 месяцев назад, скрыть # ^ |
          Rev. 2  
          Проголосовать: нравится 0 Проголосовать: не нравится

          I am not sure if this is correct now (ACed in Contest BTW).

          Edit: It's wrong

          Code
»
17 месяцев назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

This is Code foe Unsatisfied Array, can someone please point out why it is failing.. void solve(){ int n,k; cin>>n>>k; vector<vector<int>> a(k); for(int i=0; i<k; i++){ vector<int> temp(3); cin>>temp[0]>>temp[1]>>temp[2]; a[i]=temp; } vector<vector<int>> data(n+2,vector<int>(n,0)); for(int i=0; i<k; i++){ int st=a[i][0]; int en=a[i][1]; int val=a[i][2]; data[st][val-1]++; data[en+1][val-1]--; } for(int i=0; i<n; i++){ for(int j=1; j<n+2; j++) data[j][i]+=data[j-1][i]; } vector<int> ans(n+2); for(int i=1; i<n+1; i++){ bool ch=0; for(int j=0; j<n; j++){ if(data[i][j]==0){ ans[i]=(j+1); ch=1; break; } } if(ch==0){ cout<<-1<<endl; return; } } for(int i=1; i<=n; i++) cout<<ans[i]<<' '; cout<<endl; }
»
17 месяцев назад, скрыть # |
 
Проголосовать: нравится +75 Проголосовать: не нравится

I doubt the editorial solution for Equations is incorrect. The solution fails for the input

4 4 1 1 2 3 1 2 3 4 1 3 4 1 2 1 3

The editorial code's output is -1. The expected output for the test case is 1 since we can determine the value of a1 and a4 since a1+a4 = 0 and since the numbers in the array are non negative, a1 = 0 and a4 = 0.

Please add this test case and rejudge the solutions if possible.

  • »
    »
    17 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится +15 Проголосовать: не нравится

    Against it, we had finished the contest pretty early, if that test case had been there from the start we could have possibly debugged our code upon getting the wrong verdict.

    • »
      »
      »
      17 месяцев назад, скрыть # ^ |
       
      Проголосовать: нравится +4 Проголосовать: не нравится

      Yeah makes sense not to add any extra test case. But they need to change the author's code and regenerate output files for the existing test cases. There could exist a test case file where ai + aj = 0 that generated a wrong output and could have led to many teams getting a wrong verdict. In that case, it's unfair for the ones who wrote the right code and still got WA.

      • »
        »
        »
        »
        17 месяцев назад, скрыть # ^ |
         
        Проголосовать: нравится +38 Проголосовать: не нравится

        In that sense getting AC and then claiming your solution is wrong is also not fair, as you cannot guarantee that the team could not have solved with the right verdict given. In either case it's a shitty situation to be in, which could have been easily avoided if the setters had removed the word "non-negative" lol.

      • »
        »
        »
        »
        17 месяцев назад, скрыть # ^ |
         
        Проголосовать: нравится +9 Проголосовать: не нравится

        I think it's better to include both the already accepted ones and those who were affected due to this case, just check if some one got a wrong verdict due to such a case and rejudge only these solutions particularly.

»
17 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can someone share the contest link? Interested to check out the problems.

»
17 месяцев назад, скрыть # |
 
Проголосовать: нравится +37 Проголосовать: не нравится

When will be the final standings be declared?

»
17 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Why is this solution failing for Unsatisfying Array?

My code
»
17 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится +85 Проголосовать: не нравится

To summarise:

  1. AND Quest — same as this problem.
  2. Small Indices — weak testcases, GPTable (Edit: GPT gets AC due to weak test cases).
  3. Yet Another GCD Problem — unvalidated/wrong testcases.
  4. Equations — wrong model solution (might have lead to false judging).
»
17 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Where can we submit these problems for practice, kindly make this contest public.

great contest overall could have solved 4 problems but 3 is a very good result

»
17 месяцев назад, скрыть # |
Rev. 4  
Проголосовать: нравится +5 Проголосовать: не нравится
  • for the problem, Small Indices, would this work? I came up with a $$$O(n^2)$$$ solution, I haven't submitted it but I just wanted to discuss the idea. Do correct me if i have made any logical error.
  • dp[index][count of good indices in prefix of i]

DP [i][j]

  • consider first $$$i$$$ guys $$$(0..i)$$$. there are $$$j$$$ good indices
  • return pair {mxsum , mxelement}
  • {max sum formed by taking 2 elements, maximum element possible}
  • if mxsum or mxelement is -inf, then (i,j) state is not possible

Note:

  • mxelement and mxsum need not be from the same configuration, they can be from different configurations for the same $$$(i,j)$$$
  • mxelement is among all possible configurations of j good indices in first prefix (0..i) which element can be maximum.
  • mxsum is among all possible configurations of j good indices in first prefix (0..i), the maximum sum of 2 elements taken in all valid configurations

UPD: This approach is wrong.

  • »
    »
    17 месяцев назад, скрыть # ^ |
    Rev. 5  
    Проголосовать: нравится 0 Проголосовать: не нравится

    I think i have an edge case, consider the following case of (ai,bi) pairs, (1,1),(1,1),(5,2),(5,7),(5,5),(11,11),(17,17)...(1,1) 1000 times now according to the proposed method we will end up picking dp[4][1] as (10,5) even though the pair(9,7) leads to a better answer.

    Basically, the following case

    1

    10

    1 1 5 5 5 11 17 1 1 1

    1 1 2 7 5 11 17 1 1 1

  • »
    »
    17 месяцев назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится 0 Проголосовать: не нравится

    Got it, my approach is wrong. thanks

    • »
      »
      »
      17 месяцев назад, скрыть # ^ |
       
      Проголосовать: нравится +3 Проголосовать: не нравится

      This Passes, we did it similarly.

      Iterative Code
    • »
      »
      »
      17 месяцев назад, скрыть # ^ |
       
      Проголосовать: нравится 0 Проголосовать: не нравится

      1

      10

      1 1 5 5 10 16 1 1 1 1

      1 1 2 7 10 16 1 1 1 1

      Ans should be 6, your code gives 7, just using dp[i-1][j-1][1] for the transition is not correct

      • »
        »
        »
        »
        17 месяцев назад, скрыть # ^ |
         
        Проголосовать: нравится 0 Проголосовать: не нравится

        yeah someone just pointed it out

      • »
        »
        »
        »
        17 месяцев назад, скрыть # ^ |
        Rev. 2  
        Проголосовать: нравится 0 Проголосовать: не нравится
        Code

        This code is passing all edge cases I have seen so far. Is it possible to make a case where this fails

        • »
          »
          »
          »
          »
          17 месяцев назад, скрыть # ^ |
           
          Проголосовать: нравится 0 Проголосовать: не нравится

          Could you mention your approach in brief?

          • »
            »
            »
            »
            »
            »
            17 месяцев назад, скрыть # ^ |
             
            Проголосовать: нравится 0 Проголосовать: не нравится

            First think of the n**3 naive dp solution. With a 2x2 matrix with sum and max element of the 2 for which I take sum.

            After that, I can claim that for every value of sum, I only need to consider the value with the highest score. In case of multiple ways to achieve the same highest score with same sum, I consider the one with the greatest max element. (This can be proven really easily by simply considering cases)

            By doing this, I have reduced the transition from a n**2 matrix to a 2n array making this solution n**2.

            I can consider sum values greater than 2**n as equal, as my max element never exceeds 2**n

            • »
              »
              »
              »
              »
              »
              »
              17 месяцев назад, скрыть # ^ |
              Rev. 4  
              Проголосовать: нравится 0 Проголосовать: не нравится

              Proof lets consider 2d matrix state {sum of 2 elements,max of 2 elements} with score x

              Consider a case where you have to decide between {sum,sum/2} with score x and {sum,sum-1} with score x-1.

              The {sum,sum/2} will always be better/equal to the other case.

              Consider a new element y which is >= sum. let's consider sum+1 and sum separately

              case 1 : sum+1 (generalised for sum + any positive value) new elements {sum+sum/2+1,sum+1} with score x and {sum + sum,sum+1} with score x-1

              the case {sum,sum/2} has a greater score

              now for a new element y such that sum+sum/2+1 < y <= sum + sum for any other case of y, the relation remains same the cases become {sum+1+y,y} with score x and {sum+1+y,y} with score x which are both equal

              case 2: sum new elements {sum+sum/2,sum} with score x+1 and {sum + sum -1,sum} with score x

              the case {sum,sum/2} has a greater score

              now for a new element y such that sum+sum/2 < y <= sum + sum -1 for any other case of y, the relation remains same the cases become {sum+y,y} with score x+1 and {sum+y,y} with score x+1 which are both equal

              now consider y < sum

              1. y <= sum/2

              new elements {sum,sum/2} with score x+1 and {sum-1+sum/2,sum-1} with score x it can be recursively proven that {sum,sum/2} with score x+1 will always have a higher score.

              1. sum/2 < y < sum

              new elements {sum+y-sum/2,y} with score x+1 and {sum+y-1,sum-1} with score x

              the same can be recursively proven again.

              Hence, there exists no case for which {sum,sum/2} with score x is worse than {sum,sum-1} with score x-1

              This proof can be generalized for every value of mx

»
17 месяцев назад, скрыть # |
 
Проголосовать: нравится +60 Проголосовать: не нравится

There's a problem with AND Quest as well You are initializing with $$$cur = (1 \ll 30) - 1$$$, which would be incorrect if $$$k = cur$$$ and none of $$$A_i$$$ satisfy $$$A_i$$$ & $$$k$$$ $$$= k$$$. For example, consider the following case:

$$$k = (1 \ll 30) - 1$$$

$$$A = [1, 2, 3]$$$

your Output will be $$$YES$$$

here there is no subset of $$$A$$$ satisfying the constraint(your program assumes that null set gives cur leading to wrong answer)

»
17 месяцев назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится

When will the list of selected teams be declared for different sites?

»
17 месяцев назад, скрыть # |
Rev. 4  
Проголосовать: нравится 0 Проголосовать: не нравится

Can someone give few testcases for unsatisfying array since mine fails on tc 5.

My approach is to put the minimum value possible at any given instance. If 1,2,3 and 6 cannot be used at a index, use 4 and remember 1,2,3 to not use them till their respective ending index and ignore condition for 6 since 4 is already smaller than 6.

here is the code:


int main() { DRAMA; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t; cin>>t; for(int o=1;o<=t;o++){ ll n,k; cin>>n>>k; vector<pair<pair<ll,ll>,ll>> v; for(int i=0;i<k;i++){ ll a,b,c; cin>>a>>b>>c; v.push_back({{a,b},c}); } sort(all(v)); ll j=0; vector<ll> ans(n); int r=0; vector<ll> temp(n+2,0); priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> pq; for(int i=0;i<n;i++){ vector<pair<ll,pair<ll,ll>>> temp1; while(j<v.size()&&v[j].first.first-1==i){ temp[v[j].second]++; temp1.push_back({v[j].second,v[j].first}); j++; } while(!pq.empty()&&pq.top().first-1<i){ temp[pq.top().second]--; pq.pop(); } ll res=mex(temp); if(res>n){ r=1; break; } ans[i]=res; for(int i=0;i<temp1.size();i++){ if(temp1[i].first<res){ pq.push({temp1[i].second.second,temp1[i].first}); } else temp[temp1[i].first]--; } } if(r==1)cout<<-1<<endl; else { for(auto el: ans)cout<<el<<" "; cout<<endl; } } }