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

Автор BledDest, 3 недели назад, По-русски

2225A - Число между двумя другими

Автор: BledDest

Разбор
Решение 1 (BledDest)
Решение 2 (BledDest)

2225B - Чередующаяся строка

Автор: FelixArg

Разбор
Решение (FelixArg)

2225C - Красно-чёрные пары

Автор: FelixArg

Разбор
Решение (FelixArg)

2225D - Исключительные отрезки

Автор: FelixArg

Разбор
Решение (FelixArg)

2225E - Покрытие кругами

Автор: basalov_yurij

Разбор
Решение (FelixArg)

2225F - Нарезка строк

Автор: FelixArg

Разбор
Решение 1 (FelixArg)
Решение 2 (BledDest)

2225G - Простая задача

Автор: basalov_yurij

Разбор
Решение (BledDest)
  • Проголосовать: нравится
  • +38
  • Проголосовать: не нравится

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

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

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

Damn!! Fastest Edu Round editorial

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

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?

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

Very nice contest !

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

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.

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

Why can't I hack submissions on problem F?

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

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.

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

    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
»
3 недели назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

my solution to A was

let y/x be d

y = dx

a number smaller than y but divisible by x can be written as dx-x or y-x

numerator(z) = dx-x (because y-x will always be a multiple of x if y is a multiple of x and greater than x+1) denominator = x

(dx-x)/x = x(d-1)/x = d-1 which means dx-x will always be a multiple of x now let's check the second condition, which is "y is not divisible by z"

dx/dx-x dx/x(d-1) d/(d-1) and we know that 2 consecutive number have hcf of 1, so remainder is not 0 at all

thus we come to conclusion that, z = dx-x, or y-x

but we know that x<z<y, so if here our z or y-x , is not greater than x then it is breaking the order rule, so basically it isnt possible when y-x <= x or not greater than x

and our final solution is

if y-x >x yes, else no

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

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

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

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...

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

where is the tutorial of problem G

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

    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

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

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.

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

    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

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

      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

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

        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

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

          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

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

            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.

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

    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

  • »
    »
    3 недели назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится
    My solution
    Why I think it works
  • »
    »
    3 недели назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    This is my greedy approach submission:

    solution

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

    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 недели назад, скрыть # |
 
Проголосовать: нравится +5 Проголосовать: не нравится

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? __

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

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.

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

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?

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

    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".

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

      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.

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

        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.

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

        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.

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

weak pretest for problem F

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

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?

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

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;
}
»
2 недели назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится
  • Dear Codeforce Team,
  • I am writing to appeal the "skipped" verdict on my submisson for problem D in the contest Educational round 189. This is my code's number
  • 372047076.
  • The problem revolves around the xor sum from one to n, which is a well-known conclusion.The first time I learned it form csdn blog which sowed the seed i solved this problem.
  • My code is around four key functions to count the numbers mod 1 and 3 in the left and right.This is because i found that 2 or 4 can't contribute to the result, i didn't count them. n≡1(mod4),the result is always 1.n≡3(mod4),the result is always 0.Then it comes to the main function, i speed up input and output, afraid of tle.Then comes to the key point,i set four variable temp1,temp2,temp3,temp4,with my functions.The reason why i write +1 is a specific boundary correction i made during my thinking.S0=0.So i add 1.Then set two variable to multply temp1 and temp3 to get res1,temp2 and temp4 to get res2 ,Then i add them, with mod 998245353. So this is my code. I couldn't believe that my code would be similar with others because i thought my code is a little redundancy,i manually finished it with pressure, and also try to revise my errors with the examples. I apologize for the verbose implementation, but it helped me avoid mistakes.Thank you for your time and for maintaining a fair competitive on codeforce.I am confident my code is an original result. I look forward to your positive reponse.
  • Best regards,
  • wangzehao
  • include

  • define mod 998244353

  • using namespace std;
  • long long count_1_l(long long r){
  • long long temp1=r%4;
  • long long temp2=r/4;
  • if(temp1>=1){
  • temp2++;
  • }
  • return temp2;
  • }
  • long long count_3_l(long long r){
  • long long temp1=r%4;
  • long long temp2=r/4;
  • if(temp1>=3){
  • temp2++;
  • }
  • return temp2;
  • }
  • long long count_1_r(long long l, long long n){
  • long long temp1=l%4;
  • long long temp2=l/4;
  • long long temp3=n%4;
  • long long temp4=n/4;
  • if(temp1>=1){
  • temp2++;
  • }
  • if(temp3>=1){
  • temp4++;
  • }
  • return temp4-temp2;
  • }
  • long long count_3_r(long long l, long long n){
  • long long temp1=l%4;
  • long long temp2=l/4;
  • long long temp3=n%4;
  • long long temp4=n/4;
  • if(temp1>=3){
  • temp2++;
  • }
  • if(temp3>=3){
  • temp4++;
  • }
  • return temp4-temp2;
  • }
  • int main(){
  • ios::sync_with_stdio(false);
  • cin.tie(0);
  • long long t;
  • cin >> t;
  • while(t--){
  • long long n, x;
  • cin >> n >> x;
  • long long left_limit = x — 1;
  • long long temp1 = count_1_l(left_limit);
  • long long temp2 = count_3_l(left_limit) + 1;
  • long long temp3 = count_1_r(left_limit, n);
  • long long temp4 = count_3_r(left_limit, n);
  • long long res1 = (temp1 % mod) * (temp3 % mod) % mod;
  • long long res2 = (temp2 % mod) * (temp4 % mod) % mod;
  • cout << (res1 + res2) % mod << endl}
  • return0}