Please read the new rule regarding the restriction on the use of AI tools. ×

Wansur's blog

By Wansur, history, 33 hours ago, translation, In English

2013A — Zhan's Blender

First to solve: rob00

Solution
Code

2013B — Battle For Survive

First to solve: neal

Solution
Code

2013C — Password Cracking

First to solve: Pagode_Paiva

Solution
Code

2013D — Minimize the Difference

First to solve: edogawa_something

Solution
Code

2013E — Prefix GCD

First to solve: meme

Solution
Code

2013F1 — Game in Tree (Easy Version)

First to solve: EnofTaiPeople

Solution
Code with segment tree
Code in O(n)

2013F2 — Game in Tree (Hard Version)

First to solve: rainboy

Solution
Code
  • Vote: I like it
  • +32
  • Vote: I do not like it

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

Problem E originally meant a solution without a gready, but what are rich in :)

And in F you need to separately figure out when the first / second player wins if he starts at his top, because otherwise it hurts a lot)

»
25 minutes ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it

:< could someone explain why cout<<ceil(double(n) / min(x,y)); in A led to WA

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

    There are two reasons this may cause issue

    first (which is mostly the issue here), the output will be in scientific notation

    cout << ceil(1e9 / 2); // 5e+08
    

    this can be solved by casting the output to long/int

    cout << (long long)ceil(1e9 / 2); // 500000000
    

    Another issue which usually happens with large numbers is that double may not be precise enough, for example

    long long x = 1e18;
    x -= 2
    cout << (long long)ceil((double)x / 2) // 500000000000000000;
    

    Here the answer is off by 1 because double is not precise enough, a good solution for both these issues is to not use double for calculating ceil, instead you can calculate it using this

    $$$ceil(a/b) = floor((a + b - 1) / b)$$$

    Which can be written like this:

    long long a = 1e18, b = 2;
    a -= 2;
    cout << (a + b - 1) / b; // 499999999999999999