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

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

Thank y'all so much for participating!

2259A - Школа языка Му

Solution
Code
Difficulty
Quality

2259B - Minus Two

Hint 1
Hint 2
Solution
Code
Difficulty
Quality

2259C - 101

Hint 1
Hint 2
Solution
Code
Difficulty
Quality

2259D - MEX мультимножеств

Hint 1
Hint 2
Solution
Code
Difficulty
Quality

2259E - Разрушение карты сокровищ (конструктивная версия)

Hint 1
Hint 2
Solution
Code
Difficulty
Quality

2259F - Инверсии бинарной пузырьковой сортировки

Hint 1
Hint 2
Hint 3
Solution
Code
Difficulty
Quality

2259G - Убрали индекс

Hint 1
Hint 2
Solution
Code
Difficulty
Quality

2259H - Разрушение карты сокровищ (версия подсчёта)

Read the solution to problem E first

Hint 1
Hint 2
Hint 3
Solution
Code
Difficulty
Quality
Разбор задач Codeforces Round 1119 (Div. 3)
  • Проголосовать: нравится
  • +229
  • Проголосовать: не нравится

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

Auto comment: topic has been updated by nik_exists (previous revision, new revision, compare).

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

good contest!

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

nice round thanks !

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

good problems, C was kind of annoying to implement

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

Amazing round. Ty king

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

Maybe you are missing the space after [tutorial:2259B]?

It works for me:

Tutorial is loading...

nik_exists

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

W contest

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

2259E code ... cpp :skull:

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

The editorial isn't working because it doesn't use the announcement format /j

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

C is harder than D. But still orz round by nik_exists

»
2 месяца назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится
#include "codeforces.h"
#include <chrono>
#include <vector>

using namespace std;
using namespace cf;

int main() {
    comment << "\nGreat contest!\n";
}

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

