okay4869's blog

By okay4869, 10 months ago, In English

Doubt for the question here:

https://leetcode.com/problems/rotting-oranges/description/

How I initialized my queue: queue<tuple<int, int, int>> q;

WA :

while(!q.empty()) {
            auto [x, y, curr] = q.front(); q.pop();
            steps = max(steps, curr);
            for(int i = 0; i < 4; ++i) {
                int X = x+dx[i], Y = y+dy[i];
                if(X >= 0 && X < N && Y >= 0 && Y < M && grid[X][Y] == 1 && vis[X][Y] != 2) {
                    q.push({X, Y, curr+1});
                    vis[X][Y] = 2;
                }
            }
        }

AC :

while(!q.empty()) {
            int x, y, curr; tie(x, y, curr) = q.front(); q.pop();
            steps = max(steps, curr);
            for(int i = 0; i < 4; ++i) {
                int X = x+dx[i], Y = y+dy[i];
                if(X >= 0 && X < N && Y >= 0 && Y < M && grid[X][Y] == 1 && vis[X][Y] != 2) {
                    q.push({X, Y, curr+1});
                    vis[X][Y] = 2;
                }
            }
        }

The WA one passes all but one testcase, which is:

grid = [[0,0,0,0],[0,1,1,2],[1,1,1,0],[1,1,1,2],[2,0,1,1],[2,1,2,1],[1,2,0,1],[2,2,1,2],[2,1,1,0],[1,0,2,2]];

This is the first time I am experiencing this. What is the reason behind this? Thank you

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By okay4869, history, 10 months ago, In English

TLE CODE:

https://codeforces.net/contest/1886/submission/239483379

Accepted Code:

https://codeforces.net/contest/1886/submission/239483485

Is it because of

ans*=i;ans%md
ans=(ans*i)%md

? If So can anyone explain the reason why one gives TLE but other is fine?

Full text and comments »

  • Vote: I like it
  • +10
  • Vote: I do not like it

By okay4869, history, 17 months ago, In English

So I was doing this question from the Educational round 85 here: https://codeforces.net/contest/1334/problem/C

And after a few attempts this is the code that got TLE in 3rd test: https://codeforces.net/contest/1334/submission/209278732

However after adding the lines:

import sys
input = sys.stdin.buffer.readline

The same code got accepted and was pretty quick. https://codeforces.net/contest/1334/submission/209278848

This made me wonder, are there any more things I can add to my Python code to make it run faster? Any answers or even links would be greatly appreciated. Thank you.

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By okay4869, history, 18 months ago, In English

So randomly found this profile in both codeforces and leetcode. Solved all questions in a few days with like 1000 submissions a day. The profile is : https://codeforces.net/profile/chappy1 https://leetcode.com/chappy1/

Pretty crazy.....

Full text and comments »

  • Vote: I like it
  • -39
  • Vote: I do not like it

By okay4869, history, 18 months ago, In English

I personally use snake case more but its mostly random

Full text and comments »

  • Vote: I like it
  • -3
  • Vote: I do not like it