BledDest's blog

By BledDest, 5 months ago, translation, In English

2225A - A Number Between Two Others

Author: BledDest

Tutorial
Solution 1 (BledDest)
Solution 2 (BledDest)

2225B - Alternating String

Author: FelixArg

Tutorial
Solution (FelixArg)

2225C - Red-Black Pairs

Author: FelixArg

Tutorial
Solution (FelixArg)

2225D - Exceptional Segments

Author: FelixArg

Tutorial
Solution (FelixArg)

2225E - Covering Points with Circles

Author: basalov_yurij

Tutorial
Solution (FelixArg)

2225F - String Cutting

Author: FelixArg

Tutorial
Solution 1 (FelixArg)
Solution 2 (BledDest)

2225G - Simple Problem

Author: basalov_yurij

Tutorial
Solution (BledDest)
  • Vote: I like it
  • +38
  • Vote: I do not like it

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

Auto comment: topic has been translated by BledDest (original revision, translated revision, compare)

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

Damn!! Fastest Edu Round editorial

»
5 months ago, hide # |
 
Vote: I like it +10 Vote: I do not like it

I tried to solve problem G by explicitly building a graph and heuristically finding hamiltonian path in it using approach from this blog, but failed.

Does someone have a heuristic algorithm for finding hamiltonian path which will actually be good enough to solve problem G?

»
5 months ago, hide # |
 
Vote: I like it -26 Vote: I do not like it

Very nice contest !

»
5 months ago, hide # |
 
Vote: I like it +12 Vote: I do not like it

Is the randomness of test36 of E good enough?I use hexagonal close packing centered (0,0)and have roughly 90% accuracy in test2-35 stably,but drop to 78.35% in test36.

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

    The test aims to punish codes that have predictable starting points, I guess.

  • »
    »
    5 months ago, hide # ^ |
     
    Vote: I like it +8 Vote: I do not like it

    It is generated in the same way as the other tests. However, this is the first test with $$$x = 10^5$$$, all tests before it use smaller rectangles.

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

    Are your iteration bounds enough for covering the whole square? You can try initially generate more than n circles and then greedily take those with the most points enclosed.

»
5 months ago, hide # |
 
Vote: I like it +8 Vote: I do not like it

Why can't I hack submissions on problem F?

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

Tutorial for D is incomplete. The number of required indices for a specific value to the left or to the right of x can be found by simple division, based on the pattern. You have to show how to do this simple division.

  • »
    »
    5 months ago, hide # ^ |
     
    Vote: I like it +10 Vote: I do not like it

    We believe that some simpler parts of the solution should be figured out by participants themselves. But if you've tried to do it and got stuck, check out the spoiler

    Spoiler
»
5 months ago, hide # |
 
Vote: I like it +6 Vote: I do not like it

My post contest discussion stream for ABCDF https://codeforces.me/blog/entry/153161
Youtube VOD

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

problem E was cool, but now i wonder if it can be possible by using a greedy method, or if hexagonal packing is the only possible way...

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

    same question, since that was my first approach after giving up

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

    Since the points are chosen randomly, I guess a greedy method is unlikely to outperform hexagonal packing (consistently) if you don't know the point distribution in advance.

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

where is the tutorial of problem G

  • »
    »
    5 months ago, hide # ^ |
     
    Vote: I like it +21 Vote: I do not like it

    first, the aim of the problem is to find a hamiltonian path in the numbers 0..n-1, where i and j have an edge iff |i-j| is divisible by any element in a set of integers k.

    clearly, if gcd(k) != 1, there is no solution (cannot link up different sets)

    lets say we have the numbers 1..n and a set of integers k. if we choose some element x ∈ k, and we group all nodes that have an edge because |a-b| divisible by x, we get a set of x cliques, where nodes within the cliques all have the same remainder mod x. as these are cliques, we can freely order the nodes within them, so the only nodes that matter are the start and end nodes

    now we should look at edges that cross cliques. say clique 0 and clique y have at least 1 edge between them, then so do clique 1 and y+1, clique 2 and y+2 etc (obvious). so this actually looks like the same problem as before, just now on x < n nodes, but the same set k.

    so the problem can be solved recursively, let f(n,k) -> vector be a sequence of n-1 "jumps" that is the difference array for a solution with that n and k. f(n,k) = [clique 0] -> [some other clique that 0 has an edge to] -> [clique with an edge to] etc. if there are x cliques, we can determine the cross jumps needed by f(x,k), and the intra jumps by adding x each time

    finally to reconstruct the order, notice that for each clique we just care about the entry and exit node, and they need to be different. as k[i] <= n/3, every clique has >= 3 nodes, which is helpful. simple greedy method can be used to choose the entry and exit nodes for each clique

    hope it helps

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