E can be solved with 2-SAT

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

    Can you explain more

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

      Lets forget about the -1 for a moment cause they dont really matter at all in problem E. Just some border cases.

      We want i-A[i] or A[i]+i to be '1' in our string ans.

      When both i-A[i] or A[i]+i fits in the array we can choose any of them, can be both or exactly one. (.either() method in the code)

      When only one of them fits in the array it must be equal to '1' in our ans (SetValue method in the code)

      When neither of them fits theres no answer

      The conditions above are not suficient as we have to ensure in the range [i-A[i]+1,i+A[i]-1] there are no 1's in our solution. The way to solve this is an array diference to know the unvalid positions. SetValue(-i)

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

        Explain deeper how to solve the range [i-A[i]+1,i+A[i]-1] without getting TLE

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

          The main idea in the array diference is to simulate a assignment in ranges.

          We want to put in our array 'p' on the range [i-A[i]+1,i+A[i]-1] a 1 to know this range is unvalid. Instead of iterating over the range (because TLE) or having a Lazy Segment Tree, we can sum a 1 in the begining of the range and a -1 immediately after the range. Then do a prefix sum and the array going to become the desire one.

          Do some cases to convice yourself

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

        Thanks,it's a nice explanation :)

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

          I did it using stacks and queue

          Intialize the array ans of size n which are all 1 intialize the queue with {2,3,4.....n} intialize empty stack

          for i in 1,2,3 .... n if a[i] > 0 then ans[i] = 0

          in the stack keep poping until i - top < a[i] and ans[top] = 0
          
           in the queue if i is present pop it , and after that keep  poping until front - i < a[i] and ans[front] = 0
          
            push i in stack(s)

          after the loop just check if ans is a valid answer

          intuition behind this is that stack allows you to look at indexes from right to left(but less than i) which were not forced to be zero before and queue let's you look at indexes from left to right (>i) which were not forced to be zero before.

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

    i thought of 2SAT and then went for other solution (because i think we don't need 2SAT at all).

    Basically if a[i] == 0, then there should be treasure at position i. Otherwise if a[i] > 0, there should be a treasure at i — a[i] OR i + a[i]. So you just need to add a OR clause and let 2SAT solve it.

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

It Was a fun contest , but i got struck at E for almost the whole contest :-(

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

I cared too much about my rating. That's why I wanted to solve C as fast as I could and made many silly mistakes

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

Thanks for the contest! I enjoyed it

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

should i try to upsolve E? current rating is 1072 and max is 1100.

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

Nice contest!

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

i dont know why i found it hard to understand E statement otherwise amazing round!

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

Please elaborate more on the editorial of $$$E$$$.

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

    let the given array be v and the final string be s for each v[i]>0 the closest island to it should be at position i-v[i] or i+v[i] if there is an island (v[j]=0) in the range ]i-v[i],i+v[i][ then that element j will be closer to v[i] which will be a contradiction so you should output -1 then for each -1 outside of the union of these ranges you can consider it as an island (set it to 1 in s and its valid given that it does'nt influence other elements) the -1 inside the union of the ranges will be set to 0 in the final string because they cant be set to 1 after that you need to check for every element i with v[i]>0 if there is an island in i-v[i] or i+v[i]

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

The problems were amazing and realized I need to improve myself, java was kind of problematic at times

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

Why does the system testing so long?

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

good contest, but G is too easy in Div.3

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

I liked this round a lot, but B felt easier to implement than A xd. And G was really easy compared to E for me.

Good work!

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

E took me longer than F and almost had G on time but still it was a great round!

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

Amazing contest, A-D was very easy.The jump from D to E was pretty big for a div 3.

Question F was really fun!

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

i got WA on test case 2 which was n=3 -1 1 1 i got answer as 1 0 0 Placing a treasure at island 1 (100) gives: Distance from island 1 to nearest treasure = 0. Distance from island 2 to nearest treasure = 1 (which is >=1). Distance from island 3 to nearest treasure = 2 (which is >=1). As question has clearly stated that ai means treasure is 'ATLEAST' distance away from ith island so my answer should be valid why jury's answer is -1

nik_exists explain this

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

AMAZING E and F! I had a lot of fun solving them :3

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

My contest discussion stream here for ABCDEFG

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

.

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

Fantastic round, enjoy it

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

In $$$G$$$ the last-moving index will always increase, so it can be done in $$$O(n)$$$ with two-pointers rather than binary search. (I found it easier to think in terms of the "slack", $$$k-(a_{i+1}-a_{i})$$$ equivalently you are finding the position at which the total slack from your current position hits $$$k$$$; the fact this increases is then immediate from the slack always being positive).

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

I tried to construct the graph in H and do some kind of DP on it, but I got stuck in the cycles part... It took me a while to realizes the graph's cycles has a special structure: they are disjoint segments and all edges in the cycles already has their 0/1 values. At that point, I just needed to prune the cycles to do DP.

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

After solving F and G post contest, i think F<G<E. Aside from getting cooked by E, really great contest!

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

the markdown formatting is incorrect. Here’s the code for problem E in case anyone needs it :33

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

during the event i solved 4 questions i thought my rating would be 1050+ but due to the checkbox i didnt read it and i participated in unrated contest.THE FEELING cant be described :(

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

What would be the approximate rating for all the problems? I gave this contest after around 6 months of inactivity and solved 4.

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

Hello nik_exists,

This letter is about my skip from the contest.

First, I want to make clear that I didn’t cheat or use any external programs during the competition. I made my solutions by myself relying only on my knowledge.

Of course, the anti-cheat can find some similarities or something strange, and I fully understand the necessity of this measure. Nevertheless, I think that I was flagged by mistake.

If there was something in my code which attracted your attention, I will be grateful if you could tell me what it was. Besides, I am fully ready to explain my solutions and every line of my code so that you could see that I understood everything by myself.

Thank you for your consideration.

nik_exists

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

nik_exists

Amazing round, I enjoyed it , thanks a lot

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

Nice contest

»
2 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится
#include "codeforces.h"
#include <chrono>
#include <vector>

using namespace std;
using namespace cf;

int main() {
    comment << "\nGreat contest! && thank you\n";
}
»
2 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

What a contest man! Got to learn many things. Thank you!!

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

Can anyone help me, i solved a-e in this contest but all my submissions are skipped and i got a message that it was due to some violation in rule. here are my submissions 389498525,389511176,389531255,389539799 i don't understand why they are skipped but they seems fine to me.

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

nice , thanks for this useful contest =)

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

Heyy..I gave the whole contest fairly but today I received the message "your responses are not being considered due to rule violations". Can anyone tell why I got this? I didn't cheat at all.

nik_exists please look at this.

Bro......I just checked the AI flagged solutions for all codes and in code e, just the name treasure_map_fin matches, that is a pure coincidence. The logic was really simple for the problem and that's what I did step by step...find the possible indices, if none is possible flag as -1, check for exact presence......just the name of vector got same

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

first time solved 4 problems yeeepie but after the contest got a runtime error on c but still happy

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

can someone explain why TLE ?389511024 and here where went wrong ? 389560130

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

    1-Fast I/O: Use sys.stdin.read().split() instead of input().split(). Reading input line by line in multiple test cases is very slow.

    2-Hash Collisions: In Codeforces, Python's dict and Counter are vulnerable to anti-hash tests. Hackers can force hash collisions that degrade operations from $$$O(1)$$$ to $$$O(N)$$$, causing an $$$O(N^2)$$$ TLE.

    3-Unnecessary Dict: In your codes, for example, in the second code you don't need Counter at all since you only count zeros (using arr.count(0) or a basic loop).

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

nice contest! code?

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

My alternative solution for Problem H (no 2-sat, dsu required):

1) A valid treasure placement configuration must follow a specific zig-zag pattern:
- It starts with a strictly decreasing sequence (step -1) down to $$$0$$$.
- Then, it strictly increases (step +1).Then, it strictly decreases (step -1) back to $$$0$$$.
- This pattern alternates, ending with a strictly increasing sequence.
- At the transition points (the "peaks" and "valleys" between segments), the absolute difference between adjacent elements cannot exceed 1.
- Example of a valid configuration: 3 2 1 0 1 2 3 4 5 4 3 2 1 0 0 1 2 2 1 0 1 2 3 4.

2) Since each valid configuration corresponds to a distinct placement strategy, the problem reduces to counting the number of ways to replace all (-1)s with non-negative integers such that the resulting array satisfies the conditions above.

3) For each index $$$i$$$ from $$$1$$$ to $$$n$$$:
- Define $$$L[i] = k$$$ as the maximum length $$$k$$$ extending to the left of $$$i$$$ such that this segment can be validly filled as a strictly decreasing sequence from $$$k-1$$$ down to $$$0$$$. This can be computed using Binary Search + Sparse Table.
- Similarly, define $$$R[i] = k$$$ as the maximum length $$$k$$$ extending to the right of $$$i$$$ such that this segment can be validly filled as a strictly increasing sequence from $$$0$$$ up to $$$k-1$$$. This can also be computed using Binary Search + Sparse Table.

