CutieSmileHaruka's blog

By CutieSmileHaruka, history, 13 hours ago, In English

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
  • Vote: I like it
  • +3
  • Vote: I do not like it

»
4 hours ago, hide # |
 
Vote: I like it +14 Vote: I do not like it

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

»
3 hours ago, hide # |
 
Vote: I like it +16 Vote: I do not like it

yet another implementation round

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

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.

»
108 minutes ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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

»
75 minutes ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Cool problem E.

»
61 minute(s) ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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)

»
34 minutes ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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

»
30 minutes ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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?

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

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