Is the way to do C other than DP is greedily take vertical segments, else try take it horizontally? We have to take min(count from left, count from right)? Please help me if you've done it without DP.

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

    I don't think there will be a greedy solution here as you can easily see that their are two ways , like in first the two horizontal adjacent cells are of same color in both row or the two vertical row are of same color , so what happens here is that after you have decided colors for them you don't care about these choices for the next ones but the issue is that you cannot optimally choose for one of both those choices here and tbh dp was very intuitive idea here and maybe after more practice you will just see dp idea coming intuitively for this one

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

      Yes we can do it greedily

      if a[i]==b[i] then regardless of a[i+1] and b[i+1] we choose to pair a[i] and b[i] and increase i by 1

      else

      if a[i]!=a[i+1] and b[i]!=b[i+1], we pair up a[i] and b[i] and increase ans by 1, i by 1

      else if one of the conditions is false we increase ans by 1 and i by 2(horizontal pairing) if both conditions are false then we simply increase i by 2

      372033411

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

        Even simpler: When a[i] != b[i], we only need to place two dominoes horizontally if a[i] == a[i+1] and b[i] == b[i+1]. Otherwise, we will need to add 1 or 2 anyway, whichever way we place them, so we can just place one vertically and continue with the next column. 371998802

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

          i think your approach is wrong, what if the input is RR BR your code will give 0 as output, but the right answer is 1 tell me if am i wrong

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

            No, that will work as well. First, it will encounter a[0] == R and b[0] == B. Therefore, it checks whether a[0] == a[1] and b[0] == b[1]. This is not the case. In the code I sent (which got accepted), we count the number of correct dominoes, so we will just continue for i == 0. For i == 1, it finds a[1] == b[1] and thus adds 1 to the count. Then, it returns 2 — 1 = 1 wrong dominoes / tiles that need to be repainted.

    • »
      »
      »
      12 days ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      //i have solved by greedy here is my solution //sorry for messy code ~~~~~

      include <bits/stdc++.h>

      using namespace std;

      using ll = long long; using ld = long double;

      using pii = pair<int,int>; using pll = pair<ll,ll>;

      define all(x) (x).begin(), (x).end()

      define sz(x) (int)(x).size()

      define nl '\n'

      define rep(i,a,b) for (int i = (a); i < (b); i++)

      const int MOD = 1e9 + 7; const ll INF = 1e18;

      ifdef LOCAL

      define dbg(x) cerr << #x << " = " << (x) << nl

      else

      define dbg(x)

      endif

      void solve(){ int n; cin>>n; string a; string b; cin>>a; cin>>b; int cnt=0; int ok=0; for(int i=0;i<n-1;i++){ ok=i; if(a[i]==b[i])continue; if(a[i]==a[i+1]&& b[i]==b[i+1]){ i++;

      }
          else{
              cnt++;
          }
      
      
      }
      if(n==1){
          if(a[0]!=b[0])cnt++;
      
      
          cout<<cnt<<endl;
          return;
      }
      if(ok==n-2){

      if(a[n-1]!=b[n-1] && (a[n-1]!=a[n-2] || b[n-1]!=b[n-2]))cnt++; cout<<cnt<<endl; } else{ if(a[n-1]!=b[n-1]){ cnt++; } cout<<cnt<<endl; }

      } int main() {

      ifndef ONLINE_JUDGE

      freopen("input1.txt","r",stdin);
      freopen("output1.txt","w",stdout);
      #endif
      ios::sync_with_stdio(false);
      cin.tie(nullptr);
      
      int tt;
      cin >> tt;
      while (tt--) {
      
         solve();
      }
      return 0;

      } ~~~~~

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

    Label the columns with three labels — 0 if the two cells are the same, 1 if red is on top, 2 if blue is on top. Then break it into contiguous chunks with the same label.

    Chunks with label 0 can be ignored because we can cover them completely with vertical pairs. The other chunks can be covered with horizontal pairs if the length of the chunk is even. Otherwise, we have one column left over which we can flip a cell of so we can cover it with a vertical pair. So the answer is the count of all chunks with odd length that are labeled 1 or 2.

    Solution

  • »
    »
    5 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it
    My solution
    Why I think it works
  • »
    »
    5 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    This is my greedy approach submission:

    solution

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

    my method was, if the next 2 columns can do horizontal without switching then go horizontal, otherwise just take one column (if it would cost 1 to switch for horizontal then that means there's 3 red 1 blue or vice versa, in which case vertical costs the same so might as well go with that)

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

    I've done the same.

»
5 months ago, hide # |
 
Vote: I like it +5 Vote: I do not like it

E looks quite unique problem and I haven't seen one of its kind anywhere , is there any place we can practice these type of problems and are there some similar problems there online ? Also how to think about these type of problems when solving them for the first time? __

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

I was able to use suffix array for F (though I didn't get it in contest): submission

Idea was to go backwards from the end in the suffix array (so in decreasing order of suffix order) and check feasibility of the suffix. If we have found a feasible suffix $$$a$$$, another feasible suffix $$$b$$$ that is earlier in the suffix array can only improve the solution if $$$a$$$ is a prefix of $$$b$$$. So we can keep a running min of the lcp array as we scan over the suffixes to check this condition.

»
5 months ago, hide # |
 
Vote: I like it +16 Vote: I do not like it

Can anyone explain the constraint "a circle's area is at most $$$\frac{1}{10}$$$ of the rectangle's area". How does it specifically impact the solution for Problem E?

  • »
    »
    5 months ago, hide # ^ |
     
    Vote: I like it +3 Vote: I do not like it

    When the area of the circle is too big, the choice of starting point (from which we build the hexagonal pattern) affects the result much more severely. So, it increases the probability that you pick a "bad" starting point in the beginning by making the random less "pure".

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

      But how does this constraint relate to covering 89% of the points? It seems like there should be enough starting positions to cover 89% of the area.

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

        imagine if you place a circle with a large enough radius such that every point is within 2*r of the circle but not necessarily within r of the circle. You can have many points outside that you can't center circles at because they would intersect with the already placed circle. The area constraint makes it so there will generally be a point far enough away from the circle that can be used to center an additional circle at.

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

        My opinion: Because the area of the rectangle is bounded, we can't achieve ~ 90% density using hexagon packing if the radius is too big. On wikipedia they work with the infinite space, and the density converge to ~ 90% regardless of circle radius.

»
5 months ago, hide # |
 
Vote: I like it +10 Vote: I do not like it

weak pretest for problem F

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

When finding circles that can contain point p, why do we check the 5 nearest rows and cols and when is checking 3 not enough?

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

My solution for D, using observation that xor of consecutive 4 numbers with starting number being even number, is always 0. In code, y : number of even numbers before x (inclusive of x). t : total number of odd numbers between x and n (inclusive). z : (when y is odd, in case of even y, answer added for each odd number is same y/2): number of odd number, i between x and n (inclusive) such that (i+1) is divisible by 4. mul : modular binary multiplication function.

ll mul(ll a, ll b) {
    a %= MOD;
    b %= MOD;
    ll res = 0;
    while (b > 0) {
        if (b%2==1) {
            res = (res+a)%MOD;
        }
        a = (2*a)%MOD;
        b/=2;
    }
    return res;
}
 
//------------------------BE THE BEST----------------------------------------------
void solve(){
    ll n,x; cin>>n>>x;
    ll y = (x/2)+1;
    ll k = x + !(x%2);
    if(k>n) {cout<<0<<endl; re;}
    ll ans = 0;
    if(y%2==1)
    { 
        n++;
        ll z = (n-k)/4; 
        if(k%4==0 || n%4==0) z++;
        n--;
 
        ll t = (n-x)/2;
        if(n%2==0) t+=((n-x)%2);
        else t++;
     
        ll c = t-z;
 
        ans = (((mul(z,((y/2)+1)))%MOD) +ans)%MOD;
        ans = (((mul(c,(y/2)))%MOD) +ans)%MOD;
    }
    else{
        ll z = ((n-k)/2)+1;
        if(n%2==0 && k%2==0) z--;
        ans = (((mul(z,(y/2)))%MOD) +ans)%MOD;
    }
    cout<<ans<<endl;
}
»
5 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

.

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

Great editorial, thanks for the clear explanations.

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

Regarding problem D: I spent some time debugging why my solution failed before realizing I forgot to add % mod at the very end of the expression. Initially, I thought the issue was related to integer division in my helper functions. However, it turned out to be a classic long long overflow during the multiplication of the two functions' results (l * r) before the modulo operation was applied. 

Just a reminder for anyone stuck on a similar issue: always check your intermediate multiplications, even if you are using #define int long long! Thanks for the great problem.