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

Автор ClosetNarcissist, история, 12 месяцев назад, По-английски

So I was solving this problem https://mirror.codeforces.com/gym/105723/problem/F

and wrote this solution https://ideone.com/SNfGJ6

It works fine in my laptop and ideone C++ 14 but when I submitted it in C++17 (GCC 7-32) I got WA on test 1. It did not make sense to me how I got a vastly different result on the test case in my laptop and CF. I suspected some type of RTE but I could not find any. Then I just submitted in C++23 (GCC 14-64, msys2) and got AC even though I did not change anything in the code.

Anyone knows why this happened. I feel like knowing it would kind of help me avoid it in contests. idk -_-

Полный текст и комментарии »

  • Проголосовать: нравится
  • +1
  • Проголосовать: не нравится

Автор ClosetNarcissist, история, 13 месяцев назад, По-английски

Given n 3D vectors e_i, 1 <= i <= n, and a 3D vector vector v, find the value of the coefficients c_i such that v is described as a linear combination of the n vectors

v = c_0*e_0 + c_1*e_1 + ... + c_n*e_n

but the twist is to calculate c_i such that abs(c_i) <= a_i, where a_i will be given, 1 <= i <= n.

Print the coefficients c_i or print that it's impossible. (If possible print the answer that minimizes the sum of c_i). I have been pondering this question for quite some days and I still have zero idea how to approach this, will it be DP or greedy with some heuristics. I did not add any constraints since I don't really know what the time complexity will be. Any help will be appreciated. Thank you.

Полный текст и комментарии »

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

Автор ClosetNarcissist, история, 2 года назад, По-английски

Recently i did Leetcode Longest Common Subsequence problem. I used the basic dp approach and solved it in 18 ms using 12 mb space. After that i decided to check the fastest solutions for the problem and got this code

Fastest LCS code

I submitted it and it ran in 4 ms using 7.5 mb space. I tried to deconstruct the algorithm and understand how it was working. I cleaned the code a bit and got it to run in 3 ms, but I still could not understand it.

My optimized code

I could not find any relevant blogs explaining it. Can anyone help me understand how this works or link any blogs. Thanks.

Полный текст и комментарии »

  • Проголосовать: нравится
  • +4
  • Проголосовать: не нравится

Автор ClosetNarcissist, 2 года назад, По-английски

In the recent CF round 931 for problem B I realized that I could not solve it normally using DP since n was too high. I knew that some coin systems can be solved greedily but it was not the case for this one. During the contest, I solved it like this: https://mirror.codeforces.com/contest/1934/submission/249165174

But later I saw that some people just pre-calculated the answer upto 30 or something and then used some mod tricks to get the answer. I thought they picked 30 since it was the LCM and so I tried to test my hypothesis by solving the CSES Minimizing Coin problem and it actually worked. I thought this was some optimization on the problem that I did not know about before. This was my solution: https://cses.fi/paste/dbb9ee26f083862b8352b1/

However, I soon realized that my method does not work for coin systems like {3, 6, 10, 15}, as my code would give impossible for the value 32, which is obviously wrong as it should really be 4. After that, I thought there had to be some conditions that had to be met for me to use this "lcm" trick (if this is even real or just something that coincidentally worked). But I could not think of any and I could not find any relevant articles, so I want to ask you guys to make me understand.

Thanks in advance. Btw before writing this blog, I thought I'd solve the original CF problem using the "lcm" trick but it did not give the correct answers lol.

Полный текст и комментарии »

  • Проголосовать: нравится
  • +2
  • Проголосовать: не нравится