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

Автор awoo, история, 4 часа назад, По-русски

2025A - Два экрана

Идея: BledDest

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

2025B - Биномиальные коэффициенты, ну типа

Идея: adedalic

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

2025C - Новая игра

Идея: fcspartakm

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

2025D - Проверка характеристик

Идея: adedalic

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

2025E - Карточная игра

Идея: BledDest

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

2025F - Выбери свои запросы

Идея: BledDest

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

2025G - Переменный урон

Идея: BledDest

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

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

Finally

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

Hii everyone can anyone help me D problem?

https://mirror.codeforces.com/contest/2025/my

this was my solution

i would keep count of zeros till i

then our s could range from 0 to zeros

so my state is dp[s] which will have max check passed, so my time complexity was 5000*2*10^6

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

    https://mirror.codeforces.com/contest/2025/submission/286105592

    here i have reduced most of the redudant operations still i get tle

    what i am thinking is to have a vector which stores starting and ending point of zeros if more than 1 then i would just increment my of zeros to difference between start and end their by saving some more time am i going in the right direction?

    i would be using a unordered map to store my records.

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

For those, who interested in combinatorial way for problem E, using something similar to Catalan numbers: I wrote a post about it

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

Does Problem D fall under some Dp pattern saw this pattern of pushAndClear in many submissions it didn't click to me at all.

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

isn't the code in problem A's solution $$$ O(n^2) $$$ due to string slicing?

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

.

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

for Problem c , can anyone tell why this solution is giving wrong answer on test 4 (i used binarysearch to solve this): https://mirror.codeforces.com/contest/2025/submission/285946605 thanks in advance !!

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

    By binary research, you can only find the position of the last card which number is less than $$$(x+k-1)$$$, but you are not able to know if there are some numbers missing (between $$$x$$$ and the number of the last card). It’s the reason why you get wrong answer.

    BTW, if you choose to check through the whole interval between $$$x$$$ and $$$(x+k-1)$$$ to make sure there are no missing numbers, the time complexity would be something like $$$O(N^2)$$$ in worst case and fails the time limit.

    Therefore, I don’t think it’s possible to use binary research to solve this problem.

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

Note about Problem A ( or any other problem concerning strings ) if you use Python and fast IO like: input = sys.stdin.readline then make sure to strip the string from whitespace and newlines.

this code was tested in Windows fine:

import sys

# defined functions for fast input
input = sys.stdin.readline
readListInts = lambda type_="int", sep=" ": list(
    map(eval(type_), input().strip().split(sep))
)

# defined functions for fast output
output = lambda x: sys.stdout.write(str(x) + "\n")
outputString = lambda x: sys.stdout.write(x + "\n")

def main():
    for _ in range(int(input())):
        s = input()
        t = input()

        lcp = 0
        n = len(s)
        m = len(t)
        for i in range(1, min(n, m) + 1):
            if s[:i] == t[:i]:
                lcp = i
        output(n + m - max(lcp, 1) + 1)

if __name__ == "__main__":
    main()

However, the judges are based on POSIX systems and newlines are treated differently between the two systems. So I needed to make this small adjustment:

 s = input().strip()
 t = input().strip()

A small detail that may cost you a submission.

I guess for veteran competitive programmers this is trivial but it cost me some time and a wrong submission on an easy problem.

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

Problem B Binomial Coefficients Kind of Video Editorial Link: https://youtu.be/y_b2Khyk28w?si=Ku5V5m1jtT8EtA1e

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

    Honestly, instead of doing this video... up solve next time.

    Or may be just downvote this comment and rant over it.

    Not that anyone asked, but felt like sharing constructive feedback.

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

i want to know,would anyone please tell me why rating going back;

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

_i want to know,would anyone please tell me why rating going back;

»
2 часа назад, # |
Rev. 2   Проголосовать: нравится +1 Проголосовать: не нравится

my solution to D is a little different and it does not require bs or lazysum.

let $$$dp[i]$$$ denotes the $$$max \ score$$$ we can get if we are at index $$$j$$$ and have total $$$i$$$ intelligence points
if $$$A[i] == 0$$$ we will update dp values as follows.
let $$$cnt1[x] \ and \ cnt2[x]$$$ stores no. of checks with values x of intelligence and strength respectively.

if we choose to increase intelligence points then we are sure that we will pass all the intelligence checks having value $$$<=$$$ to our current intelligence values and because all the checks with value $$$<$$$ $$$current intelligence$$$ are already covered we will need to calculate how many values = current intelligence are there on the right on the right of index i and this value is stored in cnt1[current intelligence].

