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

Автор Wansur, история, 19 месяцев назад, По-русски

2013A — Блендер Жана

Первый решивший: rot

Разбор
Решение

2013B — Бой на выживание

Первый решивший: neal

Разбор
Решение

2013C — Взлом Пароля

Первый решивший: Pagode_Paiva

Разбор
Решение

2013D — Минимизировать разность

Первый решивший: edogawa_something

Разбор
Решение

2013E — Префиксные НОД

Первый решивший: meme

Разбор
Решение

2013F1 — Игра на дереве (простая версия)

Первый решивший: EnofTaiPeople

Разбор
Решение c деревом отрезков
Решение за O(n)

2013F2 — Игра на дереве (сложная версия)

Первый решивший: rainboy

Разбор
Решение
Разбор задач Codeforces Round 973 (Div. 2)
  • Проголосовать: нравится
  • +101
  • Проголосовать: не нравится

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

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)

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

    I have another solution of $$$E$$$ and I wonder if it is intended.

    Enumerate $$$a_1$$$. Note all the divisors of $$$a_1$$$ as $$$d_1,d_2,\ldots,d_m$$$. We can check if there is $$$a_j$$$ such that $$$\gcd(a_1,a_j)=d_k$$$ for every divisors.

    Note $$$dp_{i,j}$$$ as the max sum when $$$\gcd(a_1,\ldots,a_i)=j$$$. We only accept transform $$$dp_{i,j} \rightarrow dp_{i+1,k}(k \lt j)$$$ so $$$i$$$ is small ($$$log(maxa)$$$).

    So the complexity is $$$log(maxa) \cdot m^2$$$ for an $$$a_1$$$.

    The maximum number of divisors may be $$$240$$$, but if we tag the calculated numbers and skip them, the average $$$m$$$ is around $$$10$$$.

    The final complexity is $$$O(n \cdot \log(maxa) \cdot \overline{m^2})$$$.

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

      how do you check if there is a number that will turn N into one of its divisor D ?

      i thought of inclusion exclusion on the prime factors to determine if there exists such a number X that doesnt include any of the prime factors to turn N into D but it seems like u didnt use inclusion exclusion so how did u do it ?

      edit : seems like u only did it for one number

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

        Let's assume $$$d_1 \lt d_2 \lt \cdots \lt d_m$$$.

        Note $$$cnt1_x$$$ as the total of multiple of $$$x$$$, and $$$cnt2_x$$$ as the total of $$$a_i$$$ such that $$$\gcd(a_1,a_i)=x$$$.

        For $$$i=m$$$ to $$$1$$$, do $$$cnt_2[d_i]+=cnt1[d_i]$$$, and $$$cnt_2[d_j]-=cnt_2[d_i]$$$ $$$(d_i=k\cdot d_j)$$$. The complexity is $$$O(m^2)$$$.

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

any intuitive / formal proof to D ? i have a weird one that i'll write when i have time

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

why is cout.flush() not required in question C?

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

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

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

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

    use (long long)ceill(..) instead

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

My solution for problem C:

  • First binary search to find maximum consecutive one and zero's. You can binary search over array such as [0, 1, 11, 111, 1111 ...] for 1 and when result of binary search is 0 for 1 that means there aren't any 1 in password.

  • Now you can try both possible combination of max consecutive one and max consecutive zero. For ex let's say max_consec_one = 3, max_consec_zero = 4, so either 1110000 or 0000111 has to be a substring.

  • From the above example if max_consec_one = 3 and 1110000 is valid substring that means on left of this substring there has to be some amount of zero's and same logic for right. To find this cnt of zero's for left and one's for right you can again binary search.

  • You can repeat above step until string t reaches the size n of the original string.

I don't know how to prove that it is less than n * 2 queries, but I think it is. I don't know whether this approach is correct. I think my solution has some sort of implementation mistake. Here's my submission

Can someone help me to find out if my approach is incorrect or implementation?

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

    I spotted a problem in your approach, check out this case:

    111010000

    here max_consec_one = 3, max_consec_zero = 4, yet neither 1110000 nor 0000111 are substrings of the original string

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

can anyone explain problem D and E solutions for like why we did what we did . The intuition behind them.

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

You should add the binary search and prefix sum solutions to D as well.

As Sol2/Sol3.

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

So in D you literally said "here is the solution" no explanation to the logic or why it works

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

can someone explain the solution to problem D

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

