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

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

I got stuck at this problem while trying to learn sweep line technique. I've read the editorial for that problem and got seriously confused at the "y coordinate for a segment" part. Like ... how can we compare the y coordinate when a segment consist of two points ? (Apparently I think it has something to do with sorting points by increasing x coordinate, but can't figure out why ...). Also why do we only check for intersection with the "above" segment in the active set when we first meet the beginning of a segment, but check for both the "above" and "below" when we meet a segment's end ? Please explain all of my question in details if possible.

P/s : Remember that I have 2 questions ...

Edit: There's no respond ... At this point let me ask something straight, and possibly easier : Do you know any red or generally high ranked people that are willing to answer question from a noob like me ? I'm determined to get good at CP, but literally have no mentor or teacher that can go with me a long way. So I asked a friend long ago if he know a good community where people are willing to help me improve. He answered "Codeforces" and ... here I'm am, 3 years later, finally ready to change from a super lazy guy, ADHD and stuff ... to a better version of my self. I went to CF and all the blog I've posted, every characters I've written on CF is just about CP. Sometime I would receive help, but mostly, 80% of the time, it's just downvotes. I know a beginner like me will ask questions that some of you deem stupid, lame, etc... but I know I need to make mistakes to improve. Now I've set for myself a very difficult, rough goal, and time is against me (if I say what the goal is, I know some people will respond with even more negative feedback, but I'll give away a hint : I'm 17 by now). So I changed to a polyphasic sleep schedule recently, sleep for only 3-4 hours a day (yes that's possible), coding for 14-17h, The rest was spend on eating, taking bath, exercise, chores. The unusual time schedule give me more time, but in turn, I have to abandon CF ranked contest, as it always get in the way of one of my sleep phase. But as I study more, there's one clear disadvantage : I have no one to ask. Internet is a rich source of knowledge, but I can't just "figure it out" for every problem I met. I tried : go to CF -> ask a question -> get downvotes -> try even more to "figure it out" -> solve it, but cost too much time. Time is a luxury that I don't have. I know this blog will just earn me even more downvotes, but I don't really mind it. Please, if you know some one who have the patience and ability, along with kindness to answer some of my question, inform me of that person, I promise I will choose the question wisely (Generally I have a about 2 questions a day that are just beyond my ability because of my rapid pace of learning, failing, and trying (well 16h on average a day is a lot of time, I just have to do something with it) but even one answered question a week is already a bless. Most of my question posted on CF have no answer). I will just stay a grey (I've no other choice), but will try to be a student who work both hard and smart, if I ever have a teacher in CP.

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

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

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

I forgot to mention K <= 10^18 and A[i] <= 10^9. Please help !!!

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

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

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

I have a simple, easy to understand question for you guys : What make this lambda function failed to even compile ?

    int N; cin >> N;
    vt<int> adj[N+1]; // I define vector as vt
    FOR(N-1) { // for (int i = 0; i < N-1; i++)
        int u, v; cin >> u >> v;
        adj[u].pb(v); // pb is a shortcut for push_back
        adj[v].pb(u);
    }
    // remember to check for case n = 1
    vt<int> d(N+1);
    auto dfs = y_combinator([&](auto dfs, int u, int p, int &r) {
        if (u == p) d[u] = 0;
        if (d[u] > d[r]) r = u;
        each(v, adj[u]) if (v != p) { // each = for (auto &v : adj[u]) 
            d[v] = d[u]+1;
            dfs(v, u, r);
        }
    });

The thing is, when I'm trying to compile it, I received this catastrophic message :

sol.cpp: In function 'int main()':
sol.cpp:67:29: error: use of deleted function 'main()::<lambda(auto:1, int, int, int&)>::~<lambda>()'
   67 |     auto dfs = y_combinator([&](auto dfs, int u, int p, int &r) {
      |                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   68 |         if (u == p) d[u] = 0;
      |         ~~~~~~~~~~~~~~~~~~~~~
   69 |         if (d[u] > d[r]) r = u;
      |         ~~~~~~~~~~~~~~~~~~~~~~~
   70 |         each(v, adj[u]) if (v != p) {
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   71 |             d[v] = d[u]+1;
      |             ~~~~~~~~~~~~~~
   72 |             dfs(v, u, r);
      |             ~~~~~~~~~~~~~
   73 |         }
      |         ~
   74 |     });
      |     ~
sol.cpp:67:31: note: 'main()::<lambda(auto:1, int, int, int&)>::~<lambda>()' is implicitly deleted because the default definition would be ill-formed:
   67 |     auto dfs = y_combinator([&](auto dfs, int u, int p, int &r) {
      |                               ^

So I try a small fix by capturing 2 vector name d and adj, and it compile as intended ...

    int N; cin >> N;
    vt<int> adj[N+1]; // I define vector as vt
    FOR(N-1) { // for (int i = 0; i < N-1; i++)
        int u, v; cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    // remember to check for case n = 1
    vt<int> d(N+1);
    auto dfs = y_combinator([&d, &adj](auto dfs, int u, int p, int &r) { // <----------- notice this line 
        if (u == p) d[u] = 0;
        if (d[u] > d[r]) r = u;
        each(v, adj[u]) if (v != p) { // each = for (auto &v : adj[u]) 
            d[v] = d[u]+1;
            dfs(v, u, r);
        }
    });

Obviously there is a very big question from my perspective : Why did the first piece of code that I used to capture everything in side the main() function failed, but the second one work ? Is there any way around this, cus I don't want to spend time capturing variable ...

This is my code for y_combinator

Pretty much copy paste, I posted it here just in case ...

Edit : Now I have a clearer version of this question at this link, pls visit it if you find these macros in my code here confusing.

Edit2 : Oops, this question has been answered on stackoverflow. You can view the answer using the above link.

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

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

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

Uh ... basically I'm now stuck at this problem : (problem's name, cus there are 3 in that pdf file) Candy Machine. I've solved only the second subtask (n <= 8000) so I looked for full solution (which can be found here (but hey you don't need to read it to understand my question. I'm saying this just in case you want to solve the problem your self. You can submit it by this link)). So while reading the full solution, I notice that subtask 1 (n <= 85, w <= 4) can be solved using DP over the wagon positions, and the problem is ... I can't do it. Pls kindly help me with the DP part. (Though I solved subtask 2, I'm just very eager to improve my DP skill, which obviously need some fixes ...)

Just to clarify : pls show me how to solve subtask 1 (n <= 85, w <= 4) using DP. Have a good day ^_^ !!

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

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

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

Well, I was trying to do this problem and got stuck. Can anyone give me some hints (like how should I describe a state in that DP problem) ?

(The editorial is only available in Japanese so ... )

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

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

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

Oh hi Codeforces. I'm doing problem Longest Flight Route. At first I'm like "hum ... directed graph but with no circle, gotta find the longest path from 1 to n using normal BFS and I'm gonna be find ...". So it turned out that I didn't get AC because somehow I got TLE verdict on 2 test cases ... I checked the runtime of other test and saw that longest runtime for other test that got AC is like 0.09 sec so it must my algorithm's fault. I did some more check and found that something has caused my BFS to run like forever. However, it's not possible I think. My solution is just the reversed version of normal BFS : with current node u and it's child v, I check if (d[v] < d[u]+1) then update d[v], push v in the queue and I'm done (Oh sorry, I should have mention that d[i] is the longest path from 1 to i). This graph is guaranteed to have no circle, so how the heck did my code got 2 TLE

Here is my code ...

Pls leave some of your thought about this problem and what should I do to fix my code ... Can't see why BFS run forever.

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

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

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

Today is a nice day to do some virtual contest so I thought I would start with doing some AtCoder's beginner round. And I was doing just fine until I crashed into problem E — Distance on Large Perfect Binary Tree. So I read the tutorial and the explanation was ... exactly what I have in mind while doing that contest, so I think there must be something wrong with my code but I couldn't spot it no matter how hard I tried. Can you guys help me ? Here it the editorial and what I did was based on it.

My code (WA on sample test 2)

Help pls, I already used a lot of time to debug this problem but couldn't fix it.

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

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