4) Let $$$dp[i]$$$ be the number of valid ways to fill the prefix from $$$1$$$ to $$$i$$$, given that $$$a[i] = 0$$$.
- Obviously, if $$$a[i] \gt 0$$$, then $$$dp[i]=0$$$.
- If the prefix is just a single decreasing sequence down to $$$0$$$, then $$$dp[i] = 1$$$ if $$$L[i] = i$$$, otherwise $$$0$$$.
- For other valid configurations, $$$dp[i]$$$ is the sum of $$$dp[j]$$$ for all $$$1 \le j \lt i$$$ where the gap between $$$j$$$ and $$$i$$$ can form a valid "mountain" (an increasing segment followed by a decreasing segment). The condition for this is $$$\min(L[i], R[j]) \ge \lceil \frac{i - j + 1}{2} \rceil$$$, which can be rewritten as: $$$2 \times \min(L[i], R[j]) \ge i - j + 1$$$. This can be optimized from $$$O(n^2)$$$ to $$$O(nlogn)$$$ by using CDQ or Sweepline.
- If $$$R[i] = N - i + 1$$$, it means the remaining suffix (from $$$i$$$ to $$$N$$$) can be formed as a strictly increasing sequence starting from $$$0$$$. Thus, this $$$dp[i]$$$ contributes to the final answer.