can someone explain the solution to problem D

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

    The solution written in the editorial and the binary search solution of problem D are basically equivalent.

    If we always keep the array non-decreasing, then performing operations is not advantageous, which means we have the array we needed. So the problem becomes how can we keep the array non-decreasing when we continuously add elements to it. We can use binary search to search the left side of where we add new element, finding the longest interval that can be averaged using the operation that problem provide us. Equally, we can use a stack to finish the same work, just traverse forward(left) one by one. However, simply traverse forward one by one has a complexity of $$$O(N)$$$ that cannot accepted, that's why the editorial records the number of occurrences of duplicate elements.

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

sub link Can someone tell me why this is wrong? It's the same as the editorial, only difference being i wrote a simulation for the checking part

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

Wait so long for the editorial

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

In problem C: What if there is a substring of the form both t+0 and t+1 in the original string?

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

    You dont care u cant just take any of them and procceed until u hit the end of the string (neither t + 0 nor t + 1 is a substring) with this u will have a suffix of the string then start extending from the left (aka 0 + t or 1 + t until the length of t is n)

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

Regarding E's time complexity as $$$O(n\log^2W)$$$ may be better.

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

In d question what is the binary search approach ?? minimize the maximum and find largest and smallest element and maximize the minimum and find the largest and smallest element and then compare both the difference whichever will be smaller will be our answer ??

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

In F1, I was trying a solution with simultaneous BFS (from 1 for Alice, and from u for Bob). It doesn't work, but I don't know why. I would appreciate if someone could point out the edge case. At each step, Alice goes to EVERY unseen node in her frontier, marking it as 'seen', after that the neighbours of each of these nodes become her next frontier. Then Bob does the same thing. If at any point a player's frontier is empty, or only have 'seen' nodes, and its that players turn, the player loses.

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

Wansur I have a practice submission for problem D which was accepted, but I believe it shouldn't, as it has $$$O(n^2)$$$ time complexity. Here's the submission 282154960, and here's a test generator that should make it TLE:

C++

I'm posting this here because there isn't a way to hack my own submission to a past contest.

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

For those of you who don't understand what the tutorial of E is saying:

We want to prove that $$$F(a_1,a_2,\cdots,a_n,x) \ge F(x,a_1,a_2,\cdots,a_n)$$$ where $$$F$$$ is the sum defined in the problem and $$$x$$$ satisfies $$$x \lt a_1$$$. If this is true, there always exists an optimal solution where is the smallest element is re-arranged to the first position. Here is the proof:

$$$F(a_1,a_2,\cdots,a_n,x) = (\color{red}{a_1}) + \gcd(a_1,a_2) + \gcd(a_1,a_2,a_3) + \cdots + \gcd(a_1,a_2,\cdots,a_n,x)$$$

$$$F(x,a_1,a_2,\cdots,a_n) = (\color{red}{x + \gcd(x,a_1)}) + \gcd(x,a_1,a_2) + \gcd(x,a_1,a_2,a_3) + \cdots + \gcd(x,a_1,a_2,\cdots,a_n)$$$

Because $$$x \lt a_1$$$ and gcd is always smaller or equal the the difference of two numbers, we have $$$\gcd(x,a_1) \le a_1 -x \implies x + \gcd(x,a_1) \le a_1$$$.

For the rest of the terms, it is easy to observe that the term below is always less than or equal to the corresponding term above since $$$x$$$ is added in the calculation.

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

someone kindly explain solution for problem D in a bit elaborate.The tutorial is of no use

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

Your proof for problem C seems incorrect to me.

In your proof, you mentioned However, after this iteration, we will make only 1 query. But what if that iteration does not exist? For example, you coincidentally reach a suffix of size $$$n - 1$$$ for $$$t$$$, which may take $$$2(n-1)$$$ queries. And after $$$2$$$ more queries, you realized that your $$$t$$$ has reached the end of $$$s$$$. So you need $$$1$$$ additional query to know whether the first character is '0' or '1'. In total, this is $$$2(n - 1) + 2 + 1 = 2n + 1$$$ queries.

In your reference implementation, this case does not actually happen but you may need to address it in your proof.

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

why is the problem D explained without explanation?

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

can someone give some elaborative solution to problem D.the tutorial doesn't explain anything imo

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

someone explain solution for task D in a bit elaborate manner.the tutorial is of no use

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

In case you still don't understand the tutorial of D:

The key observation here is: If two consecutive elements $$$a_i \gt a_{i+1}$$$, it is always not bad to "mix them up", i.e. assign $$$a_i := \lfloor{\frac{a_i+a_{i+1}}{2}}\rfloor$$$ and $$$a_{i+1} \to \lceil{\frac{a_i+a_{i+1}}{2}} \rceil$$$. For instance, (10,1) -> (5,6) and (8,4) -> (6,6). The reason is that: 1. The answer is not worsen since the range is smaller. 2. If in the optimal operation sequence the value of $$$a_i$$$ is transferred to some element of large index instead of $$$a_{i+1}$$$, it is always valid to transfer it from $$$a_{i+1}$$$(Why?).

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

    what do you mean by transferring ai? can you explain pls

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

    I got this but I am not sure how to simulate all of this?

    I can only think of an O(n^2) solution where you do it n times to get a sorted array.

    I dont get the stack implementation in the editorial :(

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

      Let's say you have a sorted array $$$a,\cdots,a,b,\cdots,b,c,\cdots,c$$$ where $$$a \lt b \lt c$$$ and now you want to append a $$$d$$$ and keep it sorted.

      Firstly, what the stack stores is an efficient representation of the elements in the current array, i.e. $$$[(a,cnt_a),(b,cnt_b),(c,cnt_c)]$$$. Now to add $$$d$$$, we firstly mix it up with $$$c$$$. The result can be calculated in $$$O(1)$$$ because we know the sum and the total count. One slight tricky point is to split the "floor" part and the "ceil" part. For example, we have $$$(10,7)$$$ (7 tens) and mix it up with a $$$1$$$, we know that the sum is $$$10*7+1 = 71$$$ and the count is $$$7+1=8$$$. The result should be $$$[(8,1),(9,7)]$$$. (Try to figure out how $$$1$$$ and $$$7$$$ are calculated.)

      If mix-up with currently largest element(i.e. $$$c$$$) would cause the the result to be smaller than the second largest element(i.e. $$$b$$$), the first mix-up is actually not needed and we include $$$(b,cnt_b)$$$ in the mix-up as well. We keep the inclusion until the result satisfies the sorted-ness.

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

Автокомментарий: текст был обновлен пользователем Wansur (предыдущая версия, новая версия, сравнить).

»
19 месяцев назад, скрыть # |
Rev. 4  
Проголосовать: нравится +30 Проголосовать: не нравится
  • My solution for problem D :
Solution
  • »
    »
    19 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится +3 Проголосовать: не нравится

    Cool solution understood that better than in the editorial

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

    Wait isn't min going to change when min > mx — y? a[i+1] += (a[i] — (mx-y)) a[i] = mx-y

    • »
      »
      »
      19 месяцев назад, скрыть # ^ |
      Rev. 2  
      Проголосовать: нравится +1 Проголосовать: не нравится
      • min might change , but the min wont decrease , I am not saying that min wont change , min might change but the change is that min does not decrease , it will always either remain same or increase .
      • So reducing the maximum element will not decrease the min ,
      • so the value = max(a1,a2,..an) — min(a1,a2,...,an) . here when we are reducing the max then , the min might increase or remain the same , so it is always optimal to reduce the max . if min increases that means it is coming closer to the max hence the value is decreasing .
      • Also initially I have stated the assumption : Suppose it is possible to make maximum element of the array A from mx to mx-y .
      • for example a = [18 , 9 , 12 ,18 , 6]
      • initially mx = 18 and mn = 6;

      • now let us just make mx to mx-2 , 18 to 16
      • a = [16 , 11 , 12 , 16 , 8]
      • Do you see that in this newly formed array ,mx = 16 and mn = 8 , here mn is increasing , and mx is decreasing , so the overall value will decrease . from initially value = 18-6 = 12 to value = 16-8 = 8.
      • I think from above example you are able to get the idea that decreasing the maximum element wont decrease the mn , but min might increase or remain same . since max is decreasing and min is increasing overall the value is decreasing . is this helpful ?
      • »
        »
        »
        »
        19 месяцев назад, скрыть # ^ |
         
        Проголосовать: нравится 0 Проголосовать: не нравится

        what i mean is that what if mx — y gets smaller than min

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

          That is not possible , mx is changed to mx-y and mx-y < mn (you are saying this) You can look at the last element = a[n] , a[n] >= minimum(mn), we are making all the elements a[i] <= mx-y ; since the last element = a[n] >= mn , the last element can only increase . so you can not make a[n] to mx-y which is mx-y < mn . So the condition you mentioned can never happen , is this helpful ?

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

    This is what I want to do but I have difficulty coming up with binary search part. Thank you.

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

    Went through this today after being stuck on this problem for a very long time. This is a brilliant solution, it's crazy to see how much simpler this is than the stack approach or the prefix and suffix average solution. Thanks a lot!

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

Why the code of F1 can solve the problem in O(n)? Thank you!

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

Problem D. I saw a solution that we can binary search upper and lower bounds simultaneously. And I had tried this and got AC. But I'm very confused that how to prove this two independent operations is correct?

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

I wrote a more detailed editorial for problem D, if anyone is interested https://mirror.codeforces.com/blog/entry/134292

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

In the D problem, in authors solution as we are putting any element in stack only if it is larger than the previous one, as result max is at the top of stack and min should be at bottom, so taking minimum of all elements of stack(first element) should also give minimum but it is giving wa on tc3. Also, since the tc is large i cant work it out, any idea as to what might be the problem. WA_solution

Thanks in advance

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

Could anyone share the DP solution for E? Please brighten me :))