$$$dp[i] \ = \ max(dp[i] \ + \ cnt2[s - i], \ dp[i - 1] \ + \ cnt1[i])$$$
here $$$i$$$ is $$$current_intelligence$$$ and s is $$$current total score = intelligence + strength$$$

here is the 285916766 to explain better (ignore the code above solve function).

feel free to ask me if you have any queries. Thanks!

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

E can be solved using DP + OEIS sequence A050155.

Define $$$g(m,k)$$$: Number of ways to choose $$$(m+k)/2$$$ elements for Player 1 out of m cards in a given suit such that Player 1 wins as given in Problem.

Write a brute force for function $$$g$$$ -> generate the sequence and paste on OEIS -> Find the formula $$$g(m,k)$$$ given in OEIS link above -> Precompute it -> Multiply $$$g(m,j-k)$$$ with $$$DP[i-1][k]$$$ and then sum over all values of $$$0\leq k\leq j$$$ to find $$$DP[i][j].$$$ $$$1\leq i\leq n,0\leq j\leq m$$$.

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

285923775 can someone explain why its giving TLE at test case 24 , in the contest the code was accepted but then it showed TLE, Thanks in advance

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

Can someone explain why its showing TLE in this submission in problem C , in the contest it got accepted but later on it came out to be TLE 285923775 in test case 24

»
78 минут назад, # |
Rev. 5   Проголосовать: нравится 0 Проголосовать: не нравится

.

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

E is a typical problem that requires $$$y-x\ge k$$$ on a path from $$$(0,0)$$$ to $$$(m,n)$$$. See here for more details.

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

In Problem C, I have an issue:

I have two pieces of code. The first one:

from collections import deque
from sys import stdin
input = lambda: stdin.readline().rstrip()

def solve():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    hs = {}
    for i in a:
        if hs.get(str(i)) is None:
            hs[str(i)] = 0
        hs[str(i)] += 1
    mapLi = []
    mx = 0
    for i in hs:
        mx = max(mx, hs[i])
        mapLi.append([i, hs[i]])
    mapLi.sort(key=lambda i: (int(i[0]), -i[1]))
    ans = 0
    queue = deque([])
    cnt = 0
    for i, v in mapLi:
        ans = max(ans, cnt)
        while queue and len(queue) >= k:
            cnt -= queue.popleft()[1]
        ans = max(ans, cnt)
        while queue and abs(int(queue[-1][0]) - int(i)) > 1:
            cnt -= queue.pop()[1]
        ans = max(ans, cnt)
        queue.append((i, v))
        cnt += v
        ans = max(ans, cnt)
    ans = max(ans, cnt)
    return ans

for _ in range(int(input())):
    print(solve())

The second one:

from collections import deque
from sys import stdin
input = lambda: stdin.readline().rstrip()

def solve():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    hs = {}
    for i in a:
        if hs.get(i) is None:
            hs[i] = 0
        hs[i] += 1
    mapLi = []
    mx = 0
    for i in hs:
        mx = max(mx, hs[i])
        mapLi.append([i, hs[i]])
    mapLi.sort(key=lambda i: (int(i[0]), -i[1]))
    ans = 0
    queue = deque([])
    cnt = 0
    for i, v in mapLi:
        ans = max(ans, cnt)
        while queue and len(queue) >= k:
            cnt -= queue.popleft()[1]
        ans = max(ans, cnt)
        while queue and abs(int(queue[-1][0]) - int(i)) > 1:
            cnt -= queue.pop()[1]
        ans = max(ans, cnt)
        queue.append((i, v))
        cnt += v
        ans = max(ans, cnt)
    ans = max(ans, cnt)
    return ans

for _ in range(int(input())):
    print(solve())

I submitted the second piece of code to Codeforces Edu Round 170, Problem C, but it resulted in a Time Limit Exceeded (TLE). Then, I submitted the first piece of code, and it passed successfully. Is this an issue with the judging system, or is there a problem with my code? Can someone explain the reason? I would be very grateful!

link1:https://mirror.codeforces.com/contest/2025/submission/286123006 link2:https://mirror.codeforces.com/contest/2025/submission/286122969

If this problem is solved, you will get one of Python's optimization ticks!!!!!

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

    Avoid using dict or set in an open-hack round as they're to be easily hacked. If you have to, write your own hash function.

    By using str(i) instead of i as the key, you actually define another hash function for $$$i$$$ so you pass the test.