5) Code: https://codeforces.me/contest/2259/submission/389626088

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

Why is there no code?

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

I failed E purely for the reason of misunderstanding this line " a[i] ** indicates the minimum number of islands that Bessie would need to travel** ". I thought it meant that treasure can exist anywhere other than range i-a[i]+1 and i+a[i]-1. Hate myself.

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

Great contest, hope more like this one :)

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

nice contest, learn a lot tysm

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

honestly, problem A was harder than B, what do you think?

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

bullshit problems

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

Hello, I participated in this contest as an official contestant (handle: SXWisON). I solved 8/8 problems and finished around rank 15, but I am not in the rating changes list and my rating is still 1325. Could you please check if my rating update was missed? Thank you.

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

solution to G using two lazy segment trees

using SS = pair<ll, ll>;
using F = ll;
SS e_() {
    return {0, 0};
}
 
SS op_(SS a, SS b) {
    return {a.first + b.first, a.second + b.second};
}
 
SS mapping_(F f, SS x) {
    SS res;
    res.first = x.first + f * x.second;
    res.second = x.second;
    return res;
}
 
F composition_(F f, F g) {
    return f + g;
}
 
F id_() {
    return 0LL;
}
 
using S = ll;
S e() {
    return 4e18;
}
 
S op(S a, S b) {
    return min(a, b);
}
 
S mapping(F f, S x) {
    return x + f;
}
 
F composition(F f, F g) {
    return f + g;
}
 
F id() {
    return 0LL;
}
 
void solve() {
    int n; ll k; cin >> n >> k;
    vector<ll> dif(n - 1);
    vector<ll>a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }    
    for (int i = 0; i < n - 1; i++) {
        dif[i] = a[i + 1] - a[i];
    }
    vector<ll> ans;
    atcoder::lazy_segtree<SS, op_, e_, F, mapping_, composition_, id_> seg1(n - 1);
    atcoder::lazy_segtree<S, op, e, F, mapping, composition, id> seg(n - 1);
    for (int i = 0; i < n - 1; i++) {
        seg1.set(i, make_pair(0LL, 1LL));
        seg.set(i, 0LL);
    }
    for (int i = n - 2; i > 0; i--) {
        seg.apply(i, n - 1, a[i + 1] - a[i - 1]);
        seg1.apply(i, n - 1, a[i + 1] - a[i - 1]);
        if (i + 1 <= n - 2) {
            seg.apply(i + 1, n - 1, -k);
            seg1.apply(i + 1, n - 1, -k);
        }
        int j = seg.max_right(i, [&](ll x) {
            return x > k;
        });
        ans.push_back(max(0LL,seg1.prod(i, j).first - k*(j-i)));
        seg.apply(i, n - 1, -a[i + 1] + a[i - 1]);
        seg1.apply(i, n - 1, -a[i + 1] + a[i - 1]);
        seg.apply(i, n - 1, dif[i]);
        seg1.apply(i, n - 1, dif[i]);
    }
    ans.push_back(0);
    ans.insert(ans.begin(),0);
    reverse(ans.begin(),ans.end());
    for(ll x:ans){
        cout<<x<<' ';
    }
    cout<<'\n';
}
»
2 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

just gave it as virtual, great contest keep up the great work <3

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

Can we demonstrate the correctness of the solution for problem D?

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

D is interesting but a bit difficult for me.

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

Problem E was a good one. Really enjoyed solving it!

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

F is easier than E !!!!

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

thanks for the editorial

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

It seems editorial solution for 2259C is not correct. It is giving wrong output for this case: 7 -1 0 1 -1 0 0 1

output: 1 0 1 0 0 0 1

expected output: 0 0 1 0 0 0 1

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

can anyone tell why for E , its output is -1 instead of 100 TESTCASE:- 3 -1 1 1