»
19 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится
#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
// #include "..\debugging.h"
#endif

#define int long long
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
using pi = pair<int, int>;
using vvi = vector<vector<int>>;
using vcb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using mi = map<int, int>;
using si = set<int>;


#define endl "\n"
#define all(x) begin(x), end(x)
#define sz(x) int((x).size())
#define fmap(name, x) mi name; for(auto it:x) ++name[it]
#define F first
#define S second
#define elif else if
#define PB emplace_back
#define MP make_pair
#define REPi(a, b) for (int i = a; i < b; i++)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define REPO(a) for (int i = 0; i < a; i++)
#define vvl(ab, r, c, v)  vvi ab(r, vector<int>(c, v))
#define dbg(v)  cout << #v << " = " << (v) << endl;

const long long mod = 1000000007ll, mod2 = 998244353ll;

int dist(vvi &tree, int p, int node, int p2 = -1) {
    int ans = 1;
    for(int c: tree[node])
        if(c != p && c != p2) {
            ans = max(ans, dist(tree, node, c )+1);
        }
    return ans;
}

void path(vvi &tree, int node, int target, int p, vi &ans) {
    for(int i: tree[node]) {
        if(i == p)
            continue;
        ans.PB(i);
        if(i == target) {
            return;
        }
        path(tree, i, target, node, ans);
        if(ans.back() != target)
            ans.pop_back();
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;

        vvi tree(n);
        for(int i=1; i<n; ++i) {
            int u, v;
            cin >> u >> v;
            --u, --v;
            tree[u].PB(v);
            tree[v].PB(u);
        }

        int u, v;
        cin >> u >> v;
        --u, --v;

        vi adist(n, 0), bdist(n, 0), p = {-1, 0};
        path(tree, 0, u, -1, p);
        p.PB(-1);

        int m = p.size()-2;
        vi dp(m);

        for(int i=1; i<m+1; ++i)
            dp[i-1] = dist(tree, p[i-1], p[i], p[i+1]);


        vi a(m), b(m);
        for(int i=m-1; i>=0; --i) {
            a[i] = dp[i] + i;
            b[i] = dp[i] + m-i-1;
        }

        vi suffdp(m, b.back());
        vi predp(m,a.front());
        for(int i =1 ;i<m-1;i++){
            predp[i] = max(a[i],predp[i-1]);
        }
        for(int i=m-2; i>=0; --i)
            suffdp[i] = max(suffdp[i+1], b[i]);

        // dbg(p);
        // dbg(a);
        // dbg(b);
        // dbg(dp);
        // dbg(suffdp);
        // dbg(predp);


        int start = 0, end = m-1;
        int counter = 1;
        while(start < end){
            if(counter && a[start] > suffdp[start+1] || !counter && b[end] > predp[end-1] ){
                counter = !counter;
                break;
            }
            if(counter)
                start++;
            else
                end--;

            counter = !counter;
        }

        if(start == end)
            counter = !counter;
        cout << (counter?"Bob" : "Alice") << endl;
    }

    return 0;
}

can someone explain why this is wrong for F1.

Basically I tried to find the path from 1 to u. For every path value I found Dp(max depth not on path)

then I checked for early exit. If this makes sense

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

the $$$A$$$ and $$$B$$$ in E's editorial are sequences, or elements, or the gcd of a sequence?

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

problem E is god tier. loved it

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

Hey, for the solution shared for 2013F1 — Game in Tree (Easy Version), the last paragraph mentions that it can be proven that instead of using a segment tree or sparse table, one can simply iterate through all vertices on the segment and terminate the loop upon finding a greater vertex. This approach will yield a solution with a time complexity of O(n).

I am unable to prove this, so was hoping if someone could help me out with it. Thanks!

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

I am curious about the trivial solution presented for question F1. It's claimed that the time complexity of trivial loop is $$$O(n)$$$, but I cannot see why. (Though I have to admit that, to me it really looks like the trivial solution has linear time complexity)

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

Another solution to D:
1) $$$max = max$$$ of all possible suffix average ceil.
2) $$$min = min$$$ of all possible prefix average floor.
3) $$$ans = max - min$$$.
ref: https://mirror.codeforces.com/contest/2013/submission/285605752

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

Wansur is GrandMaster now! orz

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

Wansur is now red hooray!