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

Автор CutieSmileHaruka, история, 14 часов назад, По-английски

We hope you enjoyed these problems!

2222A - A Wonderful Contest

Author: Lyz09

Hint 1
Tutorial
Implementation

2222B - Artistic Balance Tree

Author: lizhous

Hint 1
Tutorial
Implementation

2222C - Median Partition

Author: ma2021tyoi0037

Hint 1
Hint 2
Tutorial
Implementation

2222D - Permutation Construction

Author: Lyz09

Hint 1
Hint 2
Tutorial
Implementation

2222E - Seek the Truth

Author: Lyz09

Hint 1
Tutorial
Implementation

2222F - Building Tree

Author: hzy_____ Preparation: Rebex

Hint 1
Hint 2
Tutorial
Implementation

2222G - Statistics on Tree

Author: Lyz09 Developer: Z-301

Hint 1
Hint 2
Hint 3
Tutorial
Implementation

2222H - Counting Sort?

Author: CutieSmileHaruka

Hint 1
Hint 2
Hint 3
Tutorial
Implementation
  • Проголосовать: нравится
  • +11
  • Проголосовать: не нравится

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

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

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

yet another implementation round

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

In C i got to the point where median of segments = median of fulll array if it exists

the trick lies in where we can compute if median of a segment = M using the comparisons which are precomputed once we fix the median

Learned something new.

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

my apparach for C

First, I precomputed the median for all prefix subarrays of odd size. Then for each recursive call, I enforced that prefix median onto the rest

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

Cool problem E.

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

Subject: Weak Test Data Report: Inefficient DP Solution Passes Time Limit in [Insert Problem Letter] — Nanatsukaze — Save Our Sound https://mirror.codeforces.com/contest/2222/problem/A

To the Problem Setter / Contest Coordinators,

I am writing to report a case of weak test data for the problem Nanatsukaze — Save Our Sound.An incredibly inefficient, Unbounded Knapsack Dynamic Programming solution is currently passing all system tests and being Accepted. The code has a worst-case time complexity that should clearly result in a Time Limit Exceeded (TLE), but it passes because the system tests are missing a specific "worst-case" scenario where the answer is "Yes" and $$$N$$$ is maximized.The Flaw in the Accepted CodeThe code attempts to check every possible score from $$$0$$$ to $$$100 \cdot n$$$ by running an unbounded knapsack DP for each target score independently.Furthermore, the code dynamically allocates a vector inside the DP function during every single iteration of the loop.

Here is the exact submission that gets accepted: https://mirror.codeforces.com/contest/2222/submission/372573074

Why it should TLE (Complexity Analysis)If the array does not contain 100 (meaning the answer is "No"), the DP quickly fails on target = 1 and breaks the loop. The execution time is negligible.However, if the array does contain 100 (meaning the answer is "Yes"), the DP loop never breaks early. It must check every number up to $$$100 \cdot N$$$.For a maxed-out test case where $$$T = 100$$$, $$$N = 10$$$, and all $$$a_i = 100$$$:The outer loop runs $$$100 \times 10 = 1,000$$$ times per testcase.can() is called $$$1,000$$$ times, allocating a vector on the heap every single time.The nested loops inside can() result in roughly $$$10,000,000$$$ operations per test case.For $$$T=100$$$, this results in $$$\approx 10^9$$$ operations and 100,000 dynamic memory allocations, which takes roughly 5 to 10 seconds locally and heavily exceeds standard time limits.

The Missing Worst-Case Test DataTo break this code, the system tests need a file filled with maximum values where the answer is "Yes".

100 10 100 100 100 100 100 100 100 100 100 100 10 100 100 100 100 100 100 100 100 100 100 ... (repeated 100 times total)

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

I find the explanation for problem C not very understandable. Can you explain in more detail how to compute dp[i] exactly.

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

    let dp[i] = max number of partitions of the subarray [0..i] into odd length segments with median = full median. dp[i] = max(dp[j]+1) over all j where j<i, the subarray [j+1..i] has odd length, and the median of [j+1..i] = full median. if all those conditions are satisfied, its a valid partition. you can check for the 3rd condition by checking if num(elements <= median) <= (i-j+1)//2 and num(elements >= median) <= (i-j+1)//2, you can use prefix sums to precompute these counts

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

My approach for C was: 1. Start walking through the array, if the median so far is as desired AND it is possible to split the rest of the array in some way to fulfill the condition, then I should cut off the array so far, sum+=1, start over with the shorter array. 2. My approach to finding out whether or not the rest of the array was splittable at all was: if the rest of the array is odd length, just check if the array as whole is valid (has correct median), if the rest of the array is even length, check for every index where we would split it into two odd-length arrays if both of these odd-length arrays are valid. If that is the case at no index, I figured, it wouldn't be possible at all.

This survived the first 3 test cases, but failed on pretest 4. I am not even quite sure which assumption is incorrect (1. or 2.). Does someone know what is wrong with my approach?

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

C can be solved without the fact that the median of each subarray is also the median of the whole sequence. Let $$$f(l, r)$$$ be the median of $$$a_l, a_{l+1}, \dots, a_r$$$. We fix the median as $$$x$$$, and let $$$dp_i$$$ be the number of subarrays when each one has median $$$x$$$. The idea is we only iterate through all $$$j$$$ such that $$$f(j, i)=x$$$, meaning across all $$$x$$$ there will be $$$O(n^2)$$$ transitions. I'm just unsure if $$$f$$$ can be computed faster than $$$O(n^2 \log n)$$$.

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

i used a similar but a bit different method on E. To track the value of c i just constructed it bit by bit from n-1 to 0th bit.